Resources
- 📦 langchain-falkordb Package (Python)
- 💻 langchain-falkordb Repository
- 📦 @falkordb/langchain-ts Package (JavaScript/TypeScript)
- 💻 FalkorDB-Langchain-js Repository
- 📓 Blog: Build AI Agents with Memory – LangChain + FalkorDB
Python Integration
The Python integration is provided by the dedicatedlangchain-falkordb package. It provides:
FalkorDBGraph— a graph wrapper with schema introspection andGraphDocumentingestion, for building knowledge graphs.FalkorDBVector— a LangChain vector store backed by FalkorDB vector indexes, with support for metadata filtering, maximal marginal relevance (MMR) search, and hybrid (vector + full-text) search.FalkorDBQAChain— a natural-language-to-Cypher question-answering chain over a FalkorDB graph.FalkorDBSaver— a LangGraph checkpointer that persists agent state in FalkorDB.FalkorDBChatMessageHistory— a LangChain chat message history that persists conversations in FalkorDB.
Installation
Install the FalkorDB LangChain integration:langchain-openai:
Quick Start
1. Connect to FalkorDB
2. Create a QA Chain
Security note: the chain executes LLM-generated Cypher against your
database. Use narrowly-scoped credentials and set
allow_dangerous_requests=True only after understanding the risks.
3. Query the Graph
Advanced Usage
Building a Knowledge Graph
FalkorDBGraph ingests GraphDocument objects (e.g. produced by an LLM
graph transformer such as LLMGraphTransformer from langchain-experimental):
Persistent Chat Message History
FalkorDBChatMessageHistory persists conversations in FalkorDB. Each
session is stored in its own graph named after the session_id, so
histories are isolated per session and survive reconnects:
Custom Cypher Generation
Loading Data into a Vector Store
This example also uses LangChain document loading utilities (pip install langchain-community langchain-text-splitters):
FalkorDBVector also supports maximal marginal relevance (MMR) search via
max_marginal_relevance_search, hybrid (vector + full-text) search via
search_type=SearchType.HYBRID, and reusing existing indexes and graphs
via from_existing_index and from_existing_graph.
Graph RAG Pattern
This example usesRetrievalQA from the langchain package (pip install langchain):
JavaScript/TypeScript Integration
FalkorDB also provides a JavaScript/TypeScript integration for LangChain applications through the @falkordb/langchain-ts package.Installation
Quick Start (JS/TS)
Alternative Connection: You can also connect using a URL format:
Key Features (JS/TS)
- Natural Language Querying: Convert questions to Cypher queries automatically
- Schema Management: Automatic schema refresh and retrieval
- Type Safety: Full TypeScript support with type definitions
- Promise-based API: Modern async/await patterns
API Reference (JS/TS)
FalkorDBGraph.initialize(config)
Create and initialize a new FalkorDB connection.
Config Options:
host(string): Database host (default: “localhost”)port(number): Database port (default: 6379)graph(string): Graph name to useurl(string): Alternative connection URL format:falkor[s]://[[username][:password]@][host][:port][/db-number]enhancedSchema(boolean): Enable enhanced schema details
query(query: string)
Execute a Cypher query on the graph.
refreshSchema()
Update the graph schema information.
Advanced Usage (JS/TS)
Custom Cypher Queries
Working with Schema (JS/TS)
Use Cases
- Conversational AI with Memory: Build chatbots that remember user context across sessions
- Question Answering over Knowledge Graphs: Convert natural language to Cypher queries automatically
- Document Q&A with Graph Context: Combine vector search with graph relationships
- Multi-hop Reasoning: Leverage graph traversal for complex queries
- Entity Extraction and Linking: Build knowledge graphs from unstructured text
Best Practices
- Schema Design: Design your graph schema with clear node labels and relationship types
- Cypher Optimization: Review generated Cypher queries and optimize for performance
- Error Handling: Implement fallbacks for cases where Cypher generation fails
- Context Management: Use graph memory to maintain conversation context efficiently
- Prompt Engineering: Customize prompts to improve Cypher query generation quality
Resources
- LangChain Documentation
- langchain-falkordb on PyPI
- langchain-falkordb Repository
- Blog: Build AI Agents with Memory
Frequently Asked Questions
What languages does the FalkorDB LangChain integration support?
What languages does the FalkorDB LangChain integration support?
The FalkorDB LangChain integration supports both Python (via the
langchain-falkordb PyPI package) and JavaScript/TypeScript (via the @falkordb/langchain-ts npm package).How do I connect LangChain to FalkorDB?
How do I connect LangChain to FalkorDB?
In Python, use
FalkorDBGraph('my_graph', host='localhost', port=6379) from langchain_falkordb. In TypeScript, use FalkorDBGraph.initialize({ host: 'localhost', port: 6379, graph: 'my_graph' }) from @falkordb/langchain-ts.Can I use FalkorDB as a vector store with LangChain?
Can I use FalkorDB as a vector store with LangChain?
Yes. Use
FalkorDBVector from langchain_falkordb to store and retrieve document embeddings. It supports similarity search with metadata filtering, maximal marginal relevance (MMR) search, hybrid (vector + full-text) search, and can be used as a retriever in RAG chains.What is FalkorDBQAChain?
What is FalkorDBQAChain?
FalkorDBQAChain is a chain from the
langchain-falkordb package that converts natural language questions into Cypher queries, executes them against FalkorDB, and returns natural language answers. Because it executes LLM-generated Cypher, you must explicitly opt in with allow_dangerous_requests=True.Can I give agents persistent memory with FalkorDB?
Can I give agents persistent memory with FalkorDB?
Yes. Use
FalkorDBChatMessageHistory to persist conversations per session, or FalkorDBSaver (a LangGraph checkpointer, installed with pip install langchain-falkordb[langgraph]) to persist agent state across restarts.