symfony/ai-postgres-store
Symfony AI Store integration for PostgreSQL using pgvector. Store and query embeddings with Postgres vector/halfvec types, distance operators, and indexing options. Links to pgvector docs plus Symfony AI contribution and issue resources.
Store interface, enabling semantic search, recommendations, and hybrid search in Laravel applications. Its alignment with pgvector ensures efficient vector storage and similarity search without external dependencies, reducing latency and operational overhead.vector, halfvec) ensures high performance, comparable to dedicated vector databases.Store interface can be wrapped in a Laravel service provider or facade with minimal boilerplate. The core functionality (vector CRUD, similarity search) is framework-agnostic.CREATE EXTENSION vector;), which may need DBA coordination or CI/CD updates for provisioning. Laravel’s Eloquent lacks native support for vector columns, requiring raw SQL or custom migrations.Store interface may change. Risk mitigated by:
symfony/ai as a direct dependency (not just this package).HttpFoundation or Console components to minimize bloat.pg_stat_statements for observability.embedding_id ranges) or sharding (pgvector supports both).symfony/ai and symfony/ai-postgres-store as composer dependencies. Leverage Laravel’s service container to bind the store.halfvec type and advanced indexing).vector type support) are prohibitive. Use for performance-critical paths.spatie/laravel-pgvector (simpler but less feature-rich).Phase 0: Pre-Requisites
CREATE EXTENSION vector;
13+ required):
SELECT version();
Phase 1: Dependency Setup
composer.json:
{
"require": {
"symfony/ai": "^0.8",
"symfony/ai-postgres-store": "^0.8",
"doctrine/dbal": "^3.6", // For raw PostgreSQL queries
"symfony/console": "^6.3" // If using Symfony CLI commands (optional)
},
"replace": {
"symfony/console": "self.version" // Avoid version conflicts
}
}
composer install and composer dump-autoload.Phase 2: Laravel Service Binding
app/Providers/VectorStoreServiceProvider.php):
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\AI\Store\PostgresStore;
use Doctrine\DBAL\Connection;
use Illuminate\Support\Facades\DB;
class VectorStoreServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('ai.vector_store', function ($app) {
$connection = DB::connection('pgsql')->getDoctrineConnection();
return new PostgresStore(
$connection,
config('database.connections.pgsql.schema'),
config('ai.postgres_store', [
'table' => 'vector_embeddings',
'embedding_column' => 'embedding',
'id_column' => 'id',
])
);
});
}
}
config/app.php:
'providers' => [
// ...
App\Providers\VectorStoreServiceProvider::class,
],
php artisan vendor:publish --provider="Symfony\AI\PostgresStore\PostgresStoreServiceProvider"
Then customize config/ai/postgres_store.php.Phase 3: Schema Migration
database/migrations/xxxx_create_vector_embeddings_table.php):
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up() {
Schema::connection('pgsql')->create('vector_embeddings', function (Blueprint $table) {
$table->id();
$table->string('metadata')->nullable();
How can I help you explore Laravel packages today?