LangChain Integration
Drop-in LangChain components backed by Dakera — persistent agent memory and server-side RAG with no local embedding model.
langchain-dakera · GitHub →Quick Start
Run Dakera
Dakera is a self-hosted memory server. Spin it up with Docker:
docker run -d \
--name dakera \
-p 3000:3000 \
-e DAKERA_ROOT_API_KEY=dk-mykey \
ghcr.io/dakera-ai/dakera:latest
# Verify it's running
curl http://localhost:3000/health
For production with persistent storage, use Docker Compose.
Install
pip install langchain-dakera
Requirements: Python ≥ 3.10, a running Dakera server.
Use it
from langchain_dakera import DakeraMemory, DakeraVectorStore
# Persistent conversation memory
memory = DakeraMemory(
api_url="http://localhost:3000",
api_key="dk-mykey",
agent_id="my-agent",
)
# RAG vector store — server handles embedding
vectorstore = DakeraVectorStore(
api_url="http://localhost:3000",
api_key="dk-mykey",
namespace="my-docs",
)
DakeraMemory
Persistent semantic memory for LangChain conversation chains. Stores and recalls conversation history using Dakera's hybrid search (BM25 + vector).
Conversation chain
from langchain.chains import ConversationChain
from langchain_openai import ChatOpenAI
from langchain_dakera import DakeraMemory
memory = DakeraMemory(
api_url="http://localhost:3000",
api_key="dk-mykey",
agent_id="chat-agent",
top_k=5, # memories to recall per turn
importance=0.7, # importance score for stored memories
)
chain = ConversationChain(
llm=ChatOpenAI(model="gpt-4o"),
memory=memory,
)
# First session
response = chain.predict(input="My name is Alice and I'm building a chatbot.")
# Later session — memory persists across restarts
response = chain.predict(input="What was I building?")
print(response) # "You mentioned you were building a chatbot."
DakeraMemory options
| Parameter | Type | Default | Description |
|---|---|---|---|
api_url | str | — | Dakera server URL |
api_key | str | "" | Dakera API key |
agent_id | str | — | Agent identifier for memory namespacing |
recall_k | int | 5 | Memories to surface per turn |
min_importance | float | 0.0 | Minimum importance threshold for recall |
importance | float | 0.7 | Importance assigned to stored memories |
memory_key | str | "history" | Key injected into the prompt |
input_key | str | first key | Input key used as recall query |
DakeraVectorStore
Server-side embedded vector store for RAG. Dakera handles embeddings on the server — no OpenAI or Hugging Face API calls needed for indexing or retrieval.
Indexing documents
from langchain_community.document_loaders import DirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_dakera import DakeraVectorStore
loader = DirectoryLoader("./docs", glob="**/*.md")
docs = loader.load()
splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
chunks = splitter.split_documents(docs)
# Index into Dakera — server handles embedding
vectorstore = DakeraVectorStore(
api_url="http://localhost:3000",
api_key="dk-mykey",
namespace="my-docs",
)
vectorstore.add_documents(chunks)
RAG chain
from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI
from langchain_dakera import DakeraVectorStore
vectorstore = DakeraVectorStore(
api_url="http://localhost:3000",
api_key="dk-mykey",
namespace="my-docs",
)
qa_chain = RetrievalQA.from_chain_type(
llm=ChatOpenAI(model="gpt-4o"),
retriever=vectorstore.as_retriever(search_kwargs={"k": 4}),
)
answer = qa_chain.run("How does Dakera handle memory decay?")
print(answer)
DakeraVectorStore options
| Parameter | Type | Default | Description |
|---|---|---|---|
api_url | str | — | Dakera server URL |
api_key | str | "" | Dakera API key |
namespace | str | — | Vector namespace to read/write |
embedding_model | str | namespace default | Server-side embedding model override |
Using environment variables
import os
from langchain_dakera import DakeraMemory
memory = DakeraMemory(
api_url=os.environ["DAKERA_API_URL"],
api_key=os.environ["DAKERA_API_KEY"],
agent_id="my-agent",
)
v0.2.0 — Sessions, Knowledge Graph, Entities & Namespaces
Version 0.2.0 adds four new classes for advanced memory management. All are importable from langchain_dakera.
Session management
Group related memories into sessions. Use as a context manager for automatic start/end.
from langchain_dakera import DakeraSessionManager
sessions = DakeraSessionManager(
api_url="http://localhost:3000",
api_key="dk-mykey",
agent_id="my-agent",
)
# Use as a context manager
with sessions.start(metadata={"task": "research"}) as session:
print(session.id)
# All memories stored here are grouped under this session
# List active sessions
active = sessions.list_sessions(active_only=True)
# Get memories from a specific session
memories = sessions.memories(session_id=session.id)
Knowledge graph
Build and query a knowledge graph from your agent's memories.
from langchain_dakera import DakeraKnowledgeGraph
kg = DakeraKnowledgeGraph(
api_url="http://localhost:3000",
api_key="dk-mykey",
agent_id="my-agent",
)
# Build the graph from stored memories
kg.build()
# Query the knowledge graph
results = kg.query(query="What does Alice work on?")
# Find paths between entities
path = kg.find_path(from_id="entity-1", to_id="entity-2")
# Export the full graph
graph = kg.export(format="json")
Entity extraction
Extract named entities from text and link them to memories.
from langchain_dakera import DakeraEntityExtractor
entities = DakeraEntityExtractor(
api_url="http://localhost:3000",
api_key="dk-mykey",
)
# Extract entities from text
found = entities.extract(
text="Alice from Acme Corp discussed the Q4 roadmap.",
entity_types=["person", "organization"],
)
# Get entities linked to a specific memory
linked = entities.memory_entities(memory_id="mem_abc123")
Namespace management
Create and manage vector namespaces for organizing document collections.
from langchain_dakera import DakeraNamespaceManager
ns = DakeraNamespaceManager(
api_url="http://localhost:3000",
api_key="dk-mykey",
)
# Create a namespace
ns.create(name="product-docs", dimension=1024)
# List all namespaces
all_ns = ns.list_namespaces()
# Get namespace details
info = ns.get(name="product-docs")
# Delete a namespace
ns.delete(name="old-docs")
Enhanced DakeraMemory (v0.2.0)
The existing DakeraMemory class gained new parameters in v0.2.0:
| Parameter | Type | Default | Description |
|---|---|---|---|
memory_type | str | "episodic" | Memory type: episodic, semantic, procedural, working |
tags | list | [] | Tags applied to stored memories |
session_id | str | None | Link memories to a session |
ttl_seconds | int | None | Auto-expire memories after N seconds |
from langchain_dakera import DakeraMemory
memory = DakeraMemory(
api_url="http://localhost:3000",
api_key="dk-mykey",
agent_id="my-agent",
memory_type="semantic",
tags=["research", "q4"],
session_id="sess_abc123",
ttl_seconds=86400, # expire after 24 hours
)
Related integrations
Links
- GitHub — dakera-langchain
- Dakera deploy — Docker Compose setup
- Dakera full documentation
- All integrations
Frequently Asked Questions
How do I add persistent memory to LangChain?
Install the langchain-dakera package, initialize DakeraMemory with your Dakera server URL and API key, then pass it as the memory parameter to your LangChain chain. Dakera handles embedding and retrieval server-side.
Does Dakera work with LangChain?
Yes, via the official langchain-dakera integration package. It provides DakeraMemory (drop-in BaseMemory) and DakeraVectorStore (drop-in VectorStore) for chains and RAG pipelines.
What does Dakera add to LangChain?
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 survive restarts and are shared across agents.
Further reading: Knowledge Graphs for AI Agents · Building Multi-Agent Memory Systems · RAG-Augmented Memory 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 →