Skip to main content
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

The * wildcard matches any non-null value. Records with null values for that field are excluded.
Use operator keywords exactly as shown (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.
Metadata filters only support bare values/eq, contains, and ne. Operators such as in, gt, or lt trigger a FilterValidationError. For multi-value checks, wrap multiple equality clauses in OR.
Find memories containing specific text, categories, or metadata values.
Use contains for case-sensitive matching and icontains for case-insensitive.
A 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.

Time-based filtering

Retrieve memories within specific date ranges using time operators.

Multiple criteria

Combine various filters for complex queries across different dimensions.
Matches records where 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.

Best practices

The root does not have to be 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.
Use "*" to match any non-null value for a field.
Combining 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

Problem: Filtered by 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:
Problem: ne comparison pulls in records with null values.Solution: Pair ne with a wildcard guard:
Solution: Use keywords with icontains on get_all:
This works on get_all. It is not supported on search() yet (returns a 500, MEM-5746) - for search, pass the text to the query argument instead.
Solution: Use gte for the start and lt for the end boundary:
Solution: Match top-level metadata keys exactly:

FAQ

No. A bare filter like {"user_id": "u1"} works on its own. Add AND, OR, or NOT only when you need to combine more than one condition.
Any non-null value. Nulls are excluded.
Unspecified fields default to NULL. Use "*" to include non-null values.
No. Equality is the default: {"user_id": "u1"} works.
Only top-level keys are supported.
For a substring match, use the 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).

Known limitations

  • Filters only constrain the fields you mention; unmentioned entity fields are not required to be null. A record carries user_id or agent_id (never both) unless it came from Direct Import, plus whatever app_id and run_id were passed.
  • Metadata supports only bare/eq, contains, and ne comparisons.
  • Wildcards ("*" ) match only records where the field is already non-null.