Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion genai-tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FalkorDB provides powerful tools and integrations for building intelligent GenAI

- [GraphRAG-SDK](./graphrag-sdk.md): Build intelligent GraphRAG applications with FalkorDB and LLMs.
- [AG2](./ag2.md): Build multi-agent AI systems with AG2 (formerly AutoGen) and FalkorDB GraphRAG.
- [LangChain](./langchain.md): Integration with LangChain for AI agents with memory.
- [LangChain](./langchain.md): Integration with LangChain for AI agents with memory (Python and JavaScript/TypeScript).
- [LangGraph](./langgraph.md): Build stateful, multi-actor agentic applications with LangGraph.
- [LlamaIndex](./llamaindex.md): Simplify development of LLM-powered applications with LlamaIndex.
- [GraphRAG Toolkit](./graphrag-toolkit.md): AWS GraphRAG Toolkit integration for building knowledge graph applications.
125 changes: 114 additions & 11 deletions genai-tools/langchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@ parent: "GenAI Tools"

FalkorDB is integrated with [LangChain](https://www.langchain.com/), 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

- 🔗 [FalkorDBQAChain Documentation](https://python.langchain.com/docs/use_cases/more/graph/graph_falkordb_qa)
- 🔗 [FalkorDBQAChain Documentation (Python)](https://python.langchain.com/docs/use_cases/more/graph/graph_falkordb_qa)
- 📦 [@falkordb/langchain-ts Package (JavaScript/TypeScript)](https://www.npmjs.com/package/@falkordb/langchain-ts)
- 💻 [FalkorDB-Langchain-js Repository](https://github.com/FalkorDB/FalkorDB-Langchain-js)
- 📓 [Blog: Build AI Agents with Memory – LangChain + FalkorDB](https://www.falkordb.com/blog/building-ai-agents-with-memory-langchain/)

## Installation
---

## Python Integration

### Installation

Install LangChain with FalkorDB support:

```bash
pip install langchain langchain-community falkordb
```

## Quick Start
### Quick Start

### 1. Connect to FalkorDB
#### 1. Connect to FalkorDB

```python
from langchain_community.graphs import FalkorDBGraph
Expand All @@ -39,7 +47,7 @@ graph = FalkorDBGraph(
)
```

### 2. Create a Knowledge Graph from Text
#### 2. Create a Knowledge Graph from Text

```python
from langchain.chains import GraphCypherQAChain
Expand All @@ -56,7 +64,7 @@ chain = GraphCypherQAChain.from_llm(
)
```

### 3. Query the Graph
#### 3. Query the Graph

```python
# Ask natural language questions
Expand All @@ -68,9 +76,9 @@ response = chain.run("What other movies did they act in?")
print(response)
```

## Advanced Usage
### Advanced Usage

### Using Graph Memory for Conversational AI
#### Using Graph Memory for Conversational AI

```python
from langchain.memory import ConversationGraphMemory
Expand All @@ -96,7 +104,7 @@ conversation.predict(input="I work as a software engineer")
conversation.predict(input="What do you know about me?")
```

### Custom Cypher Generation
#### Custom Cypher Generation

```python
from langchain.chains.graph_qa.cypher import GraphCypherQAChain
Expand Down Expand Up @@ -131,7 +139,7 @@ chain = GraphCypherQAChain.from_llm(
response = chain.run("Find all products in the electronics category")
```

### Loading Data into the Graph
#### Loading Data into the Graph

```python
from langchain_community.document_loaders import TextLoader
Expand All @@ -156,7 +164,7 @@ vector_store = FalkorDBVector.from_documents(
)
```

### Graph RAG Pattern
#### Graph RAG Pattern

```python
from langchain.chains import RetrievalQA
Expand All @@ -183,6 +191,101 @@ response = qa_chain.run("What are the key features of our product?")
print(response)
```

---

## JavaScript/TypeScript Integration

FalkorDB also provides a JavaScript/TypeScript integration for LangChain applications through the [@falkordb/langchain-ts](https://www.npmjs.com/package/@falkordb/langchain-ts) package.

### Installation

```bash
npm install @falkordb/langchain-ts falkordb langchain @langchain/openai
```

### Quick Start (JS/TS)

```typescript
import { FalkorDBGraph } from "@falkordb/langchain-ts";
import { ChatOpenAI } from "@langchain/openai";
import { GraphCypherQAChain } from "@langchain/community/chains/graph_qa/cypher";

// Initialize FalkorDB connection
const graph = await FalkorDBGraph.initialize({
host: "localhost",
port: 6379,
graph: "movies"
});
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code example uses 'graph' as the parameter name, but according to the API Reference section below (line 263), this parameter should be documented consistently. Consider clarifying whether the parameter is 'graph' or 'graphName' to avoid confusion.

Suggested change
});
graphName: "movies"

Copilot uses AI. Check for mistakes.

// Set up the language model
const model = new ChatOpenAI({ temperature: 0 });

// Create and populate the graph
await graph.query(
"CREATE (a:Actor {name:'Bruce Willis'})" +
"-[:ACTED_IN]->(:Movie {title: 'Pulp Fiction'})"
);

// Refresh the graph schema
await graph.refreshSchema();

// Create a graph QA chain
const chain = GraphCypherQAChain.fromLLM({
llm: model,
graph: graph as any,
});
Comment on lines +234 to +236
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'as any' bypasses TypeScript's type checking. Consider documenting why this type assertion is necessary or provide proper typing to avoid encouraging unsafe type practices in example code.

Suggested change
llm: model,
graph: graph as any,
});
// If needed, define a minimal type for the graph to avoid 'as any'.
// For example, if GraphCypherQAChain expects a BaseGraph type:
// import type { BaseGraph } from "@langchain/community/graphs/base";
// (Uncomment the import above and use the correct type if available)
const chain = GraphCypherQAChain.fromLLM({
llm: model,
graph: graph, // graph should already be of the correct type

Copilot uses AI. Check for mistakes.

// Ask questions about your graph
const response = await chain.run("Who played in Pulp Fiction?");
console.log(response);
// Output: Bruce Willis played in Pulp Fiction.

await graph.close();
```

### 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
- `enhancedSchema` (boolean): Enable enhanced schema details

#### `query(query: string)`

Execute a Cypher query on the graph.

```typescript
const result = await graph.query(
"MATCH (n:Person) RETURN n.name LIMIT 10"
);
```

#### `refreshSchema()`

Update the graph schema information.

```typescript
await graph.refreshSchema();
console.log(graph.getSchema());
```

For more detailed JavaScript/TypeScript examples and documentation, see the [LangChain JS/TS Integration Guide](/integration/langchain-js.html) and the [@falkordb/langchain-ts repository](https://github.com/FalkorDB/FalkorDB-Langchain-js).

---

## Use Cases

- **Conversational AI with Memory**: Build chatbots that remember user context across sessions
Expand Down
1 change: 1 addition & 0 deletions integration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Learn how to leverage FalkorDB's flexible APIs and SDKs to build high-performanc
## Topics in This Section

- [REST API](./rest.md): Learn how to interact with FalkorDB using its REST API for seamless integration with your applications.
- [LangChain JS/TS](./langchain-js.md): Integrate FalkorDB with LangChain JavaScript/TypeScript applications for AI-powered graph querying.
- [Kafka Connect](./kafka-connect.md): Learn how to interact with FalkorDB using Kafka Connect sink to replicate data from third-party applications.
- [Apache Jena](./jena.md): Learn how to use FalkorDB with Apache Jena via the jena-falkordb-adapter.
- [BOLT protocol support](./bolt-support.md): Learn how to connect to FalkorDB using the BOLT protocol.
Expand Down
2 changes: 2 additions & 0 deletions integration/langchain-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ parent: "Integration"

The [@falkordb/langchain-ts](https://www.npmjs.com/package/@falkordb/langchain-ts) package enables developers to integrate FalkorDB with LangChain applications. The integration allows applications to accept natural language questions, generate Cypher queries automatically, retrieve relevant context from the graph database, and return responses in natural language.

> **Note:** FalkorDB also provides a Python integration for LangChain. See the [LangChain Python Integration](/genai-tools/langchain.html) for Python-specific documentation.

## Installation

### Step 1
Expand Down