Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ai Postgres Store Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Vector Store Integration: The package provides a PostgreSQL-pgvector bridge for Symfony AI’s 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.
  • Laravel Adaptability: While designed for Symfony, the package can be abstracted via Laravel’s service container or Doctrine DBAL, minimizing framework lock-in. The use of PostgreSQL’s native vector types (vector, halfvec) ensures high performance, comparable to dedicated vector databases.
  • Hybrid Search Capability: Combines pgvector’s vector operations with PostgreSQL’s full-text search, enabling complex queries (e.g., "find items similar to X and matching keyword Y"). This is a key differentiator for advanced search use cases.
  • Extensibility: Supports filtering, batch operations, and metadata, which can be exposed via Laravel’s query builder or Eloquent events, making it adaptable to domain-specific needs.

Integration Feasibility

  • Symfony-Laravel Bridge:
    • Feasible: The package’s dependency on Symfony’s 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.
    • Risk: Potential version skew if Symfony AI evolves faster than Laravel’s ecosystem. Mitigate by pinning Symfony dependencies or implementing an adapter pattern to isolate changes.
  • PostgreSQL Dependencies:
    • Critical: Requires pgvector extension (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.
    • Performance: pgvector’s HNSW index delivers sub-100ms latency for <1M vectors. Benchmark raw vs. wrapped queries to validate Laravel’s ORM overhead.
  • Query Complexity:
    • Supports filtering, hybrid search, and metadata operations, but complex queries may require Doctrine DBAL for optimal performance. Validate with real-world query patterns before full adoption.

Technical Risk

  • Version Alignment:
    • Symfony AI’s Store interface may change. Risk mitigated by:
      • Using Symfony’s symfony/ai as a direct dependency (not just this package).
      • Implementing a Laravel-specific adapter layer to abstract Symfony-specific code.
    • Laravel Compatibility: Test with Laravel 10/11 and PHP 8.1+; avoid Symfony’s HttpFoundation or Console components to minimize bloat.
  • Schema Evolution:
    • pgvector updates (e.g., new distance metrics) may require schema migrations. Use Laravel’s schema builder with raw SQL fallbacks for flexibility.
  • Monitoring Gaps:
    • Lack of Laravel-native metrics for vector operations. Implement custom logging or integrate with PostgreSQL’s pg_stat_statements for observability.
  • Scaling Limits:
    • pgvector performs well for <10M vectors but may require partitioning or sharding for larger datasets. Plan for horizontal scaling if needed.

Key Questions

  1. Use Case Criticality:
    • Is this for high-traffic search (e.g., e-commerce) or low-volume analytics? Scale expectations differ (e.g., pgvector’s 1M vector limit for sub-100ms latency).
  2. Existing Infrastructure:
    • Does the team use PostgreSQL + pgvector? If not, assess extension installation and DBA resources for setup.
  3. Laravel-Symfony Tradeoffs:
    • Will the team fully abstract Symfony or embrace dual-stack? Affects long-term maintainability and team expertise.
  4. Scaling Requirements:
    • Will vectors exceed 1M? Plan for partitioning (e.g., by embedding_id ranges) or sharding (pgvector supports both).
  5. Hybrid Search Needs:
    • Does the use case require vector + full-text filtering? Validate pgvector’s GIN index performance for JSON metadata and complex queries.
  6. Cost vs. Control:
    • Compare pgvector’s TCO (existing PostgreSQL) vs. managed services (e.g., Pinecone). Document cloud cost savings and operational tradeoffs.
  7. Team Expertise:
    • Does the team have PostgreSQL/pgvector experience? If not, budget for training or DBA support during setup.
  8. Fallback Strategy:
    • What’s the recovery plan if pgvector queries degrade under load? Consider circuit breakers or fallback to a managed service.

Integration Approach

Stack Fit

  • Core Components:
    • Laravel 10/11: Use Symfony’s symfony/ai and symfony/ai-postgres-store as composer dependencies. Leverage Laravel’s service container to bind the store.
    • PostgreSQL 13+: pgvector requires PostgreSQL 13+ (for full functionality, including halfvec type and advanced indexing).
    • Doctrine DBAL: For raw PostgreSQL queries if Eloquent’s limitations (e.g., no vector type support) are prohibitive. Use for performance-critical paths.
    • Optional:
      • Redis: Cache frequent vector queries or embeddings to reduce PostgreSQL load.
      • Laravel Scout: If hybrid search is needed alongside existing Elasticsearch/Algolia integrations, evaluate dual-store synchronization.
  • Alternatives:
    • Lightweight Needs: If hybrid search isn’t required, consider Laravel-specific packages like spatie/laravel-pgvector (simpler but less feature-rich).
    • Symfony-First: If the team is fully adopting Symfony, use this package natively without Laravel abstraction.

Migration Path

  1. Phase 0: Pre-Requisites

    • Install pgvector extension in PostgreSQL:
      CREATE EXTENSION vector;
      
    • Verify PostgreSQL version (13+ required):
      SELECT version();
      
    • Update CI/CD pipelines to include pgvector extension installation for test/staging environments.
  2. Phase 1: Dependency Setup

    • Add to 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
        }
      }
      
    • Run composer install and composer dump-autoload.
  3. Phase 2: Laravel Service Binding

    • Create a service provider (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',
                      ])
                  );
              });
          }
      }
      
    • Register the provider in config/app.php:
      'providers' => [
          // ...
          App\Providers\VectorStoreServiceProvider::class,
      ],
      
    • Publish config (optional):
      php artisan vendor:publish --provider="Symfony\AI\PostgresStore\PostgresStoreServiceProvider"
      
      Then customize config/ai/postgres_store.php.
  4. Phase 3: Schema Migration

    • Create a migration for the vector table (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();
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky