LangChain Integration

The langchain-dakera package provides drop-in LangChain components backed by Dakera — persistent agent memory and server-side RAG with no local embedding model.

Quick Start

pip install langchain-dakera

Requires Python ≥ 3.10 and a running Dakera server.

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",
)

Features

Examples

Conversation chain with persistent memory

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",
    recall_k=5,
    importance=0.7,
)

chain = ConversationChain(
    llm=ChatOpenAI(model="gpt-4o"),
    memory=memory,
)

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?")
# "You mentioned you were building a chatbot."

RAG with server-side embeddings

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?")

Document indexing

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)

vectorstore = DakeraVectorStore(
    api_url="http://localhost:3300",
    api_key="dk-mykey",
    namespace="my-docs",
)
vectorstore.add_documents(chunks)

API Reference

DakeraMemory options

ParameterTypeDefaultDescription
api_urlstrDakera server URL
api_keystr""API key
agent_idstrAgent identifier for memory namespacing
recall_kint5Memories to surface per turn
min_importancefloat0.0Minimum importance threshold
importancefloat0.7Importance assigned to stored memories
memory_keystr"history"Key injected into the prompt
input_keystrfirst keyInput key used as recall query

DakeraVectorStore options

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

Configuration

export DAKERA_API_URL=http://localhost:3300
export DAKERA_API_KEY=dk-your-key

Both DakeraMemory and DakeraVectorStore read from these environment variables when api_url and api_key are not passed explicitly.

Links