LangMem is LangChain's in-process memory library, typically backed by a local vector store or an in-memory store. This guide covers the concept mapping and migration path to Spectron.
Concept mapping
| LangMem concept | Spectron equivalent | Notes |
|---|---|---|
| Namespace | Scope + Context | Spectron uses scope tags within a named Context |
| Memory (document) | Entities + attributes | Spectron extracts structure; LangMem stores flat text |
put_memories() | session.remember() | Write path is similar; extraction differs |
search_memory() | session.recall() | Spectron adds graph-density reranking |
get_memories() | session.profile() | Returns structured snapshot |
Memory type (semantic, episodic, procedural) | Memory category (knowledge, context, instructions) | Categories have different volatility and expiry |
delete_memories() | session.forget() | Spectron supports scoped and targeted forget |
| InMemoryStore | Embedded Spectron (in-process SurrealDB) | See the embedded deployment guide |
Migration example
LangMem (Python)
Spectron equivalent
Key differences
Persistence: LangMem with InMemoryStore loses all memory when the process restarts. Spectron is durable by default – all memory lives in SurrealDB and survives restarts, deployments, and crashes.
Structured extraction: LangMem stores memories as text documents. Spectron extracts structured entities, attributes, and relations. "Alice prefers concise answers" becomes an entity Person/alice with attribute communication_style = "concise, technical" – queryable and updatable as structured data.
Conflict handling: LangMem stores all memories and relies on the retrieval layer to resolve conflicts via recency ranking. Spectron detects contradictions and supersedes old attribute values, maintaining a correct, single current value with a history chain.
Namespace vs scope: LangMem uses a tuple namespace ("user", "alice"). Spectron uses a multi-dimensional scope dictionary {"user": "alice"}. Spectron scopes support subset matching – a query at {"org": "acme"} retrieves all memory across all users in that org.
Categorisation: Spectron's memory categories map loosely to LangMem memory types:
LangMem
semantic→ Spectronknowledge(facts, preferences)LangMem
episodic→ Spectroncontext(recent, auto-expiring events)LangMem
procedural→ Spectroninstructions(behavioural directives)
LangChain integration
Spectron ships a LangChain memory adapter (planned). Until it is released, use the SDK directly and inject the formatted context into your chain or graph:
Migrating from LangChain ConversationBufferMemory
If you are using the older LangChain ConversationBufferMemory or similar in-context memory, migration is straightforward: replace the buffer with Spectron sessions. Instead of passing the full conversation history as context (which grows without bound), pass a recalled summary from Spectron.
This approach scales indefinitely – context window size is bounded by the top_k recall, not by conversation length.