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.
symfony/ai-memory-store or symfony/ai-postgresql-store.neo4j-php-client. Laravel can deploy this via Docker or a managed service (e.g., AuraDB).CREATE SEMANTIC INDEX `document_embeddings`
FOR (d:Document)
OPTIONS {indexConfig: {
`vector.dimensions`: 768,
`vector.similarity_function`: 'cosine',
`vector.index_type`: 'vector-hnsw'
}}
VectorStoreInterface to the Neo4j store in Laravel’s service container:
$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()
);
});
LOAD CSV or custom Laravel jobs. Example:
LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS row
CREATE (:Document {
text: row.content,
embedding: apoc.convert.fromJsonList(row.vector),
metadata: apoc.convert.fromJsonMap(row.metadata)
})
| Risk | Mitigation Strategy |
|---|---|
| Neo4j Driver Instability | Pin neo4j/neo4j-php-client to a stable version (e.g., ^5.0) and test with Laravel’s PHP unit suite. |
| Symfony Laravel Incompatibility | Abstract Symfony interfaces behind Laravel contracts (e.g., VectorStoreInterface) to ensure decoupling. |
| Vector Index Performance | Benchmark with real-world queries (e.g., MATCH (n) WHERE vectorSimilarity(n.embedding, $query) > 0.8) and compare against alternatives like pgvector. |
| Schema Rigidity | Design flexible Neo4j labels (e.g., :Document, :Entity) and use property inheritance to avoid costly migrations. |
| Neo4j Licensing Costs | Evaluate AuraDB (managed) or community edition for cost-sensitive projects; negotiate enterprise licenses if needed. |
| Cold Start Latency | Implement warm-up queries in Laravel’s bootstrapping or use a Redis cache layer for frequent queries. |
pgvector) suffice for the use case?author = X AND year > 2020 AND category IN ['AI', 'ML']").EXPLAIN plans, latency metrics).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 with Laravel-friendly methods...
}
neo4j/neo4j-php-client (v5+ for vector support).Post → :Document, User → :Author).:Document {text: string, embedding: float[], category: string}).CREATE CONSTRAINT ON (d:Document) ASSERT d.id IS UNIQUE).LOAD CSV for bulk imports or Laravel jobs for incremental updates:
// Example Laravel job for bulk import
public function handle() {
$records = Model::chunk(1000, function ($chunk) {
$this->neo4jClient->run(
'UNWIND $records AS r
CREATE (d:Document {
text: r.content,
embedding: apoc.convert.fromJsonList(r.vector),
metadata: apoc.convert.fromJsonMap(r.metadata)
})',
['records' => $chunk->toArray()]
);
});
}
composer require symfony/ai-neo4j-store neo4j/neo4j-php-client
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'))
->withBasicAuth(env('NEO4J_USER'), env('NEO4J_PASSWORD'))
->build()
);
});
}
public function testNeo4jVectorStore() {
$store = $this->app->make(\Symfony\Component\AI\VectorStoreInterface::class);
$embedding = [1.0, 2.0, 3.0];
$store->add($embedding);
$results = $store->similaritySearch([1.1, 2.1, 3.1]);
$this->assertCount(1, $results);
}
$results = $store->similaritySearch([1.1, 2.1, 3.1], [
'
How can I help you explore Laravel packages today?