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
Filters were introduced in v1.0.0 to provide precise control over memory retrieval.
Filter structure
Filters use a nested JSON structure with logical operators at the root:Available fields and operators
Entity fields
| Field | Operators | Example |
|---|---|---|
user_id | =, !=, in, * | {"user_id": "user_123"} |
agent_id | =, !=, in, * | {"agent_id": "*"} |
app_id | =, !=, in, * | {"app_id": {"in": ["app1", "app2"]}} |
run_id | =, !=, in, * | {"run_id": "*"} |
Time fields
| Field | Operators | Example |
|---|---|---|
created_at | >, >=, <, <=, =, != | {"created_at": {"gte": "2024-01-01"}} |
updated_at | >, >=, <, <=, =, != | {"updated_at": {"lt": "2024-12-31"}} |
timestamp | >, >=, <, <=, =, != | {"timestamp": {"gt": "2024-01-01"}} |
Content fields
| Field | Operators | Example |
|---|---|---|
categories | =, !=, in, contains | {"categories": {"in": ["finance"]}} |
metadata | =, != | {"metadata": {"key": "value"}} |
keywords | contains, icontains | {"keywords": {"icontains": "invoice"}} |
Special fields
| Field | Operators | Example |
|---|---|---|
memory_ids | in | {"memory_ids": ["id1", "id2"]} |
The
* wildcard matches any non-null value. Records with null values for that field are excluded.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
Content search
Find memories containing specific text, categories, or metadata values.Text search
Text search
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
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
Cross-entity relationships
Cross-entity relationships
Nested NOT/OR logic
Nested NOT/OR logic
Best practices
The root must be
AND, OR, or NOT with an array of conditions.Use
"*" to match any non-null value for a field.When you specify
user_id only, other entity fields default to null. Use wildcards to include them.Troubleshooting
Missing results with agent_id
Missing results with agent_id
Problem: Filtered by
user_id but don’t see agent memories.Solution: Add a wildcard for agent_id so non-null entries return:ne operator returns too much
ne operator returns too much
Problem:
ne comparison pulls in records with null values.Solution: Pair ne with a wildcard guard:Case-insensitive search
Case-insensitive search
Solution: Swap to
icontains to normalize casing.Date range between two dates
Date range between two dates
Solution: Use
gte for the start and lt for the end boundary:Metadata filter not working
Metadata filter not working
Solution: Match top-level metadata keys exactly:
FAQ
Do I need AND/OR/NOT?
Do I need AND/OR/NOT?
Yes. The root must be a logical operator with an array.
What does * match?
What does * match?
Any non-null value. Nulls are excluded.
Why use wildcards?
Why use wildcards?
Unspecified fields default to NULL. Use
"*" to include non-null values.Is = required?
Is = required?
No. Equality is the default:
{"user_id": "u1"} works.Can I filter nested metadata?
Can I filter nested metadata?
Only top-level keys are supported.
How to search text?
How to search text?
Use
keywords with contains (case-sensitive) or icontains (case-insensitive).Can I nest AND/OR?
Can I nest AND/OR?