Query Transformer

Parameter reference for HyDE and the QueryTransformer base class, which rewrite the search query before Knowledge sends it to the vector database.

A query transformer rewrites the search query before Knowledge sends it to the vector database. Pass one to the query_transformer parameter of Knowledge. See Query Transformation.

from agno.knowledge.query_transformer import HyDE, QueryTransformer

HyDE

HyDE asks an LLM for a hypothetical answer to the query and searches with that answer.

ParameterTypeDefaultDescription
modelOptional[Model]NoneModel that writes the hypothetical answer. When unset, set to OpenAIResponses(id="gpt-5.4") on construction. Construction raises ImportError if no model is given and openai is not installed.
promptstrBuilt-in promptPrompt sent to the model. Replaces the built-in prompt and must contain the {query} placeholder.
include_queryboolFalseSearch with the query followed by the hypothetical answer instead of the answer alone.
max_charactersint2000Maximum length of the hypothetical answer. Longer replies are trimmed at a sentence or word break. Must be greater than 0.

HyDE returns the original query when the model call fails or the reply is empty.

QueryTransformer

Base class for custom query transformers.

MethodDescription
transform(query, run_response=None) -> strReturns the query to search with. Subclasses must implement it.
atransform(query, run_response=None) -> strAsync variant. The default runs transform() in a worker thread.
ArgumentTypeDescription
querystrThe query passed to the search.
run_responseOptional[Any]The current run output. Pass it to a model call so the call is counted in run metrics.