This guide summarizes the most impactful knobs for improving retrieval quality and answer grounding in MimirQ.
All settings are defined in
app/core/config.pyand can be set via.env.
When optimizing quality, follow this order to avoid “tuning noise”:
- Ingestion quality: parsing + governance + chunking (use Chunk Preview).
- Recall: retrieval top-k / thresholds, then hybrid fusion (BM25 + vector).
- Precision: reranking (prefer deterministic providers before LLM rerank).
- Query enhancements: rewrite / multi-query / HyDE / decomposition (one-by-one).
- Grounding: visible-evidence-only + claim checks (reduce hallucinations).
- Measure & gate: RAGAS + Evidence regression suites + CI gates.
- Explainability: trace replay + metrics + export artifacts.
Key companion guides:
- Platform design principles:
docs/guides/rag_platform_design_principles.md - Chunking:
docs/guides/chunk_preview.md,docs/guides/chunk_strategies.md - Hybrid fusion:
docs/guides/retrieval_fusion.md - Reranking:
docs/guides/reranking_colbert.md,docs/guides/reranking_ltr.md - Evidence API:
docs/guides/evidence_api.md - Regression gate:
docs/guides/regression_gate.md - Evaluation maturity model:
docs/guides/evaluation_maturity_model.md - Knowledge Graph (optional):
docs/guides/knowledge_graph.md
Key settings:
CHUNK_SIZECHUNK_OVERLAP
Rules of thumb:
- Increase
CHUNK_SIZEwhen chunks are too fragmented (too many partial matches). - Increase
CHUNK_OVERLAPwhen important context is split across chunk boundaries. - Avoid
CHUNK_OVERLAP >= CHUNK_SIZE(rejected by config validation).
Use the Chunk Preview UI to visualize and iterate:
- Guide:
docs/guides/chunk_preview.md - Strategies:
docs/guides/chunk_strategies.md
Key settings:
RETRIEVAL_TOP_K(how many chunks to retrieve)SIMILARITY_THRESHOLD(filter low-similarity chunks)
Typical tuning:
- If answers miss relevant facts: increase
RETRIEVAL_TOP_Kand/or lowerSIMILARITY_THRESHOLD. - If answers include irrelevant context: decrease
RETRIEVAL_TOP_Kand/or raiseSIMILARITY_THRESHOLD.
Key settings:
BM25_INDEX_ENABLED(enable keyword index)RETRIEVAL_FUSION_STRATEGY(linearorrrf)
When to use:
- Use BM25 for exact entity/keyword matching and for long technical documents.
- Use vector retrieval for semantic matching and paraphrased questions.
- Use
rrffusion when you want a robust ranking that combines both sources.
MimirQ supports an additional sparse candidate source (SPLADE-style scaffolding) that can improve recall on:
- acronyms (
k8svskubernetes) - domain synonyms / abbreviations
Key settings:
SPARSE_RETRIEVAL_ENABLEDSPARSE_RETRIEVAL_PROVIDER(currentlydeterministic)SPARSE_RETRIEVAL_SYNONYMS
Guide:
docs/guides/sparse_retrieval.md
Key settings:
RERANKER_PROVIDER(llm|pc|colbert|ltr|openai|dashscope|none)
Tradeoffs:
llmrerank improves precision but increases latency/cost.colbert/ltrare intended for deterministic/fast reranking (local providers; see guides below).noneis fastest; rely on better chunking + retrieval thresholds.
Guides:
docs/guides/reranking_colbert.mddocs/guides/reranking_ltr.md
These are off by default and can improve recall on ambiguous or short queries:
ENABLE_QUERY_REWRITE(rewrite follow-ups into standalone queries)QUERY_REWRITE_STRATEGY(versioned rewrite strategy id, e.g.kb_followup.v1; used for evaluation gating/rollback)
ENABLE_MULTI_QUERY(generate multiple query variants for recall)ENABLE_HYDE(generate a hypothetical passage to improve vector recall)ENABLE_QUERY_DECOMPOSITION(split complex questions into sub-questions)
Recommendation:
- Enable one at a time, measure impact with RAGAS/regression suites before enabling multiple.
Wave B 在 rag_config_template_resolver 增加了可选的 adaptive epsilon-greedy 路由能力(默认仍是 weighted,保持兼容)。
核心语义:
routing_mode=weighted:按ab_weight稳定分流。routing_mode=adaptive:epsilon概率探索,1-epsilon概率利用历史 reward 更高的 variant。feedback_reward_snapshot/feedback_reward_hook:把反馈聚合结果作为利用阶段的依据。
可审计输出:
- chat/rag metrics 中
rag_config_template.resolver_debug会记录:strategyepsilondecision(explore/exploit/weighted)chosen_variantreward_snapshot
建议 rollout:
- 先用
weighted收集稳定反馈。 - 再小流量启用
adaptive,并从epsilon=0.05~0.1起步。 - 持续观察
resolver_debug.decision与线上效果,防止 reward 偏差放大。
If you want to strongly reduce hallucinations (at the cost of more refusals and potentially buffered streaming), enable visible-evidence-only mode:
- Per-request (recommended for QA/critical workflows):
rag_config.visible_evidence_only=true
- Per-dataset default:
- set dataset
rag_defaults.visible_evidence_only=true
- set dataset
When enabled, MimirQ will:
- Abstain early when evidence is weak/empty (instead of "best effort" guessing)
- Post-check generated claims against the retrieved evidence and drop unsupported ones
- Apply the same scrubbing to structured_output JSON (keeps JSON parseable)
Claim verifier diagnostics now expose machine-readable removal reasons:
reason_codesupportedoverlap_insufficientcontradiction_numeric_mismatchcontradiction_negation_conflictnli_entailment/nli_contradiction/nli_neutralwhen optional NLI fallback is enabled
contradiction_typenumeric_mismatchnegation_conflictnumeric_and_negation
Operationally:
- Keep
RAG_CLAIM_VERIFIER_MODE=token_overlapas the cheapest baseline. - Move to
semantic_heuristicwhen you need better numeric/negation protection. - Use
strictonly when evidence spans and parser quality are already stable. - Enable
RAG_CLAIM_NLI_VERIFIER_ENABLED=trueonly as a bounded fallback layer after heuristic failure, not as the primary verifier.
Wave D adds a strict grounding retrieval profile:
rag_config.retrieval_profile=grounded_strict
grounded_strict applies the following contract together:
retrieval_mode=hybridtop_k>=20enable_reranker=true; the provider follows the deployment'sRERANKER_PROVIDERand falls back tocross_encoderretrieval_contract_mode=evidence_strictvisible_evidence_only=true
Rollout recommendation:
- Start with one dataset that has stable citations and good parse quality.
- Observe
abstain_rate,claim_check_removed, andevidence_span_missing_citationsfor 24-48 hours. - If refusal rate spikes because of span gaps, prioritize parser/chunking remediation before expanding rollout.
- Keep a rollback switch by reverting dataset default to
hybrid_ce(or clearingretrieval_profile).
MimirQ includes RAGAS evaluation and regression helpers. See:
docs/guides/regression_gate.md
You can restrict retrieval using metadata_filter (chat request rag_config.metadata_filter).
Use cases:
- Filter by page ranges (
page >= 10) - Filter by document/user tags (
document_user.tags in [...]) - Filter by frontmatter fields (
document_frontmatter.author contains "alice")
Examples:
{
"page": { "$gte": 10, "$lte": 20 },
"document_user.tags": { "$in": ["it", "hr"] }
}Notes:
- Filter keys support dotted paths (e.g.
document_user.tags). - Operators are fail-closed: unknown operators will not match.
When debugging quality issues, prefer using the trace/metrics pipeline instead of ad-hoc prints.
Key settings:
ENABLE_METRICS_LOG=trueMETRICS_LOG_PATH=./logs/rag_metrics.jsonlMETRICS_LOG_INCLUDE_TEXT=false(recommended: keeps correlation hashes instead of raw question/query)
Common workflow:
- Reproduce the bad answer
- Inspect the RAG trace (History/Graph UI) to see retrieval mode, timings, citations and refusal reasons
- If needed: export feedback → regression case, then gate future changes with the regression suite