Effective memory retrieval is key to building AI applications that provide contextually relevant responses. Mem0's search() operation is your gateway to accessing stored memories intelligently. Memories that get created in the first place through Mem0's add() operation. In this guide, we'll explore how to use client.search() effectively, from basic queries to advanced filtering techniques.
Basic Search Operations
The syntax of the search operation is:
Simple Search Example
Understanding Output Formats
Mem0 supports two output formats for search results:
V1.0 (Default) Output Structure
v1.0 returns a list of memory dictionaries.
V1.1 Enhanced Output
The main structural difference is that v1.1 adds a wrapper dict with a "results" key, while v1.0 returns the list directly. The individual memory objects inside maintain the same structure in both formats. This wrapper in v1.1 could be useful if you need to add additional metadata about the search results in the future while maintaining backwards compatibility. Filtering at search time isn't the only lever you have — Mem0 also lets you control what gets stored in the first place using inclusion and exclusion rules on add(), so irrelevant or sensitive content never enters the memory store to begin with.
Advanced Search Features
Mem0's v2 search API provides powerful filtering capabilities that allow you to precisely target the memories you need. These advanced features help you narrow down search results based on multiple criteria, time ranges, and complex logical conditions.
1. Using Version 2 Filters
Version 2 filters enable you to combine multiple search conditions using logical operators. This is particularly useful when you need to find memories that match several specific criteria simultaneously. In this example, we're searching for memories that belong to a specific user AND were created by either the travel assistant or customer support agent:
2. Date-Based Filtering
When you need to search for memories within specific time periods, date-based filtering allows you to set date ranges using "gte" (greater than or equal to) and "lte" (less than or equal to) operators. This is valuable for analyzing historical data or focusing on recent interactions:
These advanced search filters give you greater control over memory retrieval, allowing you to build more sophisticated and context-aware AI applications. user_id and agent_id are two of five scoping dimensions Mem0 supports; see how they combine in multi-user and multi-agent deployments, including run_id and org_id, and what happens when scope is set too broad or too narrow.
Conclusion
The client.search() operation is a powerful tool for retrieving relevant memories from your Mem0 instance. By understanding its features and following best practices, you can build AI applications that effectively use past interactions to provide more personalized and context-aware responses. Remember to use appropriate output formats for your needs and leverage v2 filters for complex queries.
View Mem0's documentation to learn more about integrating our memory features. You can also reach out to us at founders@mem0.ai.
GET TLDR from:
Summarize
Website/Footer
Summarize
Website/Footer
Summarize
Website/Footer
Summarize
Website/Footer










