Integration
Long-term memory for LangChain
LangChain's `ConversationBufferMemory` is in-process: your worker restarts and the memory's gone. `VectorStoreRetrieverMemory` requires a vector DB you have to host. `EngramChatMessageHistory` is a direct replacement that gives you BM25 plus vector plus knowledge-graph retrieval against a hosted backend, with explanation traces.
Install
Three steps: sign up for an Engram API key, paste a BYOK LLM-provider key on /models, then drop the snippet below into LangChain.
Three steps to memory in your agent
- Sign up. Free, no card. You'll land on a Getting Started page that walks the next two steps.
- Add your LLM key. Engram is BYOK. Paste an OpenAI / Anthropic / Groq / Together / Fireworks key and we'll route every extraction and query call through your provider. You pay your provider directly. We never see your inference.
- Paste the snippet below into your agent and restart it. Use
Authorization: Bearer <api-key>with the API key from your portal.
engram-langchain: durable BaseChatMessageHistory
Drop-in replacement for ConversationBufferMemory / VectorStoreRetrieverMemory. One hosted backend with hybrid retrieval (BM25 + vector + KG) and an explanation trace on every recall. Source: github.com/lumetra-io/engram-langchain.
- Install the Python client + LangChain:
- Vendor
engram_langchain.pyfrom the repo (~30 LOC; PyPI release coming) and export your API key: - Use it as a
BaseChatMessageHistoryon any runnable:
pip install lumetra-engram langchain langchain-corecurl -fsSL https://raw.githubusercontent.com/lumetra-io/engram-langchain/main/engram_langchain.py -o engram_langchain.py
export ENGRAM_API_KEY="<api-key>"from langchain_core.runnables.history import RunnableWithMessageHistory
from engram_langchain import EngramChatMessageHistory
chain_with_memory = RunnableWithMessageHistory(
chain,
lambda session_id: EngramChatMessageHistory(bucket=f"user-{session_id}"),
input_messages_key="input",
history_messages_key="history",
)What you can do once memory's wired in
- Replace `ConversationBufferMemory` in an existing `RunnableWithMessageHistory` with a one-line swap
- Use per-session buckets with `lambda session_id: EngramChatMessageHistory(bucket=f'user-{session_id}')`
- Call `.query()` for semantic recall across the full history when the recent-window view isn't enough
- Stack with other LangChain memory classes if you want both summary memory and full retrieval
FAQ
Does this work with both `langchain` and `langchain-core`?
Yes. `EngramChatMessageHistory` extends `BaseChatMessageHistory` from `langchain-core`, so anything that consumes that interface works.
How do I get semantic recall instead of recent-window?
Call `.query('some question')` directly on an `EngramChatMessageHistory` instance. `.messages` returns the recent window (good for prompt-stuffing), while `.query()` runs hybrid retrieval against the entire bucket.
Is the file PyPI-installable yet?
For now you vendor `engram_langchain.py` from the repo (~30 LOC). PyPI release is coming, and the file is small enough to copy in the meantime.
Related integrations
Ship durable memory in LangChain today
Free tier: 10K memories and 50K retrievals per month. No credit card. Same Engram backend powers all 41 integrations, so memories you write from one client are immediately queryable from the rest.