content/develop/ai/redisvl/api/session_manager.md
<a id="semantic-session-manager-api"></a>
class SemanticSessionManager(name, session_tag=None, prefix=None, vectorizer=None, distance_threshold=0.3, redis_client=None, redis_url='redis://localhost:6379', connection_kwargs={}, overwrite=False, **kwargs)Bases: BaseSessionManager
Initialize session memory with index
Session Manager stores the current and previous user text prompts and LLM responses to allow for enriching future prompts with session context. Session history is stored in individual user or LLM prompts and responses.
The proposed schema will support a single vector embedding constructed from either the prompt or response in a single string.
add_message(message, session_tag=None)Insert a single prompt or response into the session memory. A timestamp is associated with it so that it can be later sorted in sequential ordering after retrieval.
add_messages(messages, session_tag=None)Insert a list of prompts and responses into the session memory. A timestamp is associated with each so that they can be later sorted in sequential ordering after retrieval.
clear()Clears the chat session history.
delete()Clear all conversation keys and remove the search index.
drop(id=None)Remove a specific exchange from the conversation history.
get_recent(top_k=5, as_text=False, raw=False, session_tag=None)Retreive the recent conversation history in sequential order.
get_relevant(prompt, as_text=False, top_k=5, fall_back=False, session_tag=None, raw=False, distance_threshold=None)Searches the chat history for information semantically related to the specified prompt.
This method uses vector similarity search with a text prompt as input. It checks for semantically similar prompts and responses and gets the top k most relevant previous prompts or responses to include as context to the next LLM call.
Raises ValueError: if top_k is not an integer greater or equal to 0.
store(prompt, response, session_tag=None)Insert a prompt:response pair into the session memory. A timestamp is associated with each message so that they can be later sorted in sequential ordering after retrieval.
property messages: List[str] | List[Dict[str, str]]Returns the full chat history.
<a id="standard-session-manager-api"></a>
class StandardSessionManager(name, session_tag=None, prefix=None, redis_client=None, redis_url='redis://localhost:6379', connection_kwargs={}, **kwargs)Bases: BaseSessionManager
Initialize session memory
Session Manager stores the current and previous user text prompts and LLM responses to allow for enriching future prompts with session context.Session history is stored in individual user or LLM prompts and responses.
The proposed schema will support a single combined vector embedding constructed from the prompt & response in a single string.
add_message(message, session_tag=None)Insert a single prompt or response into the session memory. A timestamp is associated with it so that it can be later sorted in sequential ordering after retrieval.
add_messages(messages, session_tag=None)Insert a list of prompts and responses into the session memory. A timestamp is associated with each so that they can be later sorted in sequential ordering after retrieval.
clear()Clears the chat session history.
delete()Clear all conversation keys and remove the search index.
drop(id=None)Remove a specific exchange from the conversation history.
get_recent(top_k=5, as_text=False, raw=False, session_tag=None)Retrieve the recent conversation history in sequential order.
store(prompt, response, session_tag=None)Insert a prompt:response pair into the session memory. A timestamp is associated with each exchange so that they can be later sorted in sequential ordering after retrieval.
property messages: List[str] | List[Dict[str, str]]Returns the full chat history.