Skip to main content

QueryRewriter

Trait QueryRewriter 

Source
pub trait QueryRewriter: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn rewrite<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        original: &'life1 str,
        previous_attempts: &'life2 [String],
        ctx: &'life3 ExecutionContext,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
}
Expand description

Async trait the corrective-RAG recipe calls when retrieval quality requires another attempt with a different query. Implementations may be LLM-driven, heuristic (query-expansion / synonym-bag), classifier-routed, or any hybrid — the recipe takes whatever string comes back and re-runs retrieval with it.

Required Methods§

Source

fn name(&self) -> &'static str

Stable rewriter identifier — surfaces in audit dashboards alongside the per-attempt query string.

Source

fn rewrite<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, original: &'life1 str, previous_attempts: &'life2 [String], ctx: &'life3 ExecutionContext, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Produce a corrected query. original is the user’s untouched first attempt; previous_attempts is every failed retry since (in chronological order, oldest first) so the rewriter can avoid emitting an attempt the recipe has already failed on. An empty previous_attempts slice means this is the first rewrite — the rewriter sees only the original.

Implementors§

Source§

impl<M> QueryRewriter for LlmQueryRewriter<M>
where M: Runnable<Vec<Message>, Message> + 'static,