Examples
- API Request
- TypeScript
- Python (Sync)
Overview
The Retrieve User Memory endpoint performs semantic search through a user’s stored memories to find the most relevant information based on a query. This is the primary endpoint for accessing user memories in your AI applications, enabling context-aware responses and personalized interactions.Functionality
- Semantic Search: Uses advanced vector search to find memories that are semantically similar to your query
- Relevance Ranking: Returns memories ranked by relevance to the search query
- Configurable Results: Control the number of memories returned with the
max_countparameter - Intelligent Selection: When
max_countis set to 0, Cortex intelligently selects the best memories based on relevance and context - Context-Aware: Finds memories that are contextually relevant, not just keyword matches
- Personalization: Optional
user_nameparameter enhances personalization by providing user context for more targeted memory retrieval
How Semantic Search Works
Unlike traditional keyword search, semantic search understands the meaning and context of your query. For example:- Query: “authentication preferences”
- Will find memories about: “JWT tokens”, “login methods”, “security settings”, etc.
- Even if the exact words don’t match
Use Cases
- Context Retrieval: Get relevant user context before generating AI responses
- Personalization: Find user preferences and past interactions for tailored experiences
- Memory-Based Chat: Enable AI to reference past conversations and user history
- Recommendation Systems: Use user memories to provide personalized recommendations
- Customer Support: Access user history and preferences for better support
Response
Advanced Usage: Context-Aware AI Response
Different Query Examples
max_count=0, Cortex will analyze all available memories and return only the most relevant ones based on semantic similarity and contextual relevance, automatically determining the optimal number of memories to return.
Important Notes
Empty Results: If no relevant memories are found, the endpoint returns an empty array. This is normal for new users or when searching for topics not covered in existing memories.
Query Optimization:
- Be specific about the type of information you’re looking for
- Consider using synonyms or related terms if initial queries don’t return results
- Shorter, focused queries often work better than long, complex ones
- Include the
user_nameparameter for enhanced personalization and more targeted memory retrieval
Error Responses
All endpoints return consistent error responses following the standard format. For detailed error information, see our Error Responses documentation.Authorizations
Query Parameters
Example:
Example:
Required range:
0 <= x <= 50Example: