Self-query retrieval
Self-querying · Query-to-filter extraction
Turning the structured parts of a natural-language question, such as a file name, page or document type, into metadata filters before searching.
In DocSlurpGlossary entry
On this page
Self-query retrieval splits a question into what to search for and what to filter on. “What do the slides from the Q3 review say about the London expansion?” contains a topic (the London expansion) and a constraint (slides). Embedded as one string, “slides” just nudges the vector a little toward presentation-like text. Extracted as a filter, mimeType = pptx, it removes every non-slide passage before ranking, which is exact.
Extraction is done by rules, by a language model asked to return structured filters, or both. Typical targets are file names (“in the growth plan”), page ranges (“pages 10 to 14”), document types, languages, authors and dates. The remaining text becomes the search query, and the filters go to metadata filtering.
The gotcha: inventing filters
A model asked for filters sometimes finds them where none were meant. “Why was 2026 a record year?” might become date >= 2026-01-01, which drops the board update uploaded in December 2025. A wrong filter is worse than no filter: the right passage isn’t ranked low, it’s excluded. Instruct the model to extract only explicit constraints, validate the output against the fields you actually have, and show users which filters were applied.
DocSlurp’s selfQuery option combines rules (page ranges, quoted or “in the …” file names, words like “slides”, “spreadsheet” or “scanned”, and language names) with an optional model pass that is told to return only explicit filters as JSON. With it on, budget tag:finance searches for “budget” within documents tagged finance.
In DocSlurp
In DocSlurp
Off in default project retrieval settings; selfQuery: true applies heuristics (page ranges, quoted or “in the …” file names, type words such as “slides” or “spreadsheet”, language names) plus an optional model pass that returns JSON filters (core/server/src/search/self-query.ts). It also consumes tag: labels.