Recallio Memory for LangChain
This repository provides an implementation of RecallioMemory, a drop-in replacement for BaseMemory from LangChain. It stores conversation history in the Recallio cloud service using the official recallio client.
Features
- Scoped writes – memories can be associated with a specific
session_idoruser_id. - TTL support – pass a time-to+live in seconds and it will be converted to an expiration timestamp stored alongside each memory.
- Vector recall – previous messages are retrieved from Recallio using semantic search. Memories can also be filtered by custom tags.
Installation
pip install recallio langchain langchain-recallio openai
Usage
#Setup: API Keys & Imports
from langchain_recallio.memory import RecallioMemory
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
import os
# Set your keys here or use environment variables
RECALLIO_API_KEY = os.getenv("RECALLIO_API_KEY", "YOUR_RECALLIO_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "YOUR_OPENAI_API_KEY")
#Initialize RecallioMemory
memory = RecallioMemory(
project_id="project_abc",
api_key=RECALLIO_API_KEY,
session_id="demo-session-001",
user_id="demo-user-42",
default_tags=["test", "langchain"],
return_messages=True,
)
#Build a LangChain ConversationChain with RecallioMemory
# You can swap in any supported LLM here
llm = ChatOpenAI(api_key=OPENAI_API_KEY, temperature=0)
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"The following is a friendly conversation between a human and an AI. "
"The AI is talkative and provides lots of specific details from its context. "
"If the AI does not know the answer to a question, it truthfully says it does not know.",
),
("placeholder", "{history}"), # RecallioMemory will fill this slot
("human", "{input}"),
]
)
# LCEL chain that returns an AIMessage
base_chain = prompt | llm
# Create a stateful chain using RecallioMemory
def chat_with_memory(user_input: str):
# Load conversation history from memory
memory_vars = memory.load_memory_variables({"input": user_input})
# Run the chain with history and user input
response = base_chain.invoke(
{"input": user_input, "history": memory_vars.get("history", "")}
)
# Save the conversation to memory
memory.save_context({"input": user_input}, {"output": response.content})
return response
Example: Chat with Memory
# First user message – note the AI remembers the name
resp1 = chat_with_memory("Hi! My name is Guillaume. Remember that.")
print("Bot:", resp1.content)
# Second user message – AI should recall the name from memory
resp2 = chat_with_memory("What is my name?")
print("Bot:", resp2.content)
The tests use mocks and do not require a valid Recallio API key.
License
This project is distributed under the MIT license.
Release files for langchain-recallio 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_recallio-1.1.0.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_recallio-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / langchain_recallio-1.1.0.tar.gz
| Download URL | langchain_recallio-1.1.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f79f50df4b18ad681deb6c9a0596598052f1c7da4244ef5968ad3007245ac88
|
|
BLAKE2b-256 checksum How to use checksums |
24779e3daaff40c46379e4b4f94feb2853f931fc04e1f728a6ff71fcb84f0c75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / langchain_recallio-1.1.0-py3-none-any.whl
| Download URL | langchain_recallio-1.1.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d7732fd5afc7431aa4360520cc99926e92e7f12b19852910a73fd8550e999e7
|
|
BLAKE2b-256 checksum How to use checksums |
155347902b4c78cc24892d321570b7d68b64f5c5e36e4a70f0e09d033ae53937
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|