You’ll use this when…
- Retrieval must respect multiple metadata conditions before returning context.
- You need to mix numeric, boolean, and string filters in a single query.
- Agents rely on deterministic filtering instead of broad semantic search alone.
Enhanced filtering requires Mem0 1.0.0 or later and a vector store that supports the operators you enable. Unsupported operators fall back to simple equality filters.
The TypeScript SDK accepts the same filter shape shown here—transpose the dictionaries to objects and reuse the keys unchanged.
Feature anatomy
Operator quick reference
Operator quick reference
| Operator | Meaning | When to use it |
|---|---|---|
eq / ne | Equals / not equals | Exact matches on strings, numbers, or booleans. |
gt / gte | Greater than / greater than or equal | Rank results by score, confidence, or any numeric field. |
lt / lte | Less than / less than or equal | Cap numeric values (e.g., ratings, timestamps). |
in / nin | In list / not in list | Pre-approve or block sets of values without chaining multiple filters. |
contains / icontains | Case-sensitive / case-insensitive substring match | Scan text fields for keywords. |
* | Wildcard | Require that a field exists, regardless of value. |
AND / OR / NOT | Combine filters | Build logic trees so multiple conditions work together. |
Metadata selectors
Start with key-value filters when you need direct matches on metadata fields.Expect only memories tagged with
category="preferences" to return for the given user_id.Comparison operators
Layer greater-than/less-than comparisons to rank results by score, confidence, or any numeric field. Equality helpers (eq, ne) keep string and boolean checks explicit.
List-based operators
Usein and nin when you want to pre-approve or exclude specific values without writing multiple equality checks.
Verify the response includes only memories in the whitelisted categories and omits any with archived or deleted status.
String operators
contains and icontains capture substring matches, making it easy to scan descriptions or tags for keywords without retrieving irrelevant memories.
Wildcard matching
Allow any value for a field while still requiring the field to exist—handy when the mere presence of a field matters.Logical combinations
Combine filters withAND, OR, and NOT to express complex decision trees. Nest logical operators to encode multi-branch workflows.
Inspect the response metadata—each returned memory should satisfy the combined logic tree exactly. If results look too broad, log the raw filters sent to your vector store.
Configure it
Tune your vector store so filter-heavy queries stay fast. Index fields you frequently filter on and keep complex checks for later in the evaluation order.After enabling indexing, benchmark the same query—latency should drop once the store can prune documents on indexed fields before vector scoring.
Put simple key=value filters on indexed fields before your range or text conditions so the store trims results early.
When you reorder filters so indexed fields come first (
good_filters example), queries typically return faster than the avoid_filters pattern where expensive text searches run before simple checks.Qdrant
Qdrant
Full comparison, list, and logical support. Handles deeply nested boolean logic efficiently.
Chroma
Chroma
Equality and basic comparisons only. Limited nesting—break large trees into smaller calls.
Pinecone
Pinecone
Comparisons plus
in/nin. Text operators are constrained; rely on tags where possible.Weaviate
Weaviate
Full operator coverage with advanced text filters. Best option when you need hybrid text + metadata queries.
If an operator is unsupported, most stores silently ignore that branch. Add validation before execution so you can fall back to simpler queries instead of returning empty results.
Migrate from earlier filters
Existing equality filters continue to work; add new operator branches gradually so agents can adopt richer queries without downtime.
See it in action
Project management filtering
Tasks returned should belong to the targeted projects, remain incomplete, and be assigned to one of the listed teammates.
Customer support filtering
Pair
agent_id filters with ticket-specific metadata so shared support bots return only the tickets they can act on in the current session.Content recommendation filtering
Confirm personalized feeds show only unread titles that meet the rating and language criteria.
Handle invalid operators
Validate filters before executing searches so you can catch typos or unsupported operators during development instead of at runtime.
Verify the feature is working
- Log the filters sent to your vector store and confirm the response metadata matches every clause.
- Benchmark queries before and after indexing to ensure latency improvements materialize.
- Add analytics or debug logging to track how often fallbacks execute when operators fail validation.
Best practices
- Use indexed fields first: Order filters so equality checks run before complex string operations.
- Combine operators intentionally: Keep logical trees readable—large nests are harder to debug.
- Test performance regularly: Benchmark critical queries with production-like payloads.
- Plan graceful degradation: Provide fallback filters when an operator isn’t available.
- Validate syntax early: Catch malformed filters during development to protect agents at runtime.