docs(docs): Add RecallIO.AI as a memory provider (#32331)

Add requested files to add RecallIO as a memory provider.

---------

Co-authored-by: Frey <gfreyburger@gmail.com>
Co-authored-by: Mason Daugherty <mason@langchain.dev>
This commit is contained in:
RecallIO
2025-08-13 11:09:56 -04:00
committed by GitHub
parent 156ae2e69b
commit 4f71c35eb0
4 changed files with 257 additions and 8 deletions

View File

@@ -0,0 +1,215 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# RecallioMemory + LangChain Integration Demo\n",
"A minimal notebook to show drop-in usage of RecallioMemory in LangChain (with scoped writes and recall)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install recallio langchain langchain-recallio openai"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup: API Keys & Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_recallio.memory import RecallioMemory\n",
"from langchain_openai import ChatOpenAI\n",
"from langchain.prompts import ChatPromptTemplate\n",
"import os\n",
"\n",
"# Set your keys here or use environment variables\n",
"RECALLIO_API_KEY = os.getenv(\"RECALLIO_API_KEY\", \"YOUR_RECALLIO_API_KEY\")\n",
"OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\", \"YOUR_OPENAI_API_KEY\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize RecallioMemory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"memory = RecallioMemory(\n",
" project_id=\"project_abc\",\n",
" api_key=RECALLIO_API_KEY,\n",
" session_id=\"demo-session-001\",\n",
" user_id=\"demo-user-42\",\n",
" default_tags=[\"test\", \"langchain\"],\n",
" return_messages=True,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build a LangChain ConversationChain with RecallioMemory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# You can swap in any supported LLM here\n",
"llm = ChatOpenAI(api_key=OPENAI_API_KEY, temperature=0)\n",
"prompt = ChatPromptTemplate.from_messages(\n",
" [\n",
" (\n",
" \"system\",\n",
" \"The following is a friendly conversation between a human and an AI. \"\n",
" \"The AI is talkative and provides lots of specific details from its context. \"\n",
" \"If the AI does not know the answer to a question, it truthfully says it does not know.\",\n",
" ),\n",
" (\"placeholder\", \"{history}\"), # RecallioMemory will fill this slot\n",
" (\"human\", \"{input}\"),\n",
" ]\n",
")\n",
"\n",
"# LCEL chain that returns an AIMessage\n",
"base_chain = prompt | llm\n",
"\n",
"\n",
"# Create a stateful chain using RecallioMemory\n",
"def chat_with_memory(user_input: str):\n",
" # Load conversation history from memory\n",
" memory_vars = memory.load_memory_variables({\"input\": user_input})\n",
"\n",
" # Run the chain with history and user input\n",
" response = base_chain.invoke(\n",
" {\"input\": user_input, \"history\": memory_vars.get(\"history\", \"\")}\n",
" )\n",
"\n",
" # Save the conversation to memory\n",
" memory.save_context({\"input\": user_input}, {\"output\": response.content})\n",
"\n",
" return response"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example: Chat with Memory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bot: Hello Guillaume! It's nice to meet you. How can I assist you today?\n"
]
}
],
"source": [
"# First user message note the AI remembers the name\n",
"resp1 = chat_with_memory(\"Hi! My name is Guillaume. Remember that.\")\n",
"print(\"Bot:\", resp1.content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bot: Your name is Guillaume.\n"
]
}
],
"source": [
"# Second user message AI should recall the name from memory\n",
"resp2 = chat_with_memory(\"What is my name?\")\n",
"print(\"Bot:\", resp2.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## See What Is Stored in Recallio\n",
"This is for debugging/demo only; in production, you wouldn't do this on every run."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Current memory variables: {'history': [HumanMessage(content='Name is Guillaume', additional_kwargs={}, response_metadata={})]}\n"
]
}
],
"source": [
"print(\"Current memory variables:\", memory.load_memory_variables({}))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clear Memory (Optional Cleanup - Requires Manager level Key)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# memory.clear()\n",
"# print(\"Memory cleared.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,31 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Recallio\n",
"\n",
"[Recallio](https://recallio.ai/) is a powerfull API allowing to store, index, and retrieve application “memories” with built-in fact extraction, dynamic summaries, reranked recall, and a full knowledge-graph layer.\n",
"\n",
"\n",
"## Installation\n",
"\n",
"```bash\n",
"pip install langchain-recallio\n",
"```\n",
"\n",
"```python\n",
"from langchain_recallio.memory import RecallioMemory\n",
"```"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}