Skip to content

discovery(rag): advanced_search_with_refinement() never called — AdaptiveRAGRefiner (Issue #1382) is not-wired dead code #4696

@mrveiss

Description

@mrveiss

Discovery

Issue #1382 (adaptive RAG query refinement) was closed as completed, but AdvancedRAGOptimizer.advanced_search_with_refinement() is never called from RAGService, any API handler, or any workflow in non-test production code. The AdaptiveRAGRefiner LLM-driven refinement loop is entirely dead.

Evidence

advanced_rag_optimizer.py:821 — method exists, is fully implemented:

async def advanced_search_with_refinement(
    self, query: str, max_results: int = 10, enable_reranking: bool = True,
) -> Tuple[List[SearchResult], RAGMetrics, list]:
    """Run advanced_search with RLM-driven query refinement (#1382)."""

rlm/__init__.py:16AdaptiveRAGRefiner is exported:

from rlm.rag_refiner import AdaptiveRAGRefiner

Grep for advanced_search_with_refinement across all non-test files:

autobot-backend/advanced_rag_optimizer.py:821:  (definition only — zero call sites)

RAGService.advanced_search() (the actual entry point) calls self.optimizer.advanced_search() directly, bypassing advanced_search_with_refinement() entirely.

What Was Intended

AdaptiveRAGRefiner evaluates retrieval results via LLM, scores relevance (0.0–1.0), and if results are insufficient, generates a refined query and re-searches — up to max_reflections rounds. This is a meaningful quality improvement: the LLM decides whether retrieved chunks actually answer the query.

Impact

Fix

Wire advanced_search_with_refinement() into RAGService._execute_search_with_timeout() (or as a wrapper around it), gated by a new RAGConfig flag enable_rlm_refinement: bool = False (opt-in, since it adds LLM latency per query).

Affected Files

  • autobot-backend/services/rag_service.py — call advanced_search_with_refinement() when config.enable_rlm_refinement is True
  • autobot-backend/services/rag_config.py — add enable_rlm_refinement: bool = False
  • autobot-backend/advanced_rag_optimizer.py — no change needed, method is already implemented

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingnot-wiredImplemented but not connected to apprag

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions