Skip to main content
FalkorDB is integrated with LangChain, bringing powerful graph database capabilities to AI-driven applications. This integration enables the creation of AI agents with memory, enhancing their ability to retain state and context across interactions. The FalkorDB LangChain integration is available for both Python and JavaScript/TypeScript environments, making it easy to build intelligent applications in your preferred language.

Resources


Python Integration

The Python integration is provided by the dedicated langchain-falkordb package. It provides:
  • FalkorDBGraph — a graph wrapper with schema introspection and GraphDocument ingestion, 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:
The examples below also use 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 uses RetrievalQA 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 use
  • url (string): Alternative connection URL format: falkor[s]://[[username][:password]@][host][:port][/db-number]
  • enhancedSchema (boolean): Enable enhanced schema details
Example with URL:

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)

For more examples and source code, see the @falkordb/langchain-ts repository.

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

  1. Schema Design: Design your graph schema with clear node labels and relationship types
  2. Cypher Optimization: Review generated Cypher queries and optimize for performance
  3. Error Handling: Implement fallbacks for cases where Cypher generation fails
  4. Context Management: Use graph memory to maintain conversation context efficiently
  5. Prompt Engineering: Customize prompts to improve Cypher query generation quality

Resources

Frequently Asked Questions

The FalkorDB LangChain integration supports both Python (via the langchain-falkordb PyPI package) and JavaScript/TypeScript (via the @falkordb/langchain-ts npm package).
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.
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.
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.
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.