Skip to main content
Attach metadata to documents at index time, then constrain queries to the documents whose metadata matches a filter passed as QueryOptions.filter. Filtering is evaluated on the locally loaded index, so call load_index() (or open a session) before querying with a filter.

Operators

Compose multiple conditions with $and / $or (nestable). A single condition can be passed on its own without a wrapper. Metadata values are strings. Filter values can be str, int or float; a datetime raises TypeError. Dicts and JSON passed to create_index or add_docs may also hold number and boolean metadata values. They are stored as strings: 30 becomes "30", and a boolean becomes "true" or "false". Filter booleans with those strings, such as {"$eq": "true"}, not with Python True. (moss 1.18.0+)

On a loaded index

Inside a session

A session query takes the same filter syntax, evaluated in-memory against the local session index. The example below indexes a call transcript and applies a range of operators.

Date ranges

Store dates as Unix epoch seconds in a decimal string and filter with integers, so both sides compare as numbers. Filter by date explains the encoding and the pitfalls of ISO 8601 strings.

Hybrid search

Blend semantic and keyword scoring.

Sessions

Filter against a live local index.