SPM — StellarPath Memory Operating System Docs

LangChain adapter

Published Last reviewed Applies to SPM-Polaris

Use the LangChain adapter when a LangChain application should recall SPM memory before a chat-model call and store the completed turn afterwards. The adapter contains SpmMemory and SpmCallbackHandler. It is version 0.1.0 and is not published to PyPI yet.

Install from source

Clone SPM-Polaris and install the adapter directory. Install your LangChain packages in the same environment.

git clone https://github.com/VeridicalTech/SPM-Polaris.git
cd SPM-Polaris/sdk/langchain
pip install -e .

Do not use pip install spm-langchain as a public registry install. The package is not on PyPI yet.

Set the connection and memory settings before starting your application:

export SPM_BASE_URL=https://api.spmos.ai
export SPM_API_KEY=your-spm-key
export SPM_USER_PARTITION=your-user
export SPM_MEMORY_TOP_K=6
export SPM_MEMORY_TIMEOUT=10

SPM_USER_PARTITION is optional. SPM_MEMORY_TOP_K and SPM_MEMORY_TIMEOUT default to 6 and 10 seconds.

Add the callback

import os
from langchain_core.runnables import RunnableConfig
from spm_langchain import SpmCallbackHandler, SpmMemory

memory = SpmMemory(
    base_url=os.environ["SPM_BASE_URL"],
    api_key=os.environ["SPM_API_KEY"],
    user_partition=os.getenv("SPM_USER_PARTITION", ""),
    top_k=int(os.getenv("SPM_MEMORY_TOP_K", "6")),
    timeout=float(os.getenv("SPM_MEMORY_TIMEOUT", "10")),
)
callback = SpmCallbackHandler(memory)

result = chain.invoke(
    {"input": "What did I say about the launch date?"},
    config=RunnableConfig(callbacks=[callback]),
)

Before a chat-model call, the callback finds the latest user message and calls SPM recall. When recall passes, it reads the cited evidence and adds it as a SystemMessage. A refusal is a normal result, not an exception. Any gate_reason other than passed becomes a short no supporting memory note instead of verified support.

After the model finishes, the callback combines the user message and assistant output into one turn. It creates a deterministic SHA-256 idempotency key and sends the turn to SPM ingest. This makes repeated delivery of the same turn safe at the API boundary. Writes are best effort.

Limits and failure behavior

The adapter does not perform server-side summarization. It sends the text it receives from the callback, subject to the memory API's limits. It does not read across user partitions. A partition must be allowed by the API key.

The adapter performs recall for each model call. It does not cache recall results because SPM read tokens expire after about 300 seconds. Network and API failures are swallowed. Recall returns a short no supporting memory note for failures, and ingest failures do not fail the model call. This keeps the callback from stopping your chain, but it also means your application must monitor its own memory-ingest and recall health if those operations are required.