Official Python SDK for RecallrAI – a revolutionary contextual memory system that enables AI assistants to form meaningful connections between conversations, just like human memory.
Note: All datetime objects returned by the SDK are in UTC timezone.
Install the SDK via Poetry or pip:
poetry add recallrai
# or
pip install recallraiThe SDK provides full async/await support for all operations! Use AsyncRecallrAI, AsyncUser, and AsyncSession for async applications. All usage patterns are identical to the sync versions, just with await keywords.
Create a client instance with your API key and project ID:
fromrecallraiimportRecallrAIclient=RecallrAI(
api_key="rai_yourapikey",
project_id="project-uuid",
base_url="https://api.recallrai.com", # custom endpoint if applicabletimeout=60, # seconds
)fromrecallrai.exceptionsimportUserAlreadyExistsErrortry:
user=client.create_user(user_id="user123", metadata={"name": "John Doe"})
print(f"Created user: {user.user_id}")
print(f"User metadata: {user.metadata}")
print(f"Created at: {user.created_at}")
print(f"Merge conflict enabled: {user.merge_conflict_enabled}") # None = inherit project settingexceptUserAlreadyExistsErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundErrortry:
user=client.get_user("user123")
print(f"User metadata: {user.metadata}")
print(f"Last active: {user.last_active_at}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")If user_id is already trusted, you can skip the lookup request:
user=client.get_user("user123", validate=False)user_list=client.list_users(offset=0, limit=10, metadata_filter={"role": "admin"})
print(f"Total users: {user_list.total}")
print(f"Has more users: {user_list.has_more}")
print("---")
foruinuser_list.users:
print(f"User ID: {u.user_id}")
print(f"Metadata: {u.metadata}")
print(f"Created at: {u.created_at}")
print(f"Last active: {u.last_active_at}")
print("---")fromrecallrai.exceptionsimportUserNotFoundError, UserAlreadyExistsErrortry:
user=client.get_user("user123")
# update() mutates the instance; no value is returneduser.update(
new_metadata={"name": "John Doe", "role": "admin"},
new_user_id="john_doe",
merge_conflict_enabled=True# override: always raise merge conflicts for this user
)
print(f"Updated user ID: {user.user_id}")
print(f"Updated metadata: {user.metadata}")
print(f"Merge conflict enabled: {user.merge_conflict_enabled}")
print(f"Last active: {user.last_active_at}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptUserAlreadyExistsErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundErrortry:
user=client.get_user("john_doe")
user.refresh()
print(f"Refreshed user metadata: {user.metadata}")
print(f"Last active: {user.last_active_at}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundErrortry:
user=client.get_user("john_doe")
user.delete()
print("User deleted successfully")
exceptUserNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundErrorfromrecallrai.sessionimportSessiontry:
# First, get the useruser=client.get_user("user123")
# Create a session for the user.session: Session=user.create_session(
auto_process_after_seconds=600,
metadata={"type": "chat"}
)
print("Created session id:", session.session_id)
exceptUserNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrortry:
# First, get the useruser=client.get_user("user123")
# Retrieve an existing session by its IDsession=user.get_session(session_id="session-uuid")
print("Session status:", session.status)
print("Session metadata:", session.metadata)
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")If session_id is trusted, you can skip this lookup request:
session=user.get_session(session_id="session-uuid", validate=False)fromrecallrai.modelsimportRecallStrategy# Skips GET /api/v1/users/{user_id}user=client.get_user("user123", validate=False)
# Skips GET /api/v1/users/{user_id}/sessions/{session_id}session=user.get_session(session_id="session-uuid", validate=False)
# Goes directly to context retrievalcontext=session.get_context(recall_strategy=RecallStrategy.LOW_LATENCY)
print(context.context)Use this only when IDs are already trusted by your system. This optimization skips SDK pre-validation calls.
When validate=False is used, unknown reference fields are set to UNAVAILABLE until you call refresh().
Import it from recallrai.models when you need to check for this sentinel.
fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrortry:
# First, get the useruser=client.get_user("user123")
# Retrieve an existing session by its IDsession=user.get_session(session_id="session-uuid")
# Update session metadatasession.update(new_metadata={"type": "support_chat"})
print("Updated session metadata:", session.metadata)
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrortry:
# First, get the useruser=client.get_user("user123")
# Retrieve an existing session by its IDsession=user.get_session(session_id="session-uuid")
# Refresh session data from the serversession.refresh()
print("Session status:", session.status)
print("Refreshed session metadata:", session.metadata)
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrortry:
user=client.get_user("user123")
session=user.get_session(session_id="session-uuid")
session.delete()
print("Session deleted successfully")
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.modelsimportSessionStatusfromrecallrai.exceptionsimportUserNotFoundErrortry:
# First, get the useruser=client.get_user("user123")
# List sessions for this user with optional filterssession_list=user.list_sessions(
offset=0,
limit=10,
metadata_filter={"type": "chat"}, # optional: filter by session metadatastatus_filter=[SessionStatus.PENDING, SessionStatus.PROCESSING] # optional: filter by session status
)
print(f"Total sessions: {session_list.total}")
print(f"Has more sessions: {session_list.has_more}")
forsinsession_list.sessions:
print(s.session_id, s.status, s.metadata)
exceptUserNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundError, InvalidSessionStateErrorfromrecallrai.modelsimportMessageRoletry:
# Add a user messagesession.add_message(role=MessageRole.USER, content="Hello! How are you?")
# Add an assistant messagesession.add_message(role=MessageRole.ASSISTANT, content="I'm an assistant. How can I help you?")
# Available message roles:# - MessageRole.USER: Messages from the user/human# - MessageRole.ASSISTANT: Messages from the AI assistantexceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")
exceptInvalidSessionStateErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrorfromrecallrai.modelsimportRecallStrategytry:
# Get context with default parameterscontext=session.get_context()
print("Context:", context.context)
# Get context with specific recall strategycontext=session.get_context(recall_strategy=RecallStrategy.LOW_LATENCY)
print("Context:", context.context)
# Get context with custom memory retrieval parameterscontext=session.get_context(
recall_strategy=RecallStrategy.BALANCED,
min_top_k=10,
max_top_k=100,
memories_threshold=0.6,
summaries_threshold=0.5,
last_n_messages=20,
last_n_summaries=5,
timezone="America/Los_Angeles"# Optional: timezone for timestamp formatting, None for UTC
)
print("Context:", context.context)
# Get context with metadata detailscontext=session.get_context(include_metadata_ids=True)
ifcontext.metadata:
print("Memory IDs:", context.metadata.memory_ids)
print("Session IDs:", context.metadata.session_ids)
print("Vector Queries:", context.metadata.vector_search_queries)
print("Keywords:", context.metadata.keywords)
print("Summary Queries:", context.metadata.session_summaries_search_queries)
print("Date Filters:", context.metadata.date_range_filters)
print("Agent Reasoning:", context.metadata.agent_reasoning)
# Available recall strategies:# - RecallStrategy.LOW_LATENCY: Fast retrieval with basic relevance# - RecallStrategy.BALANCED: Good balance of speed and quality (default)# - RecallStrategy.AGENTIC: Agentic exploration for complex queries# Parameters:# - min_top_k: Minimum number of memories to return (default: 15, range: 5-50)# - max_top_k: Maximum number of memories to return (default: 50, range: 10-100)# - memories_threshold: Similarity threshold for memories (default: 0.6, range: 0.2-0.8)# - summaries_threshold: Similarity threshold for summaries (default: 0.5, range: 0.2-0.8)# - last_n_messages: Number of last messages to include in context (optional, range: 1-100)# - last_n_summaries: Number of last summaries to include in context (optional, range: 1-20)# - timezone: Timezone for formatting timestamps (optional, e.g., 'America/New_York', None for UTC)# - include_system_prompt: Whether to include the default system prompt of Recallr AI (default: True)exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrorfromrecallrai.modelsimportRecallStrategytry:
foreventinsession.get_context_stream(
recall_strategy=RecallStrategy.BALANCED,
timezone="America/Los_Angeles",
):
ifevent.status_update_message:
print("Status:", event.status_update_message)
ifevent.metadata:
print("Metadata:", event.metadata)
ifevent.is_final:
ifevent.error_message:
print("Error:", event.error_message)
else:
print("Final context:", event.context)
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundError, InvalidSessionStateErrortry:
session.process()
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")
exceptInvalidSessionStateErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, SessionNotFoundErrortry:
# Paginated retrievalmessages=session.get_messages(offset=0, limit=50)
formsginmessages.messages:
print(f"{msg.role.value.upper()} (at {msg.timestamp}): {msg.content}")
print(f"Has more?: {messages.has_more}")
print(f"Total messages: {messages.total}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptSessionNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, InvalidCategoriesErrortry:
user=client.get_user("user123")
# List memories with all available optionsmemories=user.list_memories(
categories=["food_preferences", "allergies"], # optional: filter by categoriessession_id_filter=["session-uuid-1", "session-uuid-2"], # optional: filter by specific sessionssession_metadata_filter={"environment": "production"}, # optional: filter by session metadataoffset=0,
limit=20, # max 200include_previous_versions=True, # default: True - include version historyinclude_connected_memories=True, # default: True - include related memories
)
formeminmemories.items:
print(f"Memory ID: {mem.memory_id}")
print(f"Categories: {mem.categories}")
print(f"Content: {mem.content}")
print(f"Created at: {mem.created_at}")
print(f"Session ID: {mem.session_id}")
# Version informationprint(f"Version: {mem.version_number} of {mem.total_versions}")
print(f"Has previous versions: {mem.has_previous_versions}")
# Previous versions (if included)ifmem.previous_versions:
print(f"Previous versions: {len(mem.previous_versions)}")
forversioninmem.previous_versions:
print(f" - Version {version.version_number}: {version.content}")
print(f" Created: {version.created_at}, Expired: {version.expired_at}")
print(f" Expiration reason: {version.expiration_reason}")
# Connected memories (if included)ifmem.connected_memories:
print(f"Connected memories: {len(mem.connected_memories)}")
forconnectedinmem.connected_memories:
print(f" - {connected.memory_id}: {connected.content}")
# Merge conflict statusprint(f"Merge conflict in progress: {mem.merge_conflict_in_progress}")
print("---")
print(f"Has more?: {memories.has_more}")
print(f"Total memories: {memories.total}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptInvalidCategoriesErrorase:
print(f"Invalid categories: {e.invalid_categories}")
print(f"Error: {e}")Each memory item returned contains the following information:
- memory_id: Unique identifier for the current/latest version of the memory
- categories: List of category strings the memory belongs to
- content: The current version's content text
- created_at: Timestamp when the latest version was created
- session_id: ID of the session that created this version
- version_number: Which version this is (e.g., 3 means this is the 3rd version)
- total_versions: Total number of versions that exist for this memory
- has_previous_versions: Boolean indicating if
total_versions > 1 - previous_versions (optional): List of
MemoryVersionInfoobjects containing:version_number: Sequential version number (1 = oldest)content: Content of that versioncreated_at: When this version was createdexpired_at: When this version expiredexpiration_reason: Why it expired (e.g., new version created)
- connected_memories (optional): List of
MemoryRelationshipobjects containing:memory_id: ID of the connected memorycontent: Brief content for context
- merge_conflict_in_progress: Boolean indicating if this memory has an active merge conflict
Retrieve the most recent messages for a user across all their sessions. This is particularly useful for chatbot applications where you need conversation context, such as WhatsApp support bots where you want to pass the last few messages to understand the ongoing conversation.
fromrecallrai.exceptionsimportUserNotFoundErrortry:
user=client.get_user("user123")
# Fetch last N messages (e.g., last 5)messages=user.get_last_n_messages(n=5)
formsginmessages.messages:
print(f"Session ID: {msg.session_id}")
print(f"{msg.role.upper()} (at {msg.timestamp}): {msg.content}")
print("---")
exceptUserNotFoundErrorase:
print(f"Error: {e}")When RecallrAI processes sessions, it may detect conflicts between new memories and existing ones. The SDK provides comprehensive tools to handle these merge conflicts, allowing you to guide the resolution process through clarifying questions.
fromrecallrai.exceptionsimportUserNotFoundErrorfromrecallrai.modelsimportMergeConflictStatustry:
user=client.get_user("user123")
# List all merge conflicts (with optional status filter)conflicts=user.list_merge_conflicts(
offset=0,
limit=10,
status=MergeConflictStatus.PENDING, # optional: filter by statussort_by="created_at", # created_at, resolved_atsort_order="desc", # asc, desc
)
print(f"Total conflicts: {conflicts.total}")
print(f"Has more: {conflicts.has_more}")
forconfinconflicts.conflicts:
print(f"Conflict ID: {conf.conflict_id}")
print(f"Status: {conf.status}")
print(f"New memory: {conf.proposed_memory_content}")
print(f"Conflicting memories: {len(conf.conflicting_memories)}")
print(f"Questions: {len(conf.clarifying_questions)}")
print(f"Created at: {conf.created_at}")
print("---")
exceptUserNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, MergeConflictNotFoundErrortry:
user=client.get_user("user123")
conflict=user.get_merge_conflict("conflict-uuid")
print(f"Conflict ID: {conflict.conflict_id}")
print(f"Status: {conflict.status.value}")
print(f"New memory content: {conflict.proposed_memory_content}")
# Examine conflicting memoriesprint("\nConflicting memories:")
formeminconflict.conflicting_memories:
print(f" Content: {mem.content}")
print(f" Reason: {mem.reason}")
print()
# View clarifying questionsprint("Clarifying questions:")
forquesinconflict.clarifying_questions:
print(f" Question: {ques.question}")
print(f" Options: {ques.options}")
print()
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptMergeConflictNotFoundErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimport (
UserNotFoundError, MergeConflictNotFoundError,
MergeConflictAlreadyResolvedError,
MergeConflictInvalidQuestionsError,
MergeConflictMissingAnswersError,
MergeConflictInvalidAnswerError,
ValidationError
)
fromrecallrai.modelsimportMergeConflictAnswertry:
user=client.get_user("user123")
conflict=user.get_merge_conflict("conflict-uuid")
# Prepare answers to the clarifying questionsanswers= []
forquesinconflict.clarifying_questions:
print(f" Question: {ques.question}")
print(f" Options: {ques.options}")
print()
answer=MergeConflictAnswer(
question=ques.question,
answer=ques.options[0], # Select first optionmessage="User prefers this option based on recent conversation"
)
answers.append(answer)
# Resolve the conflictconflict.resolve(answers)
print(f"Conflict resolved! Status: {conflict.status}")
print(f"Resolved at: {conflict.resolved_at}")
ifconflict.resolution_data:
print(f"Resolution data: {conflict.resolution_data}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptMergeConflictNotFoundErrorase:
print(f"Error: {e}")
exceptMergeConflictAlreadyResolvedErrorase:
print(f"Error: {e}")
exceptMergeConflictInvalidQuestionsErrorase:
print(f"Error: {e}")
ife.invalid_questions:
print(f"Invalid questions: {e.invalid_questions}")
exceptMergeConflictMissingAnswersErrorase:
print(f"Error: {e}")
ife.missing_questions:
print(f"Missing answers for: {e.missing_questions}")
exceptMergeConflictInvalidAnswerErrorase:
print(f"Error: {e}")
ife.questionande.valid_options:
print(f"Question: {e.question}")
print(f"Valid options: {e.valid_options}")
exceptValidationErrorase:
print(f"Error: {e}")fromrecallrai.exceptionsimportUserNotFoundError, MergeConflictNotFoundErrortry:
user=client.get_user("user123")
conflict=user.get_merge_conflict("conflict-uuid")
# Refresh to get latest status from serverconflict.refresh()
print(f"Current status: {conflict.status}")
print(f"Last updated: {conflict.resolved_at}")
exceptUserNotFoundErrorase:
print(f"Error: {e}")
exceptMergeConflictNotFoundErrorase:
print(f"Error: {e}")The merge conflict system uses several status values to track the lifecycle of conflicts:
- PENDING: Conflict detected and waiting for resolution
- IN_QUEUE: Conflict is queued for automated processing
- RESOLVING: Conflict is being processed
- RESOLVED: Conflict has been successfully resolved
- FAILED: Conflict resolution failed
importopenaifromrecallraiimportRecallrAIfromrecallrai.exceptionsimportUserNotFoundErrorfromrecallrai.modelsimportMessageRole# Initialize RecallrAI and OpenAI clientsrai_client=RecallrAI(
api_key="rai_yourapikey", project_id="your-project-uuid"
)
oai_client=openai.OpenAI(api_key="your-openai-api-key")
defchat_with_memory(user_id, session_id=None):
# Get or create usertry:
user=rai_client.get_user(user_id)
exceptUserNotFoundError:
user=rai_client.create_user(user_id)
# Create a new session or get an existing oneifsession_id:
session=user.get_session(session_id=session_id)
else:
session=user.create_session(auto_process_after_seconds=1800)
print(f"Created new session: {session.session_id}")
print("Chat session started. Type 'exit' to end the conversation.")
whileTrue:
# Get user inputuser_message=input("You: ")
ifuser_message.lower() =='exit':
break# Add the user message to RecallrAIsession.add_message(role=MessageRole.USER, content=user_message)
# Get context from RecallrAI after adding the user message# You can specify a recall strategy for different performance/quality trade-offs# Additional parameters like min_top_k, max_top_k, memories_threshold, summaries_threshold, last_n_messages, last_n_summaries are availablecontext=session.get_context() # Uses default BALANCED strategy# Create a system prompt that includes the contextsystem_prompt="You are a helpful assistant"+context.context# Get previous messagesmessages=session.get_messages(offset=0, limit=50)
previous_messages= [{"role": message.role, "content": message.content} formessageinmessages.messages]
# Call the LLM with the system prompt and conversation historyresponse=oai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": system_prompt},
**previous_messages,
],
temperature=0.7
)
assistant_message=response.choices[0].message.content# Print the assistant's responseprint(f"Assistant: {assistant_message}")
# Add the assistant's response to RecallrAIsession.add_message(role=MessageRole.ASSISTANT, content=assistant_message)
# Process the session at the end of the conversationprint("Processing session to update memory...")
session.process()
print(f"Session ended. Session ID: {session.session_id}")
returnsession.session_id# Example usageif__name__=="__main__":
user_id="user123"# To continue a previous session, uncomment below and provide the session ID# previous_session_id = "previously-saved-session-uuid"# session_id = chat_with_memory(user_id, previous_session_id)# Start a new sessionsession_id=chat_with_memory(user_id)
print(f"To continue this conversation later, use session ID: {session_id}")The RecallrAI SDK implements a comprehensive exception hierarchy to help you handle different error scenarios gracefully:
- RecallrAIError: The base exception for all SDK-specific errors. All other exceptions inherit from this.
- AuthenticationError: Raised when there's an issue with your API key or project ID authentication.
- TimeoutError: Occurs when a request takes too long to complete.
- ConnectionError: Happens when the SDK cannot establish a connection to the RecallrAI API.
- InternalServerError: Raised when the RecallrAI API returns a 5xx error code.
- RateLimitError: Raised when the API rate limit has been exceeded (HTTP 429). When available, the
retry_aftervalue is provided in the exception details.
- UserNotFoundError: Raised when attempting to access a user that doesn't exist.
- UserAlreadyExistsError: Occurs when creating a user with an ID that already exists.
- InvalidCategoriesError: Raised when filtering user memories by categories that do not exist in the project. The exception contains the list of invalid categories in
e.invalid_categories.
- SessionNotFoundError: Raised when attempting to access a non-existent session.
- InvalidSessionStateError: Occurs when performing an operation that's not valid for the current session state (e.g., adding a message to a processed session).
- MergeConflictError: Base class for merge conflict-related exceptions.
- MergeConflictNotFoundError: Raised when attempting to access a merge conflict that doesn't exist.
- MergeConflictAlreadyResolvedError: Occurs when trying to resolve a merge conflict that has already been processed.
- MergeConflictInvalidQuestionsError: Raised when the provided questions don't match the original clarifying questions.
- MergeConflictMissingAnswersError: Occurs when not all required clarifying questions have been answered.
- MergeConflictInvalidAnswerError: Raised when an answer is not one of the valid options for a question.
- ValidationError: Raised when provided data doesn't meet the required format or constraints.
You can import exceptions directly from the recallrai.exceptions module:
# Import specific exceptionsfromrecallrai.exceptionsimport (
UserNotFoundError, SessionNotFoundError,
InvalidCategoriesError,
MergeConflictNotFoundError,
MergeConflictAlreadyResolvedError,
MergeConflictInvalidQuestionsError,
MergeConflictMissingAnswersError,
MergeConflictInvalidAnswerError,
)
# Import all exceptionsfromrecallrai.exceptionsimport (
RecallrAIError,
AuthenticationError,
TimeoutError,
ConnectionError,
InternalServerError,
RateLimitError,
SessionNotFoundError, InvalidSessionStateError,
UserNotFoundError, UserAlreadyExistsError,
InvalidCategoriesError,
ValidationError,
MergeConflictError,
MergeConflictNotFoundError,
MergeConflictAlreadyResolvedError,
MergeConflictInvalidQuestionsError,
MergeConflictMissingAnswersError,
MergeConflictInvalidAnswerError,
)flowchart LR
%% Title
title[Errors and Exceptions Hierarchy]
style title fill:none,stroke:none
%% Base exception class
Exception[Exception]
RecallrAIError[RecallrAIError]
%% First level exceptions
AuthenticationError[AuthenticationError]
NetworkError[NetworkError]
ServerError[ServerError]
UserError[UserError]
SessionError[SessionError]
MergeConflictError[MergeConflictError]
ValidationError[ValidationError]
%% Second level exceptions - NetworkError children
TimeoutError[TimeoutError]
ConnectionError[ConnectionError]
%% Second level exceptions - ServerError children
InternalServerError[Internal ServerError]
RateLimitError[RateLimitError]
%% Second level exceptions - UserError children
UserNotFoundError[User NotFound Error]
UserAlreadyExistsError[User AlreadyExists Error]
%% Second level exceptions - SessionError children
InvalidSessionStateError[Invalid SessionState Error]
SessionNotFoundError[Session NotFound Error]
%% Second level exceptions - MergeConflictError children
MergeConflictNotFoundError[MergeConflict NotFound Error]
MergeConflictAlreadyResolvedError[MergeConflict AlreadyResolved Error]
MergeConflictInvalidQuestionsError[MergeConflict InvalidQuestions Error]
MergeConflictMissingAnswersError[MergeConflict MissingAnswers Error]
MergeConflictInvalidAnswerError[MergeConflict InvalidAnswer Error]
%% Connect parent to base
Exception --> RecallrAIError
%% Connect base to first level
RecallrAIError --> AuthenticationError
RecallrAIError --> NetworkError
RecallrAIError --> ServerError
RecallrAIError --> UserError
RecallrAIError --> SessionError
RecallrAIError --> MergeConflictError
RecallrAIError --> ValidationError
%% Connect first level to second level
NetworkError --> TimeoutError
NetworkError --> ConnectionError
ServerError --> InternalServerError
ServerError --> RateLimitError
UserError --> UserNotFoundError
UserError --> UserAlreadyExistsError
SessionError --> InvalidSessionStateError
SessionError --> SessionNotFoundError
MergeConflictError --> MergeConflictNotFoundError
MergeConflictError --> MergeConflictAlreadyResolvedError
MergeConflictError --> MergeConflictInvalidQuestionsError
MergeConflictError --> MergeConflictMissingAnswersError
MergeConflictError --> MergeConflictInvalidAnswerError
When implementing error handling with the RecallrAI SDK, consider these best practices:
Handle specific exceptions first: Catch more specific exceptions before general ones.
try: # SDK operationexceptUserNotFoundError: # Specific handlingexceptRecallrAIError: # General fallback
Implement retry logic for transient errors: Network and timeout errors might be temporary.
Log detailed error information: Exceptions contain useful information for debugging.
Handle common user flows: For example, check if a user exists before operations, or create them if they don't:
try: user=client.get_user(user_id) exceptUserNotFoundError: user=client.create_user(user_id)
For more detailed information on specific exceptions, refer to the API documentation.
This README outlines the basic usage of the RecallrAI SDK functions for user and session management. For additional documentation and advanced usage, please see the official documentation or the source code repository on GitHub.