LANGCHAIN · PYTHON

LangChain Integration

Drop-in LangChain components backed by Dakera — persistent agent memory and server-side RAG with no local embedding model.

Package: langchain-dakera  ·  GitHub →

Quick Start

1

Run Dakera

Dakera is a self-hosted memory server. Spin it up with Docker:

docker run -d \
  --name dakera \
  -p 3300:3300 \
  -e DAKERA_ROOT_API_KEY=dk-mykey \
  ghcr.io/dakera-ai/dakera:latest

# Verify it's running
curl http://localhost:3300/health

For production with persistent storage, use Docker Compose.

2

Install

pip install langchain-dakera

Requirements: Python ≥ 3.10, a running Dakera server.

3

Use it

from langchain_dakera import DakeraMemory, DakeraVectorStore

# Persistent conversation memory
memory = DakeraMemory(
    api_url="http://localhost:3300",
    api_key="dk-mykey",
    agent_id="my-agent",
)

# RAG vector store — server handles embedding
vectorstore = DakeraVectorStore(
    api_url="http://localhost:3300",
    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:3300",
    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

ParameterTypeDefaultDescription
api_urlstrDakera server URL
api_keystr""Dakera API key
agent_idstrAgent identifier for memory namespacing
recall_kint5Memories to surface per turn
min_importancefloat0.0Minimum importance threshold for recall
importancefloat0.7Importance assigned to stored memories
memory_keystr"history"Key injected into the prompt
input_keystrfirst keyInput 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:3300",
    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:3300",
    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

ParameterTypeDefaultDescription
api_urlstrDakera server URL
api_keystr""Dakera API key
namespacestrVector namespace to read/write
embedding_modelstrnamespace defaultServer-side embedding model override

Using environment variables

import os
from langchain_dakera import DakeraMemory

memory = DakeraMemory(
    api_url=os.environ["DAKERA_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:3300",
    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:3300",
    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:3300",
    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:3300",
    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:

ParameterTypeDefaultDescription
memory_typestr"episodic"Memory type: episodic, semantic, procedural, working
tagslist[]Tags applied to stored memories
session_idstrNoneLink memories to a session
ttl_secondsintNoneAuto-expire memories after N seconds
from langchain_dakera import DakeraMemory

memory = DakeraMemory(
    api_url="http://localhost:3300",
    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

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.