displace/ai-toolkit
Composer 安装命令:
composer require displace/ai-toolkit
包简介
Pure-PHP utilities for local-first AI pipelines: text chunkers, packed-vector math, MRL truncation.
README 文档
README
Pure-PHP utilities for local-first AI pipelines.
Text chunkers, packed-vector math, Matryoshka truncation — boring on purpose.
What is ai-toolkit?
The plumbing every embed-and-search pipeline needs and no one wants to rewrite: split documents into chunks, move vectors around in the packed float32 format, slice Matryoshka embeddings down to size. Pure PHP, no extension required, no framework, no model downloads.
composer require displace/ai-toolkit
It pairs with ext-infer (embeddings), ext-turbovec (vector search), and the ai-contracts interfaces — but depends on none of them.
Chunkers
Three strategies behind one Chunker interface, sized in characters
(multibyte-aware):
use Displace\AI\Toolkit\Text\RecursiveCharacterChunker; $chunker = new RecursiveCharacterChunker(size: 1000, overlap: 200); foreach ($chunker->chunk($markdown) as $chunk) { // embed → index }
| Chunker | Strategy | Reach for it when |
|---|---|---|
RecursiveCharacterChunker |
Split on paragraphs first, then lines, sentences, words; hard-cut last | Prose, markdown, HTML-stripped text — the default |
SentenceChunker |
Pack whole sentences; never splits mid-sentence; overlap counted in sentences | Transcripts and clean copy where sentence integrity matters |
FixedSizeChunker |
Sliding character window, verbatim slices | Logs, minified or OCR text with no useful structure |
Packed-vector math
Vectors in the Displace stack travel as packed little-endian float32
binary strings — the output of pack('g*', ...$floats), batches by
plain concatenation. Packed is the pure-PHP companion for glue code
and tests:
use Displace\AI\Toolkit\Vector\Packed; $a = Packed::pack([0.12, 0.48, /* ... */]); // floats → packed buffer $b = Packed::pack([0.33, 0.19, /* ... */]); Packed::cosine($a, $b); // similarity in [-1, 1] Packed::dot($a, $b); // inner product Packed::norm($a); // L2 norm Packed::normalize($batch, dim: 1024); // per-vector unit length Packed::unpack($a, dim: 1024); // packed buffer → floats
Matryoshka (MRL) truncation
MRL-trained embedding models (Qwen3-Embedding, ...) pack the most important information into the leading coordinates, so a prefix of the vector is itself a usable embedding. Trade recall for a smaller index by slicing — no re-embedding required:
// 1024-dim Qwen3 embeddings down to 256-dim, renormalized per vector: $small = Packed::truncate($vectors, fromDim: 1024, toDim: 256);
Only valid for MRL-trained models; truncating an ordinary embedding just throws information away.
On the hot path
Packed is for correctness, not speed — it's pure PHP. When
ext-turbovec is loaded, prefer its native Displace\Vector\Vectors
pack/unpack and let the index do the scoring; when you only need
similarity between a handful of vectors, Packed is plenty.
Deliberately out of scope
Token-based chunking — token counts are model-specific and need a tokenizer; character budgets are model-independent and close enough for retrieval (rule of thumb: ~4 characters per English token) · embedding generation — that's ext-infer or your API client · vector storage and ANN search — that's ext-turbovec or your database · document loaders/parsers (PDF, HTML, ...) — bring your own text · an orchestration framework — chains and agents belong to the frameworks.
License
MIT © 2026 Eric Mann / Displace Technologies
displace/ai-toolkit 适用场景与选型建议
displace/ai-toolkit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「vectors」 「ai」 「chunking」 「matryoshka」 「embeddings」 「rag」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 displace/ai-toolkit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 displace/ai-toolkit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 displace/ai-toolkit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP client for the Chroma Open Source Embedding Database
FineUploader bundle for Contao Open Source CMS
PHP Interface for Babel Street Text Analytics
Raphael.js Bundle for Symfony2
ChromaDB Laravel is a Laravel client for the Chroma Open Source Embedding Database
A lightweight framework that provides a standard and easy way to implement a model service layer
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-11