Registry / llm-agents / langchain-neo4j

langchain-neo4j

JSON →
library0.10.0pypypiunverified

LangChain Neo4j is an integration package connecting the LangChain framework with the Neo4j graph database. It provides functionalities for building LLM applications, including graph data interaction via `Neo4jGraph`, semantic search with `Neo4jVector`, conversational memory using `Neo4jChatMessageHistory`, and LangGraph checkpoint savers for state persistence. The current version is 0.9.0, with regular updates providing new features and compatibility improvements.

pip install -U langchain-neo4j
INSTALL
IMPORT
SIG · LANGCHAIN-NEO4J
L
langchain-neo4j
llm-agentspythonv0.10.0
Install
17.5s avg
Import
3463ms
Disk
341MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 3.536s · 339.1MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 17.5s · import 3.390s · 335MB
341MB installed
● package 341MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Neo4jGraph
from langchain_neo4j import Neo4jGraph
Neo4jVector
from langchain_neo4j import Neo4jVector
Neo4jChatMessageHistory
from langchain_neo4j import Neo4jChatMessageHistory
GraphCypherQAChain
from langchain_neo4j import GraphCypherQAChain
from langchain.chains import GraphCypherQAChain
While `GraphCypherQAChain` might have existed directly in `langchain.chains` in older LangChain versions, for `langchain-neo4j` it's correctly imported from `langchain_neo4j`.
Neo4jSaver
from langchain_neo4j import Neo4jSaver
AsyncNeo4jSaver
from langchain_neo4j import AsyncNeo4jSaver

This quickstart demonstrates how to connect to a Neo4j database using `Neo4jGraph`, optionally load sample data, and then use `GraphCypherQAChain` with an OpenAI LLM to answer natural language questions by generating and executing Cypher queries against the graph. Ensure `NEO4J_URI`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`, and `OPENAI_API_KEY` environment variables are set.

import os from langchain_neo4j import Neo4jGraph, GraphCypherQAChain from langchain_openai import ChatOpenAI # Set environment variables for Neo4j connection NEO4J_URI = os.environ.get('NEO4J_URI', 'bolt://localhost:7687') NEO4J_USERNAME = os.environ.get('NEO4J_USERNAME', 'neo4j') NEO4J_PASSWORD = os.environ.get('NEO4J_PASSWORD', 'password') OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY', '') if not OPENAI_API_KEY: raise ValueError("OPENAI_API_KEY environment variable not set.") # Initialize Neo4jGraph connection graph = Neo4jGraph(url=NEO4J_URI, username=NEO4J_USERNAME, password=NEO4J_PASSWORD) # Optional: Insert some sample movie data if the database is empty graph.query( """ MERGE (m:Movie {title:'The Matrix'}) WITH m UNWIND ['Keanu Reeves', 'Laurence Fishburne', 'Carrie-Anne Moss'] AS actor MERGE (a:Actor {name:actor}) MERGE (a)-[:ACTED_IN]->(m) """ ) # Initialize LLM llm = ChatOpenAI(temperature=0, api_key=OPENAI_API_KEY) # Create GraphCypherQAChain # IMPORTANT: allow_dangerous_requests=True is used for demonstration. # In production, ensure narrowly-scoped credentials and careful prompt engineering. chain = GraphCypherQAChain.from_llm( llm=llm, graph=graph, verbose=True, allow_dangerous_requests=True ) # Invoke the chain with a natural language query result = chain.invoke({"query": "Who acted in The Matrix?"}) print(result['result'])
Debug
Known issues
breakingLangChain v1.0.0+ requires `langchain-classic` and drops Python 3.9 support. `langchain-neo4j` v0.6.0+ is updated to reflect this change, replacing `langchain` with `langchain-classic` as a dependency and removing Python 3.9 support.
fix
Ensure your environment uses Python >=3.10 and `pip install -U langchain-classic` alongside `langchain-neo4j` if you're migrating from older LangChain versions.
affects: >=0.6.0
breakingThe `GraphCypherQAChain` was fixed in v0.9.0 to improve compatibility with non-Neo4j `GraphStore` implementations by no longer requiring the private `_enhanced_schema` attribute.
fix
Upgrade to `langchain-neo4j` v0.9.0 or later to ensure broader compatibility, especially if using custom `GraphStore` implementations.
affects: ==0.9.0
gotchaThe `GraphCypherQAChain` constructor includes an `allow_dangerous_requests` parameter. Setting this to `True` can expose your database to potential data corruption or loss if the LLM generates malicious queries.
fix
Always use narrowly-scoped database credentials with minimal permissions. Carefully evaluate the necessity of `allow_dangerous_requests=True` in production and prefer `False` where possible, or implement strong prompt engineering and input sanitization.
affects: All versions
deprecatedWhen migrating to LangChain v0.1.0 and beyond, many core LangChain classes (e.g., `ChatOpenAI`, `OpenAIEmbeddings`, `initialize_agent`) moved to `langchain-community` or `langchain-openai` packages. Older `langchain.*` imports will trigger deprecation warnings.
fix
Update your LangChain core dependencies (`pip install -U langchain-community langchain-openai`) and adjust imports to their new homes (e.g., `from langchain_openai import ChatOpenAI`).
affects: All versions when used with older LangChain core
gotchaThe `Neo4jGraph` class in older versions (prior to fix) might default to the 'neo4j' database even when a different database name is specified, leading to connection or data access issues.
fix
Ensure you are using `langchain-neo4j` v0.5.0 or newer. Verify connectivity to the correct database using standard Neo4j Python driver methods if issues persist.
affects: <0.5.0
Upgrade
Version history
0.10.0latest on PyPI · released Jun 10, 2026
Audit
Dependencies
langchain-classicrequiredRequired for compatibility with LangChain 1.0.0+ as legacy functionality moved from `langchain` to `langchain-classic`.
neo4j-graphragoptionalAdded as a dependency in v0.4.0 for enhanced RAG capabilities.
openaioptionalCommonly used with `Neo4jVector` and `GraphCypherQAChain` for embeddings and LLM functionality.
neo4jrequiredThe underlying Python driver for Neo4j database interaction.
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources