Filters
Narrow search, latest and items to what matches - who said it, what it is about, or your own metadata - with AND, OR and NOT.
filters narrows search, latest and items to the items you
added that match: by who said them, what they are about, or the metadata you gave them. A filter applies
before ranking, not after it, so a narrow filter does not come back short.
{
"query": "What did we decide about the budget?",
"filters": {
"AND": [
{ "metadata": { "priority": { "gte": 3 } } },
{ "mentions": "project:lisbon-trip" }
]
}
}The shape is the one Mem0's filters use: conditions written {"field": value} or {"field": {"op": value}},
combined with AND, OR and NOT.
Fields
| Field | Matches | Operators |
|---|---|---|
author | The item's author: its id, name, email or handle, ignoring case. | eq (a bare value), ne, in, nin, "*" |
mentions | What the item is about, as about takes it (project:lisbon-trip, or topic:diet for a bare diet), or its session as session:<id>. | contains (a bare value), in |
metadata.<key> | One top-level key of the item's metadata. | eq (a bare value), ne, in, nin, gt, gte, lt, lte, contains, icontains, "*" |
"*"means the field is set:{"metadata": {"source": "*"}}keeps items that have asource.- A metadata value is a string, a number, or
trueorfalse. A list is matched element by element, so{"metadata": {"tags": "urgent"}}matches"tags": ["urgent", "billing"]. Nested objects are kept with the item, but cannot be filtered on. - Numbers must be exact. Send an integer larger than 2^53 (9,007,199,254,740,992) as a string.
gt,gte,ltandltecompare numbers with numbers and strings with strings, nevertrueorfalse.containsmatches part of a string, or one element of a list;icontainsthe same, ignoring case. Both need a value that is not empty.inandnintake a list of 1 to 100 values.mentionstakes whatabouttakes, andsession:<id>. Anything else is refused with a422that says what to use instead, such asscopefor a place orauthorfor a person.
author and metadata are fields of items you add: what connected apps deliver has neither, so a condition on
them matches only your items.
Combining conditions
- Keys side by side must all match:
{"author": "Alice Chen", "metadata": {"source": "crm"}}. ANDandORtake a list of filters.NOTtakes one filter.- One operator per condition.
{"metadata": {"priority": {"gte": 1, "lte": 5}}}is refused; write two conditions underAND. - A filter holds at most 50 conditions, nested at most 5 deep.
What a filter matches
A filter tests items, and search and latest return excerpts and facts:
- An excerpt matches when any item in it matches.
- A negation (
ne,ninorNOT) keeps an excerpt only when none of its items matches what is negated. - A fact matches through the excerpt it was learned from.
On each route:
searchwithfiltersis a narrowed search: it returns facts and excerpts only.latestreturns the newest matching excerpts, or those betweenafterandbefore.itemslists the matching items. Items stillqueuedare not filtered, so a filtered list holds stored items only.
Over MCP, memory_search and memory_latest take the same filters. See the tools reference.
Errors
A filter that does not fit is refused with 422 before anything is read. detail names where the problem is,
then what is wrong:
{ "detail": "`filters`: filters.metadata.priority: one operator per condition, not 2; AND them. See https://docs.alexein.ai/api/search for what this route takes." }