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, QueryTransformerHyDE
HyDE asks an LLM for a hypothetical answer to the query and searches with that answer.
| Parameter | Type | Default | Description |
|---|---|---|---|
model | Optional[Model] | None | Model 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. |
prompt | str | Built-in prompt | Prompt sent to the model. Replaces the built-in prompt and must contain the {query} placeholder. |
include_query | bool | False | Search with the query followed by the hypothetical answer instead of the answer alone. |
max_characters | int | 2000 | Maximum 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.
| Method | Description |
|---|---|
transform(query, run_response=None) -> str | Returns the query to search with. Subclasses must implement it. |
atransform(query, run_response=None) -> str | Async variant. The default runs transform() in a worker thread. |
| Argument | Type | Description |
|---|---|---|
query | str | The query passed to the search. |
run_response | Optional[Any] | The current run output. Pass it to a model call so the call is counted in run metrics. |