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.agent.openai import OpenAIAgent

llm = OpenAI(model="gpt-4", openai_api_key="XXXX-XXXX", temperature=0)

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

tools = gds_db.to_tool_list()
agent = OpenAIAgent.from_tools(tools, verbose=True)

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
agent.chat("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.3.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

llama_index_tools_neo4j-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llama_index_tools_neo4j-0.3.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0

File hashes

Hashes for llama_index_tools_neo4j-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bbd57159c366f955a51e46b4f523d08c848f4bb20641bf594aeda64a450296d4
MD5 ef58f09947661402892406d48be0416e
BLAKE2b-256 0f28002458ad555d76c8fa1ca5c828013e18da6732f419ae9e52062c23aa4aeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_tools_neo4j-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9b34b5a1359c53cc1b5417dcd389a7b273ef68a996f4d4c8e5500e3980049c6
MD5 671c04094a49d3c4d51fab3cb80091b8
BLAKE2b-256 62354160f05a1583879344b4c0246f2236e30127d548d28f714c796e37ce01aa

See more details on using hashes here.

Supported by

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