Criteria Retrieval
📢 Announcing our research paper: Mem0 achieves 26% higher accuracy than OpenAI Memory, 91% lower latency, and 90% token savings! Read the paper to learn how we're revolutionizing AI agent memory.
Mem0’s Criteria Retrieval feature allows you to retrieve memories based on specific criteria. This is useful when you need to find memories that match certain conditions or criteria, such as emotional content, sentiment, or other custom attributes.
Setting Up Custom Criteria
You can define custom criteria at the project level, assigning weights to each criterion. These weights will be normalized during memory retrieval.
Using Criteria Retrieval
After setting up your criteria, you can use them to filter and retrieve memories. Here’s an example:
Search Results Comparison
Let’s compare the results from criteria-based retrieval versus standard retrieval to see how the emotional criteria affects ranking:
Search Results (with Criteria)
Search Results (without Criteria)
Looking at the example results above, we can see how criteria-based filtering affects the output:
-
Memory Ordering: With criteria, memories with high joy scores (like feeling refreshed and drawing) are ranked higher, while without criteria, the most relevant memory (“User is happy today”) comes first.
-
Score Distribution: With criteria, scores are more spread out (0.116 to 0.666) and reflect the criteria weights, while without criteria, scores are more clustered (0.336 to 0.607) and based purely on relevance.
-
Negative Content: With criteria, the negative memory about rain has a much lower score (0.116) due to the emotion criteria, while without criteria it maintains a relatively high score (0.4617) due to its relevance.
-
Curiosity Content: The storm-related memory gets a moderate score (0.400) with criteria due to the curiosity weighting, while without criteria it’s ranked lower (0.340) as it’s less relevant to the happiness query.
Key Differences
-
Scoring: With criteria, normalized scores (0-1) are used based on custom criteria weights, while without criteria, standard relevance scoring is used
-
Ordering: With criteria, memories are first retrieved by relevance, then criteria-based filtering and prioritization is applied, while without criteria, ordering is solely by relevance
-
Filtering: With criteria, post-retrieval filtering based on custom criteria (joy, curiosity, etc.) is available, which isn’t available without criteria
When no custom criteria are specified, the search will default to standard relevance-based retrieval. In this case, results are returned based solely on their relevance to the query, without any additional filtering or prioritization that would normally be applied through criteria.
How It Works
- Criteria Definition: Define custom criteria with names, descriptions, and weights
- Project Configuration: Apply these criteria at the project level
- Memory Retrieval: Use v2 search with filters to retrieve memories based on your criteria
- Weighted Scoring: Memories are scored based on the defined criteria weights
Criteria retrieval is currently supported only in search v2. Make sure to use version="v2"
when performing searches with custom criteria.
If you have any questions, please feel free to reach out to us using one of the following methods: