RewriteOutcome (rag/query_rewrite.py)

DeepTutor · deeptutor/services/rag/query_rewrite.py · python · Apache-2.0
ai, AI / Agents

Rewrites user queries into concise search queries using LLM, with fail-open behavior.

# Source: https://github.com/HKUDS/DeepTutor | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Single-query rewrite for retrieval.

Rewrites a conversational or anaphoric user query into one self-contained,
keyword-leaning search query before it reaches the KB pipeline. The layer is
fail-open by design: any LLM error, timeout, or empty output falls back to
the original query so retrieval never fails because of a rewrite.

Only the ``standalone`` strategy exists in v1 (one LLM call, one query).
``multi_query`` is reserved for a follow-up PR; the settings schema already
carries the ``strategy`` field so no migration is needed later.
"""

from __future__ import annotations

import as

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key