Skip to main content

Module self_query

Module self_query 

Source
Expand description

SelfQueryRetriever — a self-querying retriever

Lets an LLM split a natural-language query into { query, filter }: the cleaned query goes to vector retrieval, and the parsed MetadataFilter is handed to vector_store.similarity_search_with_filter for metadata filtering (relying on S3’s unified filtering capability). The split goes through lc_core::judge::structured_call (binds a tool to get structured arguments, falling back to text parsing when the model does not support it), the same execution path as Guardrails / Evaluation; the allowed_attributes whitelist blocks the LLM from filtering on fields that do not exist.

No silent degradation: when a filter references a field outside the whitelist, it explicitly returns RetrieverError::InvalidFilter rather than dropping the filter and falling back to an unfiltered search — that would return data that should have been filtered out (data-plane over-exposure). An empty whitelist = filtering is entirely disabled: filters are always ignored with a warning (this is the established “disable filtering” pattern, not silent degradation).

Structs§

SelfQueryArgs
Structured parameters parsed by the LLM: the cleaned query + an optional metadata filter.
SelfQueryRetriever
Self-querying retriever: LLM splits the query -> whitelist validation -> filtered similarity search.