Drop-in RecallIO Memory for LangChain
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_recallio-1.1.0.tar.gz.
File metadata
- Download URL: langchain_recallio-1.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f79f50df4b18ad681deb6c9a0596598052f1c7da4244ef5968ad3007245ac88
|
|
| MD5 |
172f069a0917ceb11bad1e89c4707cf6
|
|
| BLAKE2b-256 |
24779e3daaff40c46379e4b4f94feb2853f931fc04e1f728a6ff71fcb84f0c75
|
File details
Details for the file langchain_recallio-1.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_recallio-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d7732fd5afc7431aa4360520cc99926e92e7f12b19852910a73fd8550e999e7
|
|
| MD5 |
5ea3b2e1e17004dd82cc702f1db762d3
|
|
| BLAKE2b-256 |
155347902b4c78cc24892d321570b7d68b64f5c5e36e4a70f0e09d033ae53937
|