LangChain.js Integration
This page covers @dakera-ai/langchain, the LangChain.js package for Dakera. It is for TypeScript and Node.js developers who want LangChain chains and retrievers backed by Dakera's persistent agent memory and server-side embeddings.
The current release is @dakera-ai/langchain 0.3.0. It builds on the TypeScript SDK (@dakera-ai/dakera 0.12.1 or later, peer dependency ^0.12.1) and @langchain/core 1.1 or later.
Quick start
npm install @dakera-ai/langchain @dakera-ai/dakera @langchain/core
Requires Node.js 20 or later and a running Dakera server (v0.12.0 or v0.11.108) (see the Quickstart).
import { DakeraMemory, DakeraVectorStore } from "@dakera-ai/langchain";
const memory = new DakeraMemory({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
});
const vectorstore = new DakeraVectorStore({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
namespace: "my-docs",
});
Exports
- DakeraMemory: extends LangChain's
BaseMemory; recalls relevant memories for each turn and stores the exchange - DakeraVectorStore: extends
VectorStorefor RAG, with embeddings computed by the Dakera server; also offershybridSearchandfulltextSearch - DakeraSessionManager: starts and ends sessions for one agent
- DakeraKnowledgeGraph: knowledge graph operations
- DakeraEntityExtractor: entity extraction from text
- DakeraNamespaceManager: namespace management
- DakeraAgentTools: agent statistics and memory listing
Examples
Conversation chain with persistent memory
With LangChain.js v1, the legacy ConversationChain lives in @langchain/classic: npm install @langchain/classic @langchain/openai.
import { ChatOpenAI } from "@langchain/openai";
import { ConversationChain } from "@langchain/classic/chains";
import { DakeraMemory } from "@dakera-ai/langchain";
const memory = new DakeraMemory({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "chat-agent",
recallK: 5,
importance: 0.7,
});
const chain = new ConversationChain({
llm: new ChatOpenAI({ model: "gpt-4o" }),
memory,
});
await chain.invoke({ input: "My name is Alice." });
// Later, in another process: the memory is still on the Dakera server
const res = await chain.invoke({ input: "What's my name?" });
RAG retriever
import { DakeraVectorStore } from "@dakera-ai/langchain";
const vectorstore = new DakeraVectorStore({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
namespace: "my-docs",
});
// Add documents (IDs are generated when you do not pass { ids })
await vectorstore.addDocuments([
{ pageContent: "Dakera computes embeddings on the server.", metadata: {} },
{ pageContent: "Memory decay lowers the importance of stale memories.", metadata: {} },
]);
// Retrieve
const retriever = vectorstore.asRetriever({ k: 4 });
const docs = await retriever.invoke("How does Dakera embed text?");
Session management
import { DakeraSessionManager } from "@dakera-ai/langchain";
const sessions = new DakeraSessionManager({
apiUrl: "http://localhost:3000",
apiKey: "dk-mykey",
agentId: "my-agent",
});
const sessionId = await sessions.start({ user: "alice" }); // metadata; returns the session ID
// ... pass sessionId to memory operations ...
await sessions.end(); // ends the active session
end() accepts a summary argument but 0.3.0 does not send it to the server.
API reference
DakeraMemory options
| Parameter | Type | Default | Description |
|---|---|---|---|
apiUrl | string | — | Dakera server URL (required) |
apiKey | string | — | API key |
agentId | string | — | Agent whose memories are read and written (required) |
recallK | number | 5 | Memories to surface per turn |
minImportance | number | 0 | Minimum importance of recalled memories |
importance | number | 0.7 | Importance assigned to stored memories |
memoryKey | string | "history" | Key injected into the prompt |
inputKey | string | — | Input key to read the user message from |
DakeraVectorStore options
| Parameter | Type | Default | Description |
|---|---|---|---|
apiUrl | string | — | Dakera server URL (required) |
apiKey | string | — | API key |
namespace | string | — | Vector namespace to read and write (required) |
Configuration
The package does not read environment variables; pass apiUrl and apiKey to each constructor. To keep them out of source code, read them yourself:
const memory = new DakeraMemory({
apiUrl: process.env.DAKERA_API_URL ?? "http://localhost:3000",
apiKey: process.env.DAKERA_API_KEY,
agentId: "my-agent",
});
Links
LangChain.js + Dakera in production
npm install @dakera-ai/langchain: persistent memory for TypeScript LangChain agents, with embeddings computed on your Dakera server and no external embedding API.
TypeScript SDK: TypeScript SDK reference · Cursor (MCP) · Claude Desktop (MCP) · Python: LangChain