{"id":7374,"library":"llama-index-graph-stores-neo4j","title":"LlamaIndex Neo4j Graph Stores Integration","description":"The `llama-index-graph-stores-neo4j` library provides an integration for LlamaIndex to use Neo4j as a backend for graph stores. It enables persisting, visualizing, and querying knowledge graphs directly within a Neo4j database, supporting both triplet-based and property graph models. The library is actively maintained as part of the broader LlamaIndex ecosystem, with frequent updates to ensure compatibility and introduce new features.","status":"active","version":"0.7.0","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j","tags":["LlamaIndex","Neo4j","Graph Database","LLM","RAG","Knowledge Graph"],"install":[{"cmd":"pip install llama-index-graph-stores-neo4j","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Core LlamaIndex functionalities are required.","package":"llama-index-core","optional":false},{"reason":"Python driver for connecting to Neo4j database.","package":"neo4j","optional":false}],"imports":[{"symbol":"Neo4jGraphStore","correct":"from llama_index.graph_stores.neo4j import Neo4jGraphStore"},{"symbol":"Neo4jPropertyGraphStore","correct":"from llama_index.graph_stores.neo4j import Neo4jPropertyGraphStore"}],"quickstart":{"code":"import os\nfrom llama_index.graph_stores.neo4j import Neo4jPropertyGraphStore\nfrom llama_index.core import StorageContext, KnowledgeGraphIndex, SimpleDirectoryReader\nfrom llama_index.core.schema import Document\n\n# Ensure Neo4j is running (e.g., via Docker) and credentials are set\n# For local Docker setup: docker run -p 7474:7474 -p 7687:7687 -e NEO4J_AUTH=neo4j/password --name neo4j-apoc neo4j:latest\n\nNEO4J_URI = os.environ.get(\"NEO4J_URI\", \"bolt://localhost:7687\")\nNEO4J_USERNAME = os.environ.get(\"NEO4J_USERNAME\", \"neo4j\")\nNEO4J_PASSWORD = os.environ.get(\"NEO4J_PASSWORD\", \"password\") # Default password for fresh install\nNEO4J_DATABASE = os.environ.get(\"NEO4J_DATABASE\", \"neo4j\")\nOPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\", \"\") # Required for LlamaIndex processing\n\nif not OPENAI_API_KEY:\n    raise ValueError(\"OPENAI_API_KEY environment variable not set.\")\n\n# Initialize Neo4j Property Graph Store\ngraph_store = Neo4jPropertyGraphStore(\n    username=NEO4J_USERNAME,\n    password=NEO4J_PASSWORD,\n    url=NEO4J_URI,\n    database=NEO4J_DATABASE,\n)\n\n# Create storage context\nstorage_context = StorageContext.from_defaults(graph_store=graph_store)\n\n# Example document (in a real scenario, use SimpleDirectoryReader or other loaders)\ndocuments = [\n    Document(text=\"LlamaIndex is a data framework for LLM applications. It helps connect custom data sources to LLMs.\")\n]\n\n# Create a Knowledge Graph Index\n# Note: This will extract entities and relationships and store them in Neo4j.\nindex = KnowledgeGraphIndex.from_documents(\n    documents,\n    storage_context=storage_context,\n    # Other parameters like `llm`, `kg_extractors` can be configured\n    # For this quickstart, default LLM settings will use OpenAI, hence API key is needed.\n    max_triplets_per_chunk=2, # For simpler quickstart\n)\n\nprint(\"Knowledge Graph Index created and stored in Neo4j.\")\n\n# Example query (requires an LLM configured in LlamaIndex Settings or passed to the query engine)\n# query_engine = index.as_query_engine()\n# response = query_engine.query(\"What is LlamaIndex?\")\n# print(response)\n","lang":"python","description":"This quickstart demonstrates how to initialize the `Neo4jPropertyGraphStore` and integrate it with LlamaIndex to create a knowledge graph. It assumes a running Neo4j instance and requires an OpenAI API key for LlamaIndex's internal LLM processing during graph extraction. It uses environment variables for Neo4j credentials and the OpenAI API key for secure configuration."},"warnings":[{"fix":"Migrate to `Neo4jPropertyGraphStore` for richer graph representation with nodes and properties. Review LlamaIndex documentation for property graph index construction.","message":"The LlamaIndex Neo4j integration evolved from triplet-based (`Neo4jGraphStore`) to a property graph model (`Neo4jPropertyGraphStore`). Existing codebases using the older triplet model for graph creation or specific data representation might need significant refactoring.","severity":"breaking","affected_versions":"<0.7.0 (LlamaIndex v0.10.x and earlier often used simpler triplet graphs)"},{"fix":"Set `refresh_schema_on_startup=False` during initialization if the schema is stable or refresh manually. Example: `Neo4jPropertyGraphStore(..., refresh_schema_on_startup=False)`.","message":"Initializing `Neo4jPropertyGraphStore` with large existing graphs can be very slow due to the `refresh_schema()` operation, which fetches the entire schema from Neo4j.","severity":"gotcha","affected_versions":"All versions where large graphs are used"},{"fix":"Ensure your Neo4j database is running version 5.11.0 or greater, as certain Cypher features and vector indexing require it. Verify that APOC procedures are correctly installed and enabled in your Neo4j configuration. Double-check Neo4j URI, username, and password.","message":"`CypherSyntaxError` or connection issues when interacting with Neo4j, especially for advanced queries or specific APOC procedures.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install llama-index-graph-stores-neo4j`. Verify the exact import path, which is `from llama_index.graph_stores.neo4j import ...`.","cause":"The `llama-index-graph-stores-neo4j` package is not installed or there's a typo in the import statement.","error":"ModuleNotFoundError: No module named 'llama_index.graph_stores.neo4j'"},{"fix":"Ensure the Neo4j database is started and reachable (e.g., check Docker container status, network connectivity). Verify `NEO4J_URI`, `NEO4J_USERNAME`, and `NEO4J_PASSWORD` environment variables or constructor arguments are correct.","cause":"The Neo4j database is not running, is inaccessible from the client, or the connection URI/credentials are incorrect.","error":"neo4j.exceptions.ServiceUnavailable: Could not perform discovery. No routing servers available."},{"fix":"Set the `OPENAI_API_KEY` environment variable. For example: `export OPENAI_API_KEY='sk-...'`. Alternatively, configure LlamaIndex `Settings` to use a different LLM.","cause":"LlamaIndex components (like graph extractors) often default to using OpenAI models, which require an API key, even if you're only interacting with the graph store.","error":"ValueError: OPENAI_API_KEY environment variable not set."}]}