llama-index-tools-neo4j


Namellama-index-tools-neo4j JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
Summaryllama-index tools neo4j integration
upload_time2025-07-31 02:54:15
maintainershahafp
docs_urlNone
authorNone
requires_python<4.0,>=3.9
licenseNone
keywords cypher graph neo4j
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Neo4j Schema Query Builder

```bash
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](#usage)
  - [Initialization](#initialization)
  - [Running a Query](#running-a-query)
- [Features](#features)

## Usage

### Initialization

Initialize the `Neo4jQueryToolSpec` class with:

```python
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:

```python
# 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-tools-neo4j",
    "maintainer": "shahafp",
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "cypher, graph, neo4j",
    "author": null,
    "author_email": "Your Name <you@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/d4/96/8c7428225c16553b518297ea805ecaa40f3574c22df9e45c7ab316c69f22/llama_index_tools_neo4j-0.4.0.tar.gz",
    "platform": null,
    "description": "# Neo4j Schema Query Builder\n\n```bash\npip install llama-index-tools-neo4j\n```\n\nThe `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.\n\n## Table of Contents\n\n- [Usage](#usage)\n  - [Initialization](#initialization)\n  - [Running a Query](#running-a-query)\n- [Features](#features)\n\n## Usage\n\n### Initialization\n\nInitialize the `Neo4jQueryToolSpec` class with:\n\n```python\nfrom llama_index.tools.neo4j import Neo4jQueryToolSpec\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.core.agent.workflow import FunctionAgent\n\ngds_db = Neo4jQueryToolSpec(\n    url=\"neo4j-url\",\n    user=\"neo4j-user\",\n    password=\"neo4j=password\",\n    llm=llm,\n    database=\"neo4j\",\n)\n\ntools = gds_db.to_tool_list()\nagent = FunctionAgent(\n    tools=tools,\n    llm=OpenAI(model=\"gpt-4.1\"),\n)\n```\n\nWhere:\n\n- `url`: Connection string for the Neo4j database.\n- `user`: Username for the Neo4j database.\n- `password`: Password for the Neo4j database.\n- `llm`: A language model for generating Cypher queries (any type of LLM).\n- `database`: The database name.\n\n### Running a Query\n\nTo use the agent:\n\n```python\n# use agent\nresp = await agent.run(\"Where is JFK airport is located?\")\n```\n\n```\nGenerated Cypher:\n\nMATCH (p:Port {port_code: 'JFK'})\nRETURN p.location_name_wo_diacritics AS Location\n\nFinal answer:\n'The port code JFK is located in New York, United States.'\n```\n\n## Features\n\n- **Schema-Based Querying**: The class extracts the Neo4j database schema to guide the Cypher query generation.\n- **Self-Healing**: On a Cypher syntax error, the class corrects itself to produce a valid query.\n- **Language Model Integration**: Uses a language model for natural and accurate Cypher query generation.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "llama-index tools neo4j integration",
    "version": "0.4.0",
    "project_urls": null,
    "split_keywords": [
        "cypher",
        " graph",
        " neo4j"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5da85099d44f57db98917f1adeef72a70e325ce27870929e44cb8c361b4f8a01",
                "md5": "edcace0e161c5e9f0523244b5c89f203",
                "sha256": "a5e1f9bf97bf4adcfe47cd1f2babbeb6bc44c6e26b45a066238f7fda73951b3d"
            },
            "downloads": -1,
            "filename": "llama_index_tools_neo4j-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "edcace0e161c5e9f0523244b5c89f203",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 7170,
            "upload_time": "2025-07-31T02:54:14",
            "upload_time_iso_8601": "2025-07-31T02:54:14.911417Z",
            "url": "https://files.pythonhosted.org/packages/5d/a8/5099d44f57db98917f1adeef72a70e325ce27870929e44cb8c361b4f8a01/llama_index_tools_neo4j-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d4968c7428225c16553b518297ea805ecaa40f3574c22df9e45c7ab316c69f22",
                "md5": "a98dee8cdca38fd23bd71e896fc93064",
                "sha256": "fbfe31ba239aca9ca927613da2b1f7ad3d2e06408ca0746c8c926c6e816cb34a"
            },
            "downloads": -1,
            "filename": "llama_index_tools_neo4j-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a98dee8cdca38fd23bd71e896fc93064",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 7289,
            "upload_time": "2025-07-31T02:54:15",
            "upload_time_iso_8601": "2025-07-31T02:54:15.611995Z",
            "url": "https://files.pythonhosted.org/packages/d4/96/8c7428225c16553b518297ea805ecaa40f3574c22df9e45c7ab316c69f22/llama_index_tools_neo4j-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-31 02:54:15",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-tools-neo4j"
}
        
Elapsed time: 3.14521s