{"id":6400,"library":"neo4j-graphrag","title":"Neo4j GraphRAG Python Client","description":"The neo4j-graphrag library provides Pythonic access and utilities for integrating with Neo4j's GraphRAG (Retrieval Augmented Generation) features. It simplifies building Knowledge Graphs from unstructured text, performing vector embeddings, and executing RAG queries against a Neo4j graph database. The current version is 1.14.1, with a release cadence that is quite active, often seeing minor releases monthly.","status":"active","version":"1.14.1","language":"en","source_language":"en","source_url":"https://github.com/neo4j/neo4j-graphrag-python","tags":["neo4j","graphrag","llm","rag","knowledge-graph","ai"],"install":[{"cmd":"pip install neo4j-graphrag","lang":"bash","label":"Base installation"},{"cmd":"pip install neo4j-graphrag[openai,vertexai,ollama]","lang":"bash","label":"Installation with common LLM integrations"}],"dependencies":[{"reason":"Core dependency for connecting to Neo4j database (requires >=5.19.0,<6.0.0)","package":"neo4j","optional":false},{"reason":"For using OpenAILLM","package":"openai","optional":true},{"reason":"For using VertexAILLM","package":"google-cloud-aiplatform","optional":true},{"reason":"For using MistralAILLM","package":"mistralai","optional":true},{"reason":"For using OllamaLLM","package":"ollama","optional":true},{"reason":"For PDF document loading (e.g., PdfLoader)","package":"pypdf","optional":true}],"imports":[{"symbol":"GraphRAGPipeline","correct":"from neo4j_graphrag.graph_rag_pipeline import GraphRAGPipeline"},{"symbol":"SimpleKGPipeline","correct":"from neo4j_graphrag.knowledge_graph_builder import SimpleKGPipeline"},{"note":"LLM classes are typically imported directly from `neo4j_graphrag.llm`","wrong":"from neo4j_graphrag.llm.openai import OpenAILLM","symbol":"OpenAILLM","correct":"from neo4j_graphrag.llm import OpenAILLM"},{"symbol":"VertexAILLM","correct":"from neo4j_graphrag.llm import VertexAILLM"},{"symbol":"Neo4jStore","correct":"from neo4j_graphrag.retrievers import Neo4jStore"}],"quickstart":{"code":"import os\nfrom neo4j import GraphDatabase\nfrom neo4j_graphrag.graph_rag_pipeline import GraphRAGPipeline\nfrom neo4j_graphrag.llm import OpenAILLM\n\n# --- Configuration (Set environment variables or replace placeholders) ---\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\")\nNEO4J_DATABASE = os.environ.get(\"NEO4J_DATABASE\", \"neo4j\")\nOPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\", \"\") # Required for OpenAILLM\n\nif not all([NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD, OPENAI_API_KEY]):\n    print(\"Warning: Please set NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD, and OPENAI_API_KEY environment variables for a runnable example.\")\n    print(\"Using default values for Neo4j, which may not connect without a running instance.\")\n    print(\"OpenAI API key is missing. The LLM initialization might fail or proceed without API calls.\")\n\ntry:\n    # 1. Initialize Neo4j Driver\n    driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USERNAME, NEO4J_PASSWORD))\n    # Verify connection to ensure Neo4j is reachable and credentials are correct\n    driver.verify_connectivity()\n    print(\"Neo4j connection verified successfully.\")\n\n    # 2. Initialize your chosen LLM (e.g., OpenAI)\n    llm = OpenAILLM(api_key=OPENAI_API_KEY)\n\n    # 3. Initialize the GraphRAG pipeline\n    # This pipeline is designed to work with a knowledge graph. For best results,\n    # ensure your Neo4j database has relevant data, possibly built using SimpleKGPipeline.\n    pipeline = GraphRAGPipeline(\n        llm=llm,\n        graph_driver=driver,\n        database=NEO4J_DATABASE\n    )\n\n    # 4. Ask a question to the pipeline\n    question = \"Who is the CEO of Neo4j?\"\n    print(f\"\\nQuestion: {question}\")\n    response = pipeline.query(question)\n\n    print(f\"Answer: {response.answer}\")\n\nexcept Exception as e:\n    print(f\"An error occurred during quickstart: {e}\")\nfinally:\n    if 'driver' in locals():\n        driver.close()\n        print(\"Neo4j driver closed.\")","lang":"python","description":"This quickstart demonstrates how to set up and use the `GraphRAGPipeline` with an OpenAI LLM to query a Neo4j knowledge graph. It requires Neo4j to be running and accessible, and an OpenAI API key. Ensure `NEO4J_URI`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`, and `OPENAI_API_KEY` environment variables are set."},"warnings":[{"fix":"Ensure your project uses Python versions between 3.10 and 3.14 (inclusive). Downgrade Python if necessary or wait for future `neo4j-graphrag` updates.","message":"Python 3.9 support was dropped in version 1.12.0. Additionally, Python 3.15 and newer are not yet supported (requires_python: <3.15,>=3.10.0).","severity":"breaking","affected_versions":">=1.12.0"},{"fix":"Avoid `__` (double underscore) at the beginning or end of entity labels when extracting schema or designing your graph data model.","message":"As of version 1.14.1, schema extraction for entity labels explicitly forbids the use of `__` (double underscore) prefixes or suffixes. This may affect existing knowledge graphs or data ingestion pipelines that use such naming conventions.","severity":"gotcha","affected_versions":">=1.14.1"},{"fix":"Review your LLM interaction patterns. If using direct LLM calls or specific output parsing, check the updated API for structured output methods and tool calling. Adapt your code to handle the new capabilities or maintain compatibility if relying on older patterns.","message":"Version 1.13.0 introduced significant changes for LLM integrations, including support for structured output in `LLMInterfaceV2`, `OpenAILLM`, `VertexAILLM`, and tool calling for `OllamaLLM`. If you were interacting with these LLMs directly or expecting specific unstructured text outputs, your code may need adjustment.","severity":"breaking","affected_versions":">=1.13.0"},{"fix":"Upgrade to `neo4j-graphrag` version 1.14.0 or newer to ensure compatibility with modern Neo4j versions and their APOC library.","message":"Version 1.14.0 fixed usage of deprecated APOC procedures. If you are using an older version of `neo4j-graphrag` with a newer Neo4j database version (e.g., Neo4j 5.x) that has removed or changed older APOC procedures, you might encounter errors.","severity":"gotcha","affected_versions":"<1.14.0"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}