LangChain.js Integration
Persistent semantic memory and server-side vector search for LangChain.js. Full TypeScript types — no local embedding model required.
@dakera-ai/langchain · GitHub →| Class | Description |
|---|---|
DakeraMemory | Drop-in BaseMemory for LangChain.js conversation chains |
DakeraVectorStore | VectorStore backed by Dakera's server-side embedding engine |
Quick Start
Run Dakera
docker run -d \
--name dakera \
-p 3000:3000 \
-e DAKERA_ROOT_API_KEY=dk-mykey \
ghcr.io/dakera-ai/dakera:latest
curl http://localhost:3000/health # → {"status":"ok"}
Install
npm install @dakera-ai/langchain @dakera-ai/dakera @langchain/core
Requirements: Node.js ≥ 20, a running Dakera server.
Use it
import { DakeraMemory } from "@dakera-ai/langchain";
import { ConversationChain } from "langchain/chains";
import { ChatOpenAI } from "@langchain/openai";
const memory = new DakeraMemory({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
});
const chain = new ConversationChain({
llm: new ChatOpenAI({ model: "gpt-4o" }),
memory,
});
// Memory persists across sessions and restarts
const response = await chain.call({ input: "My project is called NeuralBridge." });
console.log(response.response);
DakeraMemory
Persistent conversation memory for LangChain.js chains. Stores and recalls conversation history using Dakera's hybrid search (BM25 + vector).
import { DakeraMemory } from "@dakera-ai/langchain";
import { ConversationChain } from "langchain/chains";
import { ChatOpenAI } from "@langchain/openai";
const memory = new DakeraMemory({
apiUrl: "http://localhost:3000",
apiKey: process.env.DAKERA_API_KEY!,
agentId: "my-agent",
recallK: 5, // how many past memories to surface per turn
importance: 0.7, // importance score for stored memories
});
const chain = new ConversationChain({
llm: new ChatOpenAI({ model: "gpt-4o" }),
memory,
});
// First session
await chain.call({ input: "My name is Alice and I'm building a chatbot." });
// Later session — memory persists across restarts
const { response } = await chain.call({ input: "What was I building?" });
console.log(response); // "You mentioned you were building a chatbot."
DakeraMemory options
| Option | Type | Default | Description |
|---|---|---|---|
apiUrl | string | — | Dakera server URL (e.g. http://localhost:3000) |
apiKey | string | "" | Dakera API key |
agentId | string | — | Agent identifier for memory namespacing |
recallK | number | 5 | How many past memories to surface per turn |
importance | number | 0.7 | Importance score for stored memories |
minImportance | number | 0.0 | Minimum importance threshold for recall |
DakeraVectorStore
Server-side embedded vector store for RAG. Compatible with VectorStore from @langchain/core. Dakera handles all embeddings — no OpenAI embeddings API needed.
import { DakeraVectorStore } from "@dakera-ai/langchain";
const vectorStore = new DakeraVectorStore({
apiUrl: "http://localhost:3000",
apiKey: process.env.DAKERA_API_KEY!,
namespace: "my-docs",
});
// Index documents (server handles embedding)
await vectorStore.addDocuments([
{ pageContent: "Dakera is a self-hosted memory server.", metadata: {} },
{ pageContent: "It scores 88.2% on the LoCoMo benchmark.", metadata: {} },
]);
// Similarity search
const results = await vectorStore.similaritySearch("benchmark score", 3);
console.log(results);
RAG chain with retrieval
import { DakeraVectorStore } from "@dakera-ai/langchain";
import { RetrievalQAChain } from "langchain/chains";
import { ChatOpenAI } from "@langchain/openai";
const vectorStore = new DakeraVectorStore({
apiUrl: "http://localhost:3000",
apiKey: process.env.DAKERA_API_KEY!,
namespace: "product-docs",
});
const chain = RetrievalQAChain.fromLLM(
new ChatOpenAI({ model: "gpt-4o" }),
vectorStore.asRetriever({ k: 4 }),
);
const { text } = await chain.call({ query: "How does memory decay work?" });
console.log(text);
DakeraVectorStore options
| Option | Type | Default | Description |
|---|---|---|---|
apiUrl | string | — | Dakera server URL |
apiKey | string | "" | Dakera API key |
namespace | string | — | Vector namespace to read/write |
embeddingModel | string | namespace default | Server-side embedding model override |
v0.2.0 — Sessions, Knowledge Graph, Entities & Namespaces
Version 0.2.0 adds four new classes for advanced memory management. All are importable from @dakera-ai/langchain.
Session management
Group related memories into sessions with automatic lifecycle tracking.
import { DakeraSessionManager } from "@dakera-ai/langchain";
const sessions = new DakeraSessionManager({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
});
// Start a session
const session = await sessions.start({ task: "research" });
console.log(session.id);
// End the session
await sessions.end("Research complete");
// List active sessions
const active = await sessions.list(true);
// Get memories from a session
const memories = await sessions.memories(session.id);
Knowledge graph
Build and query a knowledge graph from your agent's memories.
import { DakeraKnowledgeGraph } from "@dakera-ai/langchain";
const kg = new DakeraKnowledgeGraph({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
});
// Build the graph from stored memories
await kg.build();
// Query the knowledge graph
const results = await kg.query({ query: "What does Alice work on?" });
// Find paths between entities
const path = await kg.path("entity-1", "entity-2");
// Export the full graph
const graph = await kg.export("json");
Entity extraction
Extract named entities from text and link them to memories.
import { DakeraEntityExtractor } from "@dakera-ai/langchain";
const extractor = new DakeraEntityExtractor({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
});
// Extract entities from text
const found = await extractor.extract("Alice from Acme Corp discussed the Q4 roadmap.");
// Get entities linked to a memory
const linked = await extractor.memoryEntities("mem_abc123");
Namespace management
Create and manage vector namespaces for organizing document collections.
import { DakeraNamespaceManager } from "@dakera-ai/langchain";
const ns = new DakeraNamespaceManager({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
});
// Create a namespace
await ns.create("product-docs", { dimension: 1024 });
// List all namespaces
const allNs = await ns.list();
// Get namespace details
const info = await ns.get("product-docs");
// Delete a namespace
await ns.delete("old-docs");
Enhanced DakeraMemory (v0.2.0)
The existing DakeraMemory class gained new constructor options in v0.2.0:
| Option | Type | Default | Description |
|---|---|---|---|
memoryType | string | "episodic" | Memory type: episodic, semantic, procedural, working |
tags | string[] | [] | Tags applied to stored memories |
sessionId | string | undefined | Link memories to a session |
ttlSeconds | number | undefined | Auto-expire memories after N seconds |
import { DakeraMemory } from "@dakera-ai/langchain";
const memory = new DakeraMemory({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
memoryType: "semantic",
tags: ["research", "q4"],
sessionId: "sess_abc123",
ttlSeconds: 86400, // expire after 24 hours
});
Related integrations
Links
- GitHub — dakera-langchain-js
- Dakera deploy — Docker Compose setup
- Dakera full documentation
- All integrations
Frequently Asked Questions
How do I add persistent memory to LangChain.js?
Install @dakera-ai/langchain, create a new DakeraMemory instance with your Dakera server URL and API key, then pass it as the memory option to your LangChain.js chain. All embedding and retrieval is handled server-side.
Does Dakera work with LangChain.js?
Yes, via the official @dakera-ai/langchain npm package. It provides DakeraMemory (drop-in BaseMemory) and DakeraVectorStore (drop-in VectorStore) with full TypeScript types.
What does Dakera add to LangChain.js?
Dakera provides persistent cross-session memory, hybrid BM25 + vector semantic search over past interactions, server-side RAG with no local embedding model, knowledge graph construction, session management, and memory decay. Memories persist across process restarts and deployments.
Further reading: MCP Protocol Explained · Building Multi-Agent Memory Systems · Namespace Isolation pattern
Add persistent memory to your framework.
One Docker command starts the server. One pip or npm install gives your agents memory that survives the session.
Prefer managed hosting? Join the Dakera Cloud waitlist →