PHPackages                             displace/ai-toolkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. displace/ai-toolkit

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

displace/ai-toolkit
===================

Pure-PHP utilities for local-first AI pipelines: text chunkers, packed-vector math, MRL truncation.

v0.1.0(1mo ago)0155MITPHPPHP ^8.3CI passing

Since Jun 11Pushed 1mo agoCompare

[ Source](https://github.com/DisplaceTech/ai-toolkit)[ Packagist](https://packagist.org/packages/displace/ai-toolkit)[ Docs](https://github.com/DisplaceTech/ai-toolkit)[ RSS](/packages/displace-ai-toolkit/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

ai-toolkit
==========

[](#ai-toolkit)

 **Pure-PHP utilities for local-first AI pipelines.**
 Text chunkers, packed-vector math, Matryoshka truncation — boring on purpose.

 [![CI](https://github.com/DisplaceTech/ai-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/DisplaceTech/ai-toolkit/actions/workflows/ci.yml) [![Packagist](https://camo.githubusercontent.com/e9f932db5add50974549cebe86cc2b74351274e9337912342307581589ed26cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646973706c6163652f61692d746f6f6c6b6974)](https://packagist.org/packages/displace/ai-toolkit) [![PHP 8.3 / 8.4 / 8.5](https://camo.githubusercontent.com/f8c66ec3458748baee370b7844203c334e62735196a3c31b11c504ab609f4be7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e33253230253743253230382e34253230253743253230382e352d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/f8c66ec3458748baee370b7844203c334e62735196a3c31b11c504ab609f4be7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e33253230253743253230382e34253230253743253230382e352d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465) [![mbstring only](https://camo.githubusercontent.com/2af4a71cdc92e64a6001326652f2dc37fe04ddd9ed935e2e57edecbb6b258c29/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d6d62737472696e672532306f6e6c792d627269676874677265656e)](https://camo.githubusercontent.com/2af4a71cdc92e64a6001326652f2dc37fe04ddd9ed935e2e57edecbb6b258c29/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d6d62737472696e672532306f6e6c792d627269676874677265656e) [![MIT License](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](LICENSE)

---

What is ai-toolkit?
-------------------

[](#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](https://github.com/DisplaceTech/ext-infer)(embeddings), [ext-turbovec](https://github.com/DisplaceTech/ext-turbovec)(vector search), and the [ai-contracts](https://github.com/DisplaceTech/ai-contracts) interfaces — but depends on none of them.

Chunkers
--------

[](#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
}
```

ChunkerStrategyReach for it when`RecursiveCharacterChunker`Split on paragraphs first, then lines, sentences, words; hard-cut lastProse, markdown, HTML-stripped text — **the default**`SentenceChunker`Pack whole sentences; never splits mid-sentence; overlap counted in sentencesTranscripts and clean copy where sentence integrity matters`FixedSizeChunker`Sliding character window, verbatim slicesLogs, minified or OCR text with no useful structurePacked-vector math
------------------

[](#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

[](#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
---------------

[](#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
-------------------------

[](#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
-------

[](#license)

[MIT](LICENSE) © 2026 Eric Mann / Displace Technologies

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86bb3fa9fcfe57b8d313e527e9e02bde810951b25722b4717b0953a6c8db41b2?d=identicon)[ericmann](/maintainers/ericmann)

---

Top Contributors

[![ericmann](https://avatars.githubusercontent.com/u/605474?v=4)](https://github.com/ericmann "ericmann (13 commits)")

---

Tags

aivectorsembeddingsragchunkingtext-splittermatryoshka

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/displace-ai-toolkit/health.svg)

```
[![Health](https://phpackages.com/badges/displace-ai-toolkit/health.svg)](https://phpackages.com/packages/displace-ai-toolkit)
```

###  Alternatives

[maestroerror/laragent

Power of AI Agents in your Laravel project

639159.9k](/packages/maestroerror-laragent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
