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 Neo4J Store Laravel Package

symfony/ai-neo4j-store

Neo4j Store integration for Symfony AI Store, enabling use of Neo4j as a vector store with support for vector indexes. Includes links to Neo4j documentation and Symfony AI resources for contributing and reporting issues.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Hybrid Graph-Vector Synergy: The package excels in Laravel/PHP applications requiring semantic search with graph context (e.g., knowledge graphs, recommendation engines). Neo4j’s native vector indexes enable low-latency similarity search while preserving relational data, aligning with Laravel’s strengths in structured data and relationships (e.g., Eloquent ORM).
  • Symfony AI Ecosystem: If the Laravel app uses Symfony AI components (e.g., for embeddings or LLM orchestration), this package provides a seamless integration path. For pure Laravel, minimal abstraction (e.g., a facade or service layer) is needed to decouple Symfony dependencies, avoiding vendor lock-in.
  • Use Case Alignment:
    • Strengths: Ideal for complex retrieval (e.g., "Find patents citing quantum computing authored by MIT after 2020").
    • Weaknesses: Overkill for simple vector search (e.g., chatbot context windows). Consider symfony/ai-memory-store for lightweight use cases.

Integration Feasibility

  • Neo4j Dependency:
    • Requires Neo4j 5.12+ (for semantic indexes) and the neo4j-php-client. Laravel can host this via Docker or a managed service (e.g., AuraDB).
    • Schema Setup: Vector indexes must be pre-configured via Cypher (one-time cost). Example:
      CREATE SEMANTIC INDEX `embedding_index`
      FOR (n:Node)
      OPTIONS {indexConfig: {
        `vector.dimensions`: 768,
        `vector.similarity_function`: 'cosine'
      }}
      
  • Symfony AI Bridge:
    • Laravel must bind Symfony’s VectorStoreInterface to the Neo4j store. Example:
      $this->app->bind(\Symfony\Component\AI\VectorStoreInterface::class, function ($app) {
          return new \Symfony\Component\AI\Store\Neo4jStore(
              new \Neo4j\ClientBuilder()->withUri(env('NEO4J_URI'))->build()
          );
      });
      
  • Data Migration:
    • No built-in tools; use Cypher LOAD CSV or custom scripts. Example:
      LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS row
      CREATE (:Document {text: row.content, embedding: apoc.convert.fromJsonList(row.vector)})
      

Technical Risk

Risk Mitigation
Neo4j Driver Instability Pin neo4j/neo4j-php-client to a stable version (e.g., ^5.0). Test with Laravel’s PHP unit.
Symfony Laravel Incompatibility Abstract Symfony interfaces behind Laravel contracts (e.g., VectorStoreInterface).
Vector Index Performance Benchmark with real-world queries (e.g., MATCH (n) WHERE vectorSimilarity(n.embedding, $query) > 0.8).
Schema Rigidity Design flexible Neo4j labels (e.g., :Document, :Entity) to avoid costly migrations.
Neo4j Licensing Costs Evaluate AuraDB (managed) or community edition for cost-sensitive projects.

Key Questions

  1. Is Neo4j’s graph context a hard requirement, or could a simpler vector store (e.g., pgvector) suffice?
  2. What’s the expected query pattern? Neo4j excels at graph-aware filtering (e.g., "Find embeddings where author = X AND year > 2020").
  3. How will data be ingested? Bulk loads via Cypher or incremental updates via Laravel jobs?
  4. What’s the fallback if Neo4j’s vector search is too slow? Consider hybrid caching (e.g., Redis for hot vectors).
  5. Are there existing Neo4j graphs to leverage, or will this require a new schema?

Integration Approach

Stack Fit

  • Laravel + Symfony AI:
    • Option 1: Use Symfony AI’s VectorStoreInterface directly (if Laravel can tolerate Symfony dependencies).
    • Option 2: Create a Laravel-compatible facade to hide Symfony classes:
      namespace App\Services;
      
      use Symfony\Component\AI\VectorStoreInterface;
      use Neo4j\ClientBuilder;
      
      class Neo4jVectorStore implements \Symfony\Component\AI\VectorStoreInterface {
          public function __construct(private VectorStoreInterface $store) {}
          // Delegate to Symfony store...
      }
      
  • Neo4j Compatibility:
    • Driver: neo4j/neo4j-php-client (v5+ for vector support).
    • Schema: Requires semantic indexes (configured via Cypher).
    • Alternatives: If Neo4j is overkill, consider:
      • PostgreSQL + pgvector (for simpler vector search).
      • Milvus/Weaviate (for distributed scaling).

Migration Path

  1. Assess Current State:
    • Audit existing vector storage (e.g., Elasticsearch, flat files).
    • Map entities to Neo4j nodes (e.g., Post:Document with embedding property).
  2. Schema Design:
    • Define labels/properties (e.g., :Document {text: string, embedding: float[], category: string}).
    • Plan for semantic index creation (one-time setup).
  3. Data Migration:
    • Use Cypher LOAD CSV or Laravel jobs to import data:
      // Example Laravel job for bulk import
      public function handle() {
          $records = Model::all()->toArray();
          $this->neo4jClient->run('UNWIND $records AS r CREATE (:Document {text: r.content, embedding: r.vector})', ['records' => $records]);
      }
      
  4. Laravel Integration:
    • Install dependencies:
      composer require symfony/ai-neo4j-store neo4j/neo4j-php-client
      
    • Bind the store in AppServiceProvider:
      public function register() {
          $this->app->singleton(\Symfony\Component\AI\VectorStoreInterface::class, function ($app) {
              return new \Symfony\Component\AI\Store\Neo4jStore(
                  new \Neo4j\ClientBuilder()->withUri(env('NEO4J_URI'))->build()
              );
          });
      }
      
  5. Testing:
    • Validate CRUD operations:
      $store = app(\Symfony\Component\AI\VectorStoreInterface::class);
      $store->add([1.0, 2.0, 3.0]); // Test embedding insertion
      $results = $store->similaritySearch([1.1, 2.1, 3.1]); // Test retrieval
      

Compatibility

  • Laravel Versions: Works with Laravel 10+ (PHP 8.1+). Test with your target version.
  • Neo4j Versions: Requires Neo4j 5.12+. Verify compatibility with your driver version.
  • Symfony AI: Must match the package’s dependency range (check composer.json for symfony/ai version).
  • PHP Extensions: No special requirements beyond standard PHP + Neo4j driver.

Sequencing

  1. Phase 1: Proof of Concept (2 weeks)
    • Set up Neo4j with a sample dataset (e.g., 10K embeddings).
    • Implement a minimal Laravel service to test add()/similaritySearch().
    • Benchmark latency vs. alternatives (e.g., pgvector).
  2. Phase 2: Full Integration (4 weeks)
    • Migrate production data to Neo4j via Cypher or Laravel jobs.
    • Replace existing vector store logic with the Symfony bridge.
    • Add monitoring for Neo4j query performance (e.g., EXPLAIN queries).
  3. Phase 3: Optimization (Ongoing)
    • Tune semantic index configurations (e.g., vector.dimensions).
    • Implement caching for frequent queries (e.g., Redis layer).
    • Explore Neo4j read replicas for scaling.

Operational Impact

Maintenance

  • Neo4j Management:
    • Backups: Critical for vector data. Use Neo4j’s built-in backup tools or AuraDB snapshots.
    • Index Maintenance: Semantic indexes may require rebuilding if performance degrades
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony