Metadata Filtering
Metadata filtering lets you attach structured key-value pairs to your files at index time, then narrow search results at query time using those fields. This is useful for scoping searches by department, date range, access level, content type, or any other dimension relevant to your data.
Attaching Metadata at Index Time
Pass custom_metadata on any indexing endpoint. Every chunk from that file inherits the metadata.
Plain text
Cloud storage (S3, GCS, Azure, R2)
Metadata applies to all files in the indexing job.
Supported value types
Filtering at Query Time
Pass metadata_filter in the query request body to restrict results to chunks matching your criteria.
Filters work with both inference: true (AI-powered answers) and inference: false (raw search results).
Filter Operators
Combining Filters
Implicit AND
Multiple fields at the top level are combined with AND:
This matches chunks where department is “finance” AND year is at least 2024 AND is_public is false.
Explicit OR
Use $or to match chunks that satisfy any of the conditions:
Mixing AND and OR
Combine top-level AND with nested OR:
This matches chunks from 2024 or later in either the legal or finance department.
Full Example
Index documents with metadata, then query with filters: