Skip to main content

llama-index tools neo4j integration

Project description

Neo4j Schema Query Builder

pip install llama-index-tools-neo4j

The Neo4jQueryToolSpec class provides a way to query a Neo4j graph database based on a provided schema definition. The class uses a language model to generate Cypher queries from user questions and has the capability to recover from Cypher syntax errors through a self-healing mechanism.

Table of Contents

Usage

Initialization

Initialize the Neo4jQueryToolSpec class with:

from llama_index.tools.neo4j import Neo4jQueryToolSpec
from llama_index.llms.openai import OpenAI
from llama_index.core.agent.workflow import FunctionAgent

gds_db = Neo4jQueryToolSpec(
    url="neo4j-url",
    user="neo4j-user",
    password="neo4j=password",
    llm=llm,
    database="neo4j",
)

tools = gds_db.to_tool_list()
agent = FunctionAgent(
    tools=tools,
    llm=OpenAI(model="gpt-4.1"),
)

Where:

  • url: Connection string for the Neo4j database.
  • user: Username for the Neo4j database.
  • password: Password for the Neo4j database.
  • llm: A language model for generating Cypher queries (any type of LLM).
  • database: The database name.

Running a Query

To use the agent:

# use agent
resp = await agent.run("Where is JFK airport is located?")
Generated Cypher:

MATCH (p:Port {port_code: 'JFK'})
RETURN p.location_name_wo_diacritics AS Location

Final answer:
'The port code JFK is located in New York, United States.'

Features

  • Schema-Based Querying: The class extracts the Neo4j database schema to guide the Cypher query generation.
  • Self-Healing: On a Cypher syntax error, the class corrects itself to produce a valid query.
  • Language Model Integration: Uses a language model for natural and accurate Cypher query generation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_neo4j-0.4.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_tools_neo4j-0.4.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_tools_neo4j-0.4.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_tools_neo4j-0.4.1.tar.gz
Algorithm Hash digest
SHA256 0a103e6ee1fd4e2eba738d3266b1afef9c9251d83279b2bcb24af77185448af7
MD5 980d5eaeb5112e644d759d0480aada5d
BLAKE2b-256 2ddedd70f69eb7cde9e060a048ced44ab27c71c4ad9327b8665c06cdffe55abb

See more details on using hashes here.

File details

Details for the file llama_index_tools_neo4j-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_tools_neo4j-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbcbcc96a01d76504a2a4568af1da67cfb0f52c0d9aaa9f68056703d7bf6d5b8
MD5 d322ca61eaad21272d8504dbf55792c9
BLAKE2b-256 fbf9974b3bf93961486e7a5d8b5402f028524dbf056364b51290e2ca13ed6e07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page