Neo4j Graph Vector Database
The Neo4j plugin provides indexer and retriever implementations that use the Neo4j graph database for vector search capabilities.
Neo4j is a graph database that combines the power of graph relationships with vector search capabilities. It enables you to store documents as nodes with vector embeddings while maintaining rich relationships between entities, making it ideal for knowledge graphs, recommendation systems, and complex AI applications that need both semantic search and graph traversal.
Installation
Section titled “Installation”npm install genkitx-neo4j
Configuration
Section titled “Configuration”To use this plugin, specify it when you initialize Genkit:
import { genkit } from 'genkit';import { neo4j } from 'genkitx-neo4j';import { googleAI } from '@genkit-ai/google-genai';
const ai = genkit({ plugins: [ neo4j([ { indexId: 'bob-facts', embedder: googleAI.embedder('gemini-embedding-001'), }, ]), ],});
You must specify a Neo4j index ID and the embedding model you want to use.
Connection Configuration
Section titled “Connection Configuration”There are two ways to configure the Neo4j connection:
- Using environment variables:
NEO4J_URI=bolt://localhost:7687 # Neo4j's binary protocolNEO4J_USERNAME=neo4jNEO4J_PASSWORD=passwordNEO4J_DATABASE=neo4j # Optional: specify database name
- Using the
clientParams
option:
neo4j([ { indexId: 'bob-facts', embedder: googleAI.embedder('gemini-embedding-001'), clientParams: { url: 'bolt://localhost:7687', // Neo4j's binary protocol username: 'neo4j', password: 'password', database: 'neo4j', // Optional }, },]),
Note: The
bolt://
protocol is Neo4j’s proprietary binary protocol designed for efficient client-server communication.
Configuration Options
Section titled “Configuration Options”The Neo4j plugin accepts the following configuration options:
indexId
: (required) The name of the index to use in Neo4jembedder
: (required) The embedding model to useclientParams
: (optional) Neo4j connection configuration
Import retriever and indexer references like so:
import { neo4jRetrieverRef } from 'genkitx-neo4j';import { neo4jIndexerRef } from 'genkitx-neo4j';
Retrieval
Section titled “Retrieval”Use the retriever reference with ai.retrieve()
:
// To use the index you configured when you loaded the plugin:let docs = await ai.retrieve({ retriever: neo4jRetrieverRef, query, // Optional: limit number of results (max 1000) k: 5,});
// To specify an index:export const bobFactsRetriever = neo4jRetrieverRef({ indexId: 'bob-facts', // Optional: custom display name displayName: 'Bob Facts Database',});docs = await ai.retrieve({ retriever: bobFactsRetriever, query, k: 10,});
Indexing
Section titled “Indexing”Use the indexer reference with ai.index()
:
// To use the index you configured when you loaded the plugin:await ai.index({ indexer: neo4jIndexerRef, documents });
// To specify an index:export const bobFactsIndexer = neo4jIndexerRef({ indexId: 'bob-facts', // Optional: custom display name displayName: 'Bob Facts Database',});await ai.index({ indexer: bobFactsIndexer, documents });
See the Retrieval-augmented generation page for a general discussion on indexers and retrievers.
Learn More
Section titled “Learn More”For more information, feedback, or to report issues, visit the Neo4j plugin GitHub repository.