Skip to main content

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.

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.6.0.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.6.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llama_index_tools_neo4j-0.6.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_neo4j-0.6.0.tar.gz
Algorithm Hash digest
SHA256 49f98bd9f42a2a8504bc99cbeae8dd489623fe114149abeedcb39106c4192c89
MD5 fc0255bb712918337806eee5785f3ae5
BLAKE2b-256 74449603c3c9adfd74822155acafdf19b8bee956196ae9bfa62437b2f61c4301

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llama_index_tools_neo4j-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_neo4j-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ad9b3021006f1028ff65140558a56405d3b4bd442b017163f749534220c2cdd
MD5 6473dd004caf0342398bb00ed830ce05
BLAKE2b-256 8412959e680eea9a5cce001730875cef18f412a1b6de3f502436680ee4437d01

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page