Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1Panel dev MaxKB Question Optimization

From Leeroopedia
Knowledge Sources
Domains NLP, RAG
Last Updated 2026-10-10 00:00 GMT

Overview

A query refinement technique that uses an LLM to rewrite ambiguous or context-dependent user questions into self-contained, retrieval-friendly queries.

Description

Question optimization (also called query rewriting or query expansion) is the first step in MaxKB's legacy chat pipeline. When a user asks a follow-up question like "How does it work?", the question lacks the context needed for effective retrieval. The BaseResetProblemStep sends the original question plus the last 3 chat history messages to an LLM, which produces a complete, context-aware reformulation. The result is extracted from `` tags in the LLM response. If no model is configured, the original question is returned unchanged.

Usage

Use this principle when designing:

  • Conversational RAG systems with follow-up questions
  • Query rewriting for improved retrieval accuracy
  • Context-aware question expansion pipelines

Theoretical Basis

The query rewriting process leverages LLM's understanding of conversational context:

# Abstract algorithm description (NOT real implementation)
def optimize_question(question, chat_history, llm_model):
    # Build context from last 3 conversation turns
    context = format_history(chat_history[-3:])
    prompt = f"Given context, rewrite this question: ({question}). Output in <data></data>"
    response = llm_model.invoke(context + [HumanMessage(prompt)])
    # Extract rewritten question from <data> tags
    return extract_tag(response, "data") or question

The `` tag extraction ensures the LLM output is constrained to the rewritten question, preventing verbose explanations from polluting the retrieval query.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment