PHPackages                             sqlite-vec/sqlite-vec - 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. [Database &amp; ORM](/categories/database)
4. /
5. sqlite-vec/sqlite-vec

ActiveLibrary[Database &amp; ORM](/categories/database)

sqlite-vec/sqlite-vec
=====================

PHP support for sqlite-vec: vector search for SQLite

v0.1.1(2mo ago)0115MITPHPPHP &gt;=8.1

Since Apr 8Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/rlerdorf/sqlite-vec)[ Packagist](https://packagist.org/packages/sqlite-vec/sqlite-vec)[ Docs](https://github.com/rlerdorf/sqlite-vec)[ RSS](/packages/sqlite-vec-sqlite-vec/feed)WikiDiscussions main Synced 2w ago

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

sqlite-vec for PHP
==================

[](#sqlite-vec-for-php)

PHP support for [sqlite-vec](https://github.com/asg017/sqlite-vec); a vector search extension for SQLite.

Ships pre-built binaries for Linux (x86\_64, aarch64), macOS (x86\_64, Apple Silicon), and Windows (x86\_64). No compilation needed.

Requirements
------------

[](#requirements)

- PHP 8.1+
- `ext-pdo_sqlite` (recommended, zero-config on PHP 8.4+) or `ext-sqlite3`

Installation
------------

[](#installation)

```
composer require sqlite-vec/sqlite-vec
```

### SQLite3 class users

[](#sqlite3-class-users)

The `SQLite3` class requires `sqlite3.extension_dir` to be set in php.ini. A setup script is included:

```
sudo vendor/bin/sqlite-vec-setup
```

This detects your PHP ini scan directories and writes a config file pointing `sqlite3.extension_dir` to the bundled binary. Run with `--dry-run` to preview, `--status` to check current config, or `--remove` to uninstall.

`Pdo\Sqlite` on PHP 8.4+ does **not** need this step.

Usage
-----

[](#usage)

### Load the extension

[](#load-the-extension)

```
use SqliteVec\SqliteVec;

// PDO (PHP 8.4+) — zero config
// Note: the DSN needs the "sqlite:" prefix even with \Pdo\Sqlite
$db = new \Pdo\Sqlite('sqlite::memory:');  // or 'sqlite:/path/to/db.sqlite'
SqliteVec::load($db);

// SQLite3 — requires sqlite-vec-setup first
$db = new \SQLite3(':memory:');
SqliteVec::load($db);
```

### Vector search

[](#vector-search)

```
$db = new \Pdo\Sqlite('sqlite::memory:');
SqliteVec::load($db);

// Create a vector table (4-dimensional float vectors)
$db->exec('CREATE VIRTUAL TABLE vec_items USING vec0(embedding float[4])');

// Insert vectors
$stmt = $db->prepare('INSERT INTO vec_items(rowid, embedding) VALUES (:id, :emb)');
$vectors = [
    1 => [1.0, 0.0, 0.0, 0.0],
    2 => [0.0, 1.0, 0.0, 0.0],
    3 => [0.0, 0.0, 1.0, 0.0],
];
foreach ($vectors as $id => $vec) {
    $stmt->bindValue(':id', $id, PDO::PARAM_INT);
    // Important: use PARAM_LOB, not PARAM_STR — PARAM_STR causes SQLite to
    // interpret the binary blob as text, producing silent garbage results.
    $stmt->bindValue(':emb', SqliteVec::serializeFloat32($vec), PDO::PARAM_LOB);
    $stmt->execute();
}

// KNN query — find the nearest vector to [1.0, 0.1, 0.0, 0.0]
$query = SqliteVec::serializeFloat32([1.0, 0.1, 0.0, 0.0]);
$stmt = $db->prepare(
    'SELECT rowid, distance FROM vec_items WHERE embedding MATCH :q ORDER BY distance LIMIT 3'
);
$stmt->bindValue(':q', $query, PDO::PARAM_LOB);  // Must be PARAM_LOB
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo "rowid={$row['rowid']} distance={$row['distance']}\n";
}
```

### Serialization helpers

[](#serialization-helpers)

```
// Float32 vectors
$binary = SqliteVec::serializeFloat32([1.0, 2.0, 3.0]);
$array  = SqliteVec::deserializeFloat32($binary);

// Int8 vectors (values in [-128, 127])
$binary = SqliteVec::serializeInt8([1, -1, 127, -128]);
$array  = SqliteVec::deserializeInt8($binary);
```

### Check version

[](#check-version)

```
$version = SqliteVec::vecVersion($db); // e.g. "v0.1.9"
```

API
---

[](#api)

### `SqliteVec::load(SQLite3|PDO $db): void`

[](#sqlitevecloadsqlite3pdo-db-void)

Load the sqlite-vec extension into a database connection.

### `SqliteVec::extensionPath(): string`

[](#sqlitevecextensionpath-string)

Return the absolute path to the platform-specific binary.

### `SqliteVec::serializeFloat32(array $vector): string`

[](#sqlitevecserializefloat32array-vector-string)

Pack a float array into the binary format sqlite-vec expects.

### `SqliteVec::deserializeFloat32(string $binary): array`

[](#sqlitevecdeserializefloat32string-binary-array)

Unpack a binary float32 vector back to a PHP array.

### `SqliteVec::serializeInt8(array $vector): string`

[](#sqlitevecserializeint8array-vector-string)

Pack an int array (values -128..127) into binary int8 format.

### `SqliteVec::deserializeInt8(string $binary): array`

[](#sqlitevecdeserializeint8string-binary-array)

Unpack a binary int8 vector back to a PHP array.

### `SqliteVec::vecVersion(SQLite3|PDO $db): string`

[](#sqlitevecvecversionsqlite3pdo-db-string)

Query the loaded sqlite-vec version string.

Bundled sqlite-vec version
--------------------------

[](#bundled-sqlite-vec-version)

This package bundles sqlite-vec **v0.1.9**. The pre-built binaries are distributed under the same MIT license as sqlite-vec itself.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance85

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

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

Every ~0 days

Total

2

Last Release

80d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04c4b64e4b0528a79749a79b300ef81c093cbdaeb733b2b2c2a39b4352fa19a3?d=identicon)[rlerdorf](/maintainers/rlerdorf)

---

Top Contributors

[![rlerdorf](https://avatars.githubusercontent.com/u/54641?v=4)](https://github.com/rlerdorf "rlerdorf (5 commits)")

---

Tags

searchsqlitevectorknnembedding

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sqlite-vec-sqlite-vec/health.svg)

```
[![Health](https://phpackages.com/badges/sqlite-vec-sqlite-vec/health.svg)](https://phpackages.com/packages/sqlite-vec-sqlite-vec)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k595.8M6.5k](/packages/doctrine-dbal)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58725.2M48](/packages/scienta-doctrine-json-functions)[codewithkyrian/chromadb-php

A PHP client for the Chroma Open Source Embedding Database

83317.9k11](/packages/codewithkyrian-chromadb-php)[arnoson/kirby-loupe

Search Kirby with Loupe

421.2k](/packages/arnoson-kirby-loupe)[codewithkyrian/chromadb-laravel

ChromaDB Laravel is a Laravel client for the Chroma Open Source Embedding Database

144.1k](/packages/codewithkyrian-chromadb-laravel)[ark/database

Light weight database abstraction

107.8k](/packages/ark-database)

PHPackages © 2026

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