Memory filters provide a flexible way to query and retrieve specific memories from your memory store. You can filter by users, agents, content categories, time ranges, and combine multiple conditions using logical operators.
When to use filters
When working with large-scale memory stores, you need precise control over which memories to retrieve. Filters help you:- Isolate user data: Retrieve memories for specific users while maintaining privacy
- Debug and audit: Export specific memory subsets for analysis
- Target content: Find memories with specific categories or metadata
- Time-based queries: Retrieve memories within specific date ranges
- Performance optimization: Reduce query complexity by pre-filtering
Filter structure
Filters use a nested JSON structure with logical operators at the root:Available fields and operators
Entity fields
Time fields
Content fields
Special fields
* wildcard matches any non-null value. Records with null values for that field are excluded.eq, ne, gte, etc.). SQL-style symbols such as >= or != are rejected by the Platform API.Common filter patterns
Use these ready-made filters to target typical retrieval scenarios without rebuilding logic from scratch.Single user
Single user
All users
All users
User across all runs
User across all runs
eq, contains, and ne. Operators such as in, gt, or lt trigger a FilterValidationError. For multi-value checks, wrap multiple equality clauses in OR.Content search
Find memories containing specific text, categories, or metadata values.Text search (keywords)
Text search (keywords)
contains for case-sensitive matching and icontains for case-insensitive.keywords filter works on get_all, but passing it to search() currently returns a 500 (MEM-5746). For text relevance during a search, pass the text to the query argument instead of filtering on keywords.Categories
Categories
Metadata
Metadata
Time-based filtering
Retrieve memories within specific date ranges using time operators.Date range
Date range
Multiple criteria
Combine various filters for complex queries across different dimensions.Multiple users
Multiple users
OR logic
OR logic
Exclude categories
Exclude categories
Specific memory IDs
Specific memory IDs
All entities populated
All entities populated
user_id equals user_123 and run_id/app_id are both non-null. It does not require other entity fields to be null.Advanced examples
Level up foundational patterns with compound filters that coordinate entity scope, tighten time windows, and weave in exclusion rules for high-precision retrievals.Multi-dimensional filtering
Multi-dimensional filtering
Entity-specific retrieval
Entity-specific retrieval
Nested NOT/OR logic
Nested NOT/OR logic
Best practices
AND, OR, or NOT. A bare filter like {"user_id": "alice"} works on its own; wrap conditions in a logical operator only when you need to combine more than one."*" to match any non-null value for a field.user_id and agent_id in the same AND clause only returns records that have both values set. Memories created by a normal client.add never do: each extracted fact is attributed to its speaker, so it carries user_id or agent_id, not both. Use OR to match either scope. Only Direct Import (infer=False) writes both fields on one record.A filter object with both an AND key and a sibling OR key at the same level silently drops the OR branch today. Nest the OR inside the AND array instead of placing them as siblings.Troubleshooting
Missing results with agent_id
Missing results with agent_id
user_id but don’t see agent memories.Solution: A user_id filter only matches records that have that user_id set; it won’t surface memories written with only agent_id. Use OR to query both scopes:ne operator returns too much
ne operator returns too much
ne comparison pulls in records with null values.Solution: Pair ne with a wildcard guard:Case-insensitive text match
Case-insensitive text match
keywords with icontains on get_all:get_all. It is not supported on search() yet (returns a 500, MEM-5746) - for search, pass the text to the query argument instead.Date range between two dates
Date range between two dates
gte for the start and lt for the end boundary:Metadata filter not working
Metadata filter not working
FAQ
Do I need AND/OR/NOT?
Do I need AND/OR/NOT?
{"user_id": "u1"} works on its own. Add AND, OR, or NOT only when you need to combine more than one condition.What does * match?
What does * match?
Why use wildcards?
Why use wildcards?
"*" to include non-null values.Is = required?
Is = required?
{"user_id": "u1"} works.Can I filter nested metadata?
Can I filter nested metadata?
How to search text?
How to search text?
keywords filter with contains/icontains on get_all. For relevance-ranked search, pass the text to the query argument on search(). Note: keywords is not supported inside search() filters yet (returns a 500, MEM-5746).Can I nest AND/OR?
Can I nest AND/OR?
Known limitations
- Filters only constrain the fields you mention; unmentioned entity fields are not required to be null. A record carries
user_idoragent_id(never both) unless it came from Direct Import, plus whateverapp_idandrun_idwere passed. - Metadata supports only bare/
eq,contains, andnecomparisons. - Wildcards (
"*") match only records where the field is already non-null.