benbjurstrom/pgvector-scout
Laravel Scout driver for PostgreSQL pgvector. Store embeddings on your models and run fast vector similarity search directly in Postgres. Supports multiple embedding indexes (OpenAI, Gemini, testing) with publishable config and easy setup.
Start by installing the package and publishing its config:
composer require benbjurstrom/pgvector-scout
php artisan vendor:publish --tag="pgvector-scout-config"
php artisan vendor:publish --tag="scout-config"
Configure an embedding index (e.g., openai) in config/pgvector-scout.php, set SCOUT_DRIVER=pgvector, and install pgvector in PostgreSQL (via CREATE EXTENSION IF NOT EXISTS vector;). Then, run php artisan scout:index openai to generate the migration, and php artisan migrate. Finally, add HasEmbeddings and Searchable traits to your model, define searchableAs() and toSearchableArray()—and you're ready to embed and search.
saved, updated, and deleted events—no manual intervention needed.openai, gemini, ollama) for different model sizes or providers. Use searchableAs() in your model to bind it to a specific index.$similar = Model::search($vector)->get();.whereSearchable() to pre-filter via regular Eloquent conditions before vector comparison, drastically reducing compute cost for large tables:
Model::search('query')
->whereSearchable(fn($q) => $q->where('status', 'active'))
->get();
EmbeddingSaved event for logging, metrics, or external notification of embedding operations.where filters and orderBy on non-vector columns after the vector scan (e.g., post-filter by relevance score or date).dimensions in config/pgvector-scout.php exactly match the provider’s output (e.g., OpenAI text-embedding-3-small defaults to 1536; overriding to 256 requires explicit reduction via the provider API). Mismatched dimensions cause silent query errors or corrupted results.url, api_key, model) are updated and credentials are valid. Test with the fake index first.delete(), but you must use SoftDeletes on your model. Verify scout:sync-indexes isn’t skipping soft-deleted records.whereSearchable() to narrow the candidate set. pgvector’s index scan (ANN) is efficient, but full scans on millions of rows still dominate latency.whereHasMorph refactor in v0.3.0).fake index for unit tests to avoid real API calls—define a custom handler that returns predictable vectors in config/pgvector-scout.php during testing environment.Scout::filterUsing(fn ($builder) => $builder->tap(fn ($q) => dump($q->toSql()))); to inspect generated SQL—including <-> cosine distance comparisons.How can I help you explore Laravel packages today?