PHPackages                             benbjurstrom/sqlite-vec-scout - 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. [Search &amp; Filtering](/categories/search)
4. /
5. benbjurstrom/sqlite-vec-scout

ActiveLibrary[Search &amp; Filtering](/categories/search)

benbjurstrom/sqlite-vec-scout
=============================

sqlite-vec driver for Laravel Scout

v0.1.0(6mo ago)13MITPHPPHP ^8.2

Since Oct 26Pushed 6mo agoCompare

[ Source](https://github.com/benbjurstrom/sqlite-vec-scout)[ Packagist](https://packagist.org/packages/benbjurstrom/sqlite-vec-scout)[ Docs](https://github.com/benbjurstrom/sqlite-vec-scout)[ GitHub Sponsors]()[ RSS](/packages/benbjurstrom-sqlite-vec-scout/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (4)Used By (0)

[![Logo](https://private-user-images.githubusercontent.com/12499093/505766352-4ef54415-e0be-4301-ab2e-98b39cceae12.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUxNTAwODMsIm5iZiI6MTc3NTE0OTc4MywicGF0aCI6Ii8xMjQ5OTA5My81MDU3NjYzNTItNGVmNTQ0MTUtZTBiZS00MzAxLWFiMmUtOThiMzljY2VhZTEyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAyVDE3MDk0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ1ODRhN2QxNjQyNjVmYmQ4N2RjYmM3MjA4MTQ4Njk1YzA3NDUzOWMwZjc3MDg0ODAyMTdlOTZlYzljMTI5MzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.5QVCrkGIpM1thMMsJffKhFMZXXuKqeUQEyu9XGWChI8)](https://private-user-images.githubusercontent.com/12499093/505766352-4ef54415-e0be-4301-ab2e-98b39cceae12.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUxNTAwODMsIm5iZiI6MTc3NTE0OTc4MywicGF0aCI6Ii8xMjQ5OTA5My81MDU3NjYzNTItNGVmNTQ0MTUtZTBiZS00MzAxLWFiMmUtOThiMzljY2VhZTEyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAyVDE3MDk0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ1ODRhN2QxNjQyNjVmYmQ4N2RjYmM3MjA4MTQ4Njk1YzA3NDUzOWMwZjc3MDg0ODAyMTdlOTZlYzljMTI5MzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.5QVCrkGIpM1thMMsJffKhFMZXXuKqeUQEyu9XGWChI8)

[![Latest Version on Packagist](https://camo.githubusercontent.com/605649d78eb82d9c36ad63e115cdb12f0b461c22e2bdacafa5b83887c336a0f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656e626a75727374726f6d2f73716c6974652d7665632d73636f75742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/benbjurstrom/sqlite-vec-scout)[![GitHub Tests Action Status](https://camo.githubusercontent.com/acef3cbee0ea52d29042dfcd315424683e00e7b8224cc694a2ac746f53446d44/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62656e626a75727374726f6d2f73716c6974652d7665632d73636f75742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/benbjurstrom/sqlite-vec-scout/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/62fdf9a9056977864f93ec17c7daa80665b10181fe88adaf7893bbb1dbe99a6f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62656e626a75727374726f6d2f73716c6974652d7665632d73636f75742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/benbjurstrom/sqlite-vec-scout/actions?query=workflow%3A)

sqlite-vec driver for Laravel Scout
===================================

[](#sqlite-vec-driver-for-laravel-scout)

Use the [sqlite-vec](https://github.com/asg017/sqlite-vec) extension with Laravel Scout for vector similarity search.

🚀 Quick Start
-------------

[](#-quick-start)

#### 1. Install the package using composer:

[](#1-install-the-package-using-composer)

```
composer require benbjurstrom/sqlite-vec-scout
```

#### 2. Publish the scout config and the package config:

[](#2-publish-the-scout-config-and-the-package-config)

```
php artisan vendor:publish --tag="scout-config"
php artisan vendor:publish --tag="sqlite-vec-scout-config"
```

This is the contents of the published `sqlite-vec-scout.php` config file. By default it contains 3 different indexes, one for OpenAI, one for Google Gemini, and one for testing. The rest of this guide will use the OpenAI index as an example.

```
return [
    /*
    |--------------------------------------------------------------------------
    | sqlite-vec Extension Path
    |--------------------------------------------------------------------------
    |
    | Point this to your compiled vec0 module when PDO::loadExtension is
    | available. Leave it null when sqlite-vec is baked into your PHP binary.
    |
    */
    'extension_path' => env('SQLITE_VEC_EXTENSION_PATH'),

    /*
    |--------------------------------------------------------------------------
    | Embedding Index Configurations
    |--------------------------------------------------------------------------
    |
    | Here you can define the configuration for different embedding indexes.
    | Each index can have its own specific configuration options.
    |
    */
    'indexes' => [
        'openai' => [
            'handler' => Handlers\OpenAiHandler::class,
            'model' => 'text-embedding-3-small',
            'dimensions' => 256, // See Reducing embedding dimensions https://platform.openai.com/docs/guides/embeddings#use-cases
            'url' => 'https://api.openai.com/v1',
            'api_key' => env('OPENAI_API_KEY'),
            'table' => 'openai_embeddings',
        ],
        'gemini' => [
            'handler' => Handlers\GeminiHandler::class,
            'model' => 'text-embedding-004',
            'dimensions' => 256,
            'url' => 'https://generativelanguage.googleapis.com/v1beta',
            'api_key' => env('GEMINI_API_KEY'),
            'table' => 'gemini_embeddings',
            'task' => 'SEMANTIC_SIMILARITY', // https://ai.google.dev/api/embeddings#tasktype
        ],
        'ollama' => [
            'handler' => Handlers\OllamaHandler::class,
            'model' => 'nomic-embed-text',
            'dimensions' => 768,
            'url' => 'http://localhost:11434/api/embeddings',
            'api_key' => 'none',
            'table' => 'ollama_embeddings',
        ],
        'fake' => [ // Used for testing
            'handler' => Handlers\FakeHandler::class,
            'model' => 'fake',
            'dimensions' => 3,
            'url' => 'https://example.com',
            'api_key' => '123',
            'table' => 'fake_embeddings',
        ],
    ],
];
```

#### 3. Set the scout driver to sqlite-vec in your .env file and add your OpenAI API key:

[](#3-set-the-scout-driver-to-sqlite-vec-in-your-env-file-and-add-your-openai-api-key)

```
SCOUT_DRIVER=sqlite-vec
OPENAI_API_KEY=your-api-key
```

#### 4. Run the scout index command to create a migration file for your embeddings:

[](#4-run-the-scout-index-command-to-create-a-migration-file-for-your-embeddings)

```
php artisan scout:index openai
php artisan migrate
```

#### 5. Update the model you wish to make searchable:

[](#5-update-the-model-you-wish-to-make-searchable)

Add the `HasEmbeddings` and `Searchable` traits to your model. Additionally add a `searchableAs()` method that returns the name of your index. Finally implement `toSearchableArray()` with the content from the model you want converted into an embedding.

```
use BenBjurstrom\SqliteVecScout\Models\Concerns\HasEmbeddings;
use Laravel\Scout\Searchable;

class YourModel extends Model
{
    use HasEmbeddings, Searchable;

    /**
     * Get the name of the index associated with the model.
     */
    public function searchableAs(): string
    {
        return 'openai';
    }

    /**
     * Get the indexable content for the model.
     */
    public function toSearchableArray(): array
    {
        return [
            'title' => $this->title,
            'content' => $this->content,
        ];
    }
}
```

🔍 Usage
-------

[](#-usage)

### Create embeddings for your models:

[](#create-embeddings-for-your-models)

Laravel Scout uses eloquent model observers to automatically keep your search index in sync anytime your Searchable models change.

This package uses this functionality automatically generate embeddings for your models when they are saved or updated; or remove them when your models are deleted.

If you want to manually generate embeddings for existing models you can use the artisan command below. See the [Scout documentation](https://laravel.com/docs/8.x/scout) for more information.

```
artisan scout:import "App\Models\YourModel"
```

### Search using vector similarity:

[](#search-using-vector-similarity)

You can use the typical Scout syntax to search your models. For example:

```
$results = YourModel::search('your search query')->get();
```

Note that the text of your query will be converted into a vector embedding using the model index's configured handler. It's important that the same model is used for both indexing and searching.

### Search using existing vectors:

[](#search-using-existing-vectors)

You can also pass an existing embedding vector as a search parameter. This can be useful to find related models. For example:

```
$vector = $someModel->embedding->vector;
$results = YourModel::search($vector)->get();
```

### Evaluate search results:

[](#evaluate-search-results)

All search queries will be ordered by similarity to the given input and include the embedding relationship. The value of the nearest neighbor search can be accessed as follows:

```
$results = YourModel::search('your search query')->get();
$results->first()->embedding->neighbor_distance; // 0.26834 (example value)
```

The larger the distance the less similar the result is to the input.

🛠Using custom handlers
----------------------

[](#using-custom-handlers)

By default this package uses OpenAI to generate embeddings. To do this it uses the [OpenAiHandler](https://github.com/benbjurstrom/sqlite-vec-scout/blob/main/src/Handlers/OpenAiHandler.php) class paired with the openai index found in the packages [config file](https://github.com/benbjurstrom/sqlite-vec-scout/blob/main/config/sqlite-vec-scout.php).

You can generate embeddings from other providers by adding a custom Handler. A handler is a simple class defined in the [HandlerContract](https://github.com/benbjurstrom/sqlite-vec-scout/blob/main/src/HandlerContract.php) that takes a string, a config object, and returns a `BenBjurstrom\\SqliteVecScout\\Vector` instance.

Whatever api calls or logic is needed to turn a string into a vector should be defined in the `handle` method of your custom handler.

If you need to pass api keys, embedding dimensions, or any other configuration to your handler you can define them in the `config/sqlite-vec-scout.php` file.

Installing sqlite-vec locally
-----------------------------

[](#installing-sqlite-vec-locally)

The native `sqlite-vec` extension **must** be loaded on the same SQLite connection that Laravel uses. The service provider validates this at boot time and will throw a runtime exception if `vec0` is unavailable.

`sqlite-vec` ships as a small SQLite extension that can be compiled from source or installed via language-specific packages. For PHP-specific guidance on compiling binaries with extension loading enabled — including a full static-php-cli build script — read Ben Bjurstrom's guide: .

To see if your current PHP binary can load extensions dynamically run:

```
php -d detect_unicode=0 -r 'var_dump(method_exists(new PDO("sqlite::memory:"), "loadExtension"));'
```

When the command prints `bool(true)`, download a `vec0` build, expose its full path via `SQLITE_VEC_EXTENSION_PATH` (or the `sqlite-vec-scout.extension_path` config key), and the service provider will call `PDO::loadExtension()` before validating the module. If the command returns `bool(false)` you must compile sqlite-vec directly into PHP — the blog post above demonstrates how to do this with static-php-cli and ensures the `SQLITE_ENABLE_LOAD_EXTENSION` flag is set for both `sqlite3` and `pdo_sqlite`.

👏 Credits
---------

[](#-credits)

- [Ben Bjurstrom](https://github.com/benbjurstrom)
- [All Contributors](../../contributors)

📝 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance71

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

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

194d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c6e87e7d26b161a120d9f149fabc989bf2d5bcccee4e9972867b477d336b92b?d=identicon)[benbjurstrom](/maintainers/benbjurstrom)

---

Top Contributors

[![benbjurstrom](https://avatars.githubusercontent.com/u/12499093?v=4)](https://github.com/benbjurstrom "benbjurstrom (3 commits)")

---

Tags

laravelBen Bjurstromsqlite-vecsqlite-vec-scout

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-site-search

A site search engine

300129.1k](/packages/spatie-laravel-site-search)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ivanomatteo/laravel-scout-fulltext-engine

A scout DB fulltext-based driver that store index data in related tables

101.1k](/packages/ivanomatteo-laravel-scout-fulltext-engine)

PHPackages © 2026

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