diff --git a/README.md b/README.md
index 16fb4c60..775b128b 100644
--- a/README.md
+++ b/README.md
@@ -71,11 +71,11 @@ To get started with RAG, either from scratch or using a popular framework like L
| [/RAG/07_user_role_based_rag.ipynb](python-recipes/RAG/07_user_role_based_rag.ipynb) | Implement a simple RBAC policy with vector search using Redis |
### LLM Memory
-LLMs are stateless. To maintain context within a conversation chat sessions must be stored and resent to the LLM. Redis manages the storage and retrieval of chat sessions to maintain context and conversational relevance.
+LLMs are stateless. To maintain context within a conversation chat sessions must be stored and resent to the LLM. Redis manages the storage and retrieval of message histories to maintain context and conversational relevance.
| Recipe | Description |
| --- | --- |
-| [/llm-session-manager/00_session_manager.ipynb](python-recipes/llm-session-manager/00_llm_session_manager.ipynb) | LLM session manager with semantic similarity |
-| [/llm-session-manager/01_multiple_sessions.ipynb](python-recipes/llm-session-manager/01_multiple_sessions.ipynb) | Handle multiple simultaneous chats with one instance |
+| [/llm-message-history/00_message_history.ipynb](python-recipes/llm-message-history/00_llm_message_history.ipynb) | LLM message history with semantic similarity |
+| [/llm-message-history/01_multiple_sessions.ipynb](python-recipes/llm-message-history/01_multiple_sessions.ipynb) | Handle multiple simultaneous chats with one instance |
### Semantic Cache
An estimated 31% of LLM queries are potentially redundant ([source](https://arxiv.org/pdf/2403.02694)). Redis enables semantic caching to help cut down on LLM costs quickly.
diff --git a/python-recipes/RAG/07_user_role_based_rag.ipynb b/python-recipes/RAG/07_user_role_based_rag.ipynb
index f7b4466e..278159aa 100644
--- a/python-recipes/RAG/07_user_role_based_rag.ipynb
+++ b/python-recipes/RAG/07_user_role_based_rag.ipynb
@@ -60,7 +60,7 @@
}
],
"source": [
- "%pip install -q \"redisvl>=0.4.1\" openai langchain-community pypdf"
+ "%pip install -q \"redisvl>=0.6.0\" openai langchain-community pypdf"
]
},
{
@@ -1335,7 +1335,7 @@
"from typing import List, Optional\n",
"import os\n",
"\n",
- "from redisvl.extensions.session_manager import StandardSessionManager\n",
+ "from redisvl.extensions.message_history import MessageHistory\n",
"\n",
"\n",
"class RAGChatManager:\n",
@@ -1395,7 +1395,7 @@
" user_id: User identifier\n",
" \"\"\"\n",
" if user_id not in self.sessions:\n",
- " self.sessions[user_id] = StandardSessionManager(\n",
+ " self.sessions[user_id] = MessageHistory(\n",
" name=f\"session:{user_id}\",\n",
" redis_client=self.kb.redis_client\n",
" )\n",
diff --git a/python-recipes/llm-session-manager/00_llm_session_manager.ipynb b/python-recipes/llm-message-history/00_llm_message_history.ipynb
similarity index 96%
rename from python-recipes/llm-session-manager/00_llm_session_manager.ipynb
rename to python-recipes/llm-message-history/00_llm_message_history.ipynb
index 83b9f6d3..bc2c1cd1 100644
--- a/python-recipes/llm-session-manager/00_llm_session_manager.ipynb
+++ b/python-recipes/llm-message-history/00_llm_message_history.ipynb
@@ -6,16 +6,16 @@
"source": [
"\n",
"\n",
- "# LLM Session Memory - Multiple Sessions\n",
+ "# LLM Message History\n",
"\n",
- "Large Language Models are inherently stateless and have no knowledge of previous interactions with a user, or even of previous parts of the current conversation. While this may not be noticeable when asking simple questions, it becomes a hinderance when engaging in long running conversations that rely on conversational context.\n",
+ "Large Language Models are inherently stateless and have no knowledge of previous interactions with a user, or even of previous parts of the current conversation. While this may not be noticeable when asking simple questions, it becomes a hindrance when engaging in long running conversations that rely on conversational context.\n",
"\n",
"The solution to this problem is to append the previous conversation history to each subsequent call to the LLM.\n",
"\n",
- "This notebook will show how to use Redis to structure and store and retrieve this conversational session memory.\n",
+ "This notebook will show how to use Redis to structure and store and retrieve this conversational message history.\n",
"\n",
"## Let's Begin!\n",
- "
\n"
+ "
\n"
]
},
{
@@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
- "%pip install cohere \"redisvl>=0.4.1\" sentence-transformers"
+ "%pip install cohere \"redisvl>=0.6.0\" sentence-transformers"
]
},
{
@@ -153,7 +153,7 @@
" return response.text\n",
"\n",
" def remap(self, context) -> List[Dict]:\n",
- " ''' re-index the chat history to match the Cohere API requirements '''\n",
+ " ''' re-index the message history to match the Cohere API requirements '''\n",
" new_context = []\n",
" for statement in context:\n",
" if statement[\"role\"] == \"user\":\n",
@@ -174,9 +174,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Import SemanticSessionManager\n",
+ "### Import MessageHistory\n",
"\n",
- "redisvl provides the SemanticSessionManager for easy management of session state."
+ "redisvl provides the MessageHistory and SemanticMessageHistory classes for easy management of LLM conversations."
]
},
{
@@ -185,10 +185,10 @@
"metadata": {},
"outputs": [],
"source": [
- "from redisvl.extensions.session_manager import SemanticSessionManager\n",
+ "from redisvl.extensions.message_history import SemanticMessageHistory\n",
"\n",
- "user_session = SemanticSessionManager(name=\"llm chef\")\n",
- "user_session.add_message({\"role\":\"system\", \"content\":\"You are a helpful chef, assisting people in making delicious meals\"})"
+ "user_history = SemanticMessageHistory(name=\"llm chef\")\n",
+ "user_history.add_message({\"role\":\"system\", \"content\":\"You are a helpful chef, assisting people in making delicious meals\"})"
]
},
{
@@ -224,9 +224,9 @@
],
"source": [
"prompt = \"can you give me some ideas for breakfast?\"\n",
- "context = user_session.get_recent()\n",
+ "context = user_history.get_recent()\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "user_session.store(prompt, response)\n",
+ "user_history.store(prompt, response)\n",
"print('USER: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -286,9 +286,9 @@
],
"source": [
"prompt = \"can you give me the recipe for those pancakes?\"\n",
- "context = user_session.get_recent()\n",
+ "context = user_history.get_recent()\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "user_session.store(prompt, response)\n",
+ "user_history.store(prompt, response)\n",
"print('USER: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -360,9 +360,9 @@
],
"source": [
"prompt =\"I am vegetarian. Can you remove the eggs?\"\n",
- "context = user_session.get_recent()\n",
+ "context = user_history.get_recent()\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "user_session.store(prompt, response)\n",
+ "user_history.store(prompt, response)\n",
"print('USER: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -436,9 +436,9 @@
],
"source": [
"prompt = \"I am also vegan. Can you replace the butter too?\"\n",
- "context = user_session.get_recent()\n",
+ "context = user_history.get_recent()\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "user_session.store(prompt, response)\n",
+ "user_history.store(prompt, response)\n",
"print('USER: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -521,9 +521,9 @@
],
"source": [
"prompt = \"I changed my mind. Can you give me the first recipe from your list?\"\n",
- "context = user_session.get_recent(top_k=5)\n",
+ "context = user_history.get_recent(top_k=5)\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "user_session.store(prompt, response)\n",
+ "user_history.store(prompt, response)\n",
"print('USER: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -561,7 +561,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Semantic session memory"
+ "## Semantic message history"
]
},
{
@@ -608,10 +608,10 @@
],
"source": [
"prompt = \"Can you give me the avocado one?\"\n",
- "user_session.set_distance_threshold(0.75)\n",
- "context = user_session.get_relevant(prompt=prompt)\n",
+ "user_history.set_distance_threshold(0.75)\n",
+ "context = user_history.get_relevant(prompt=prompt)\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "user_session.store(prompt, response)\n",
+ "user_history.store(prompt, response)\n",
"print('USER: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -648,7 +648,7 @@
"metadata": {},
"outputs": [],
"source": [
- "user_session.clear()"
+ "user_history.clear()"
]
}
],
diff --git a/python-recipes/llm-session-manager/01_multiple_sessions.ipynb b/python-recipes/llm-message-history/01_multiple_sessions.ipynb
similarity index 89%
rename from python-recipes/llm-session-manager/01_multiple_sessions.ipynb
rename to python-recipes/llm-message-history/01_multiple_sessions.ipynb
index f6e30546..1453dc44 100644
--- a/python-recipes/llm-session-manager/01_multiple_sessions.ipynb
+++ b/python-recipes/llm-message-history/01_multiple_sessions.ipynb
@@ -6,13 +6,13 @@
"source": [
"\n",
"\n",
- "# LLM Session Memory - Multiple Sessions\n",
+ "# LLM Message History - Multiple Sessions\n",
"\n",
"Large Language Models are inherently stateless and have no knowledge of previous interactions with a user, or even of previous parts of the current conversation. The solution to this problem is to append the previous conversation history to each subsequent call to the LLM.\n",
- "This notebook will show how to use Redis to structure and store and retrieve this conversational session memory and how to manage multiple sessions simultaneously.\n",
+ "This notebook will show how to use Redis to structure and store and retrieve this conversational message history and how to manage multiple conversation sessions simultaneously.\n",
"\n",
"## Let's Begin!\n",
- "
\n"
+ "
\n"
]
},
{
@@ -28,7 +28,7 @@
"metadata": {},
"outputs": [],
"source": [
- "%pip install cohere \"redisvl>=0.4.1\" sentence-transformers"
+ "%pip install cohere \"redisvl>=0.6.0\" sentence-transformers"
]
},
{
@@ -150,7 +150,7 @@
" return response.text\n",
"\n",
" def remap(self, context) -> List[Dict]:\n",
- " ''' re-index the chat history to match the Cohere API requirements '''\n",
+ " ''' re-index the message history to match the Cohere API requirements '''\n",
" new_context = []\n",
" for statement in context:\n",
" if statement[\"role\"] == \"user\":\n",
@@ -171,9 +171,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Import SemanticSessionManager\n",
+ "### Import SemanticMessageHistory\n",
"\n",
- "redisvl provides the SemanticSessionManager for easy management of session state.\n",
+ "redisvl provides the SemanticMessageHistory for easy management of conversational message history state.\n",
"It also allows for tagging of messages to separate conversation sessions with the `session_tag` optional parameter.\n",
"Let's create a few personas that can talk to our AI.\n"
]
@@ -195,16 +195,16 @@
"metadata": {},
"outputs": [],
"source": [
- "from redisvl.extensions.session_manager import SemanticSessionManager\n",
+ "from redisvl.extensions.message_history import SemanticMessageHistory\n",
"\n",
- "session = SemanticSessionManager(name='budgeting help')"
+ "history = SemanticMessageHistory(name='budgeting help')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "#### Here we'll have multiple separate conversations simultaneously, all using the same session manager.\n",
+ "#### Here we'll have multiple separate conversations simultaneously, all using the same message history object.\n",
"#### Let's add some conversation history to get started.\n",
"\n",
"#### We'll assign each message to one of our users with their own `session_tag`."
@@ -217,7 +217,7 @@
"outputs": [],
"source": [
"# adding messages to the student session\n",
- "session.add_messages(\n",
+ "history.add_messages(\n",
" [{\"role\":\"system\",\n",
" \"content\":\"You are a personal assistant helping people create sound financial budgets. Be very brief and concise in your responses.\"},\n",
" {\"role\":\"user\",\n",
@@ -230,7 +230,7 @@
" session_tag=student)\n",
"\n",
"#adding messages to the young professional session\n",
- "session.add_messages(\n",
+ "history.add_messages(\n",
" [{\"role\":\"system\",\n",
" \"content\":\"You are a personal assistant helping people create sound financial budgets. Be very brief and concise in your responses.\"},\n",
" {\"role\":\"user\",\n",
@@ -243,7 +243,7 @@
" session_tag=yp)\n",
"\n",
"#adding messages to the retiree session\n",
- "session.add_messages(\n",
+ "history.add_messages(\n",
" [{\"role\":\"system\",\n",
" \"content\":\"You are a personal assistant helping people create sound financial budgets. Be very brief and concise in your responses.\"},\n",
" {\"role\":\"user\",\n",
@@ -260,7 +260,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "#### With the same session manager calling the same LLM we can handle distinct conversations. There's no need to instantiate separate classes or clients.\n",
+ "#### With the same message history instance and calling the same LLM we can handle distinct conversations. There's no need to instantiate separate classes or clients.\n",
"\n",
"#### Just retrieve the conversation of interest using the same `session_tag` parameter when fetching context."
]
@@ -282,9 +282,9 @@
],
"source": [
"prompt = \"What is the single most important thing I should focus on financially?\"\n",
- "context = session.get_recent(session_tag=student)\n",
+ "context = history.get_recent(session_tag=student)\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "session.store(prompt, response, session_tag=student)\n",
+ "history.store(prompt, response, session_tag=student)\n",
"print('Student: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -306,9 +306,9 @@
],
"source": [
"prompt = \"What is the single most important thing I should focus on financially?\"\n",
- "context = session.get_recent(session_tag=yp)\n",
+ "context = history.get_recent(session_tag=yp)\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "session.store(prompt, response, session_tag=yp)\n",
+ "history.store(prompt, response, session_tag=yp)\n",
"print('Young Professional: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -330,9 +330,9 @@
],
"source": [
"prompt = \"What is the single most important thing I should focus on financially?\"\n",
- "context = session.get_recent(session_tag=retired)\n",
+ "context = history.get_recent(session_tag=retired)\n",
"response = client.converse(prompt=prompt, context=context)\n",
- "session.store(prompt, response, session_tag=retired)\n",
+ "history.store(prompt, response, session_tag=retired)\n",
"print('Retiree: ', prompt)\n",
"print('\\nLLM: ', response)"
]
@@ -362,7 +362,7 @@
}
],
"source": [
- "for ctx in session.get_recent(session_tag=student):\n",
+ "for ctx in history.get_recent(session_tag=student):\n",
" print(ctx)"
]
},
@@ -372,7 +372,7 @@
"metadata": {},
"outputs": [],
"source": [
- "session.clear()"
+ "history.clear()"
]
}
],