Rig-Neo4j Integration
The rig-neo4j
crate provides a vector store implementation using Neo4j as the underlying datastore. This integration allows for efficient vector-based searches within a Neo4j graph database, leveraging Neo4j’s vector index capabilities.
Key Features
- Vector Indexing: Supports creating and querying vector indexes in Neo4j, enabling semantic search capabilities.
- Integration with OpenAI: Utilizes OpenAI’s embedding models to generate vector representations of data.
- Flexible Querying: Offers methods to perform top-N searches and retrieve node IDs based on vector similarity.
- Customizable Index Configuration: Allows configuration of index properties such as dimensions and similarity functions.
Prerequisites
- Neo4j GenAI Plugin: Required for vector indexing capabilities. Enabled by default in Neo4j Aura or can be installed on self-managed instances.
- Pre-existing Vector Index: The Neo4j vector index must be created before performing searches. This can be done using the Neo4j browser, Cypher queries, or the
Neo4jClient::create_vector_index
method.
Usage
Setup
Add the rig-neo4j
crate to your Cargo.toml
:
[dependencies]
rig-neo4j = "0.2.0"
Example Workflow
- Connect to Neo4j: Establish a connection using the
Neo4jClient
.
let neo4j_client = Neo4jClient::connect("neo4j://localhost:7687", "username", "password").await?;
- Create Vector Index: Define and create a vector index on your data.
neo4j_client.create_vector_index(
IndexConfig::new("moviePlots"),
"Movie",
&model
).await?;
- Perform Vector Search: Query the vector index for similar nodes.
let results = index.top_n::<Movie>("a historical movie on quebec", 5).await?;
Example Code
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let neo4j_client = Neo4jClient::connect("neo4j://localhost:7687", "username", "password").await?;
let model = openai_client.embedding_model(TEXT_EMBEDDING_ADA_002);
neo4j_client.create_vector_index(
IndexConfig::new("moviePlots"),
"Movie",
&model
).await?;
let index = neo4j_client.get_index(model, "moviePlots", SearchParams::default()).await?;
let results = index.top_n::<Movie>("a historical movie on quebec", 5).await?;
println!("{:#?}", results);
Ok(())
}
Additional Resources
- Examples: See the examples directory for detailed usage scenarios.
- Neo4j Documentation: Refer to the Neo4j vector index documentation for more information on setting up and using vector indexes.