WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Feature] Retrieval should prioritize knowledge base over web search when both are enabled

Open YG52052051 opened this issue 3 months ago • 3 comments

Current behavior

When a chat/IM session enables web search together with knowledge bases, retrieval runs both in parallel and merges results into a single ranked list (retrievalSourceMixed), with cross-source score comparison and no source priority. The classified intent (e.g. kb_search) does not gate web results.

Problem

For enterprise KB-QA scenarios this inverts expectations: for a question the KB clearly answers (e.g. "who is responsible for ops?"), SEO-optimized generic web pages routinely outrank the KB's own documents, so the bot answers from the web — or even claims it "cannot search the knowledge base" — while the correct answer exists in the KB. Users must disable web search entirely to get reliable KB answers, losing the hybrid capability.

Suggested options (any one would help)

  1. Cascade fallback: search the KB first; invoke web search only when KB top scores fall below a threshold.
  2. Source-priority weighting: when KB results pass a confidence bar, suppress or down-weight web results in the merged ranking.
  3. Intent gating: when query intent is classified as kb_search, restrict targets to KB; use web only for web_search intent.

Happy to contribute a PR once a direction is agreed.

Environment

WeKnora main @ 2026-09, IM channel (WeCom) with web_search_enabled=true on the builtin quick-answer agent; observed via pipeline logs (stage=Search ... web_enabled=true + web results ranked above KB chunks).

YG52052051 avatar Sep 02 '26 07:09 YG52052051

Living Memory should keep source, scope, freshness, and retrieval intent attached to each result, so a knowledge-base answer is not treated as interchangeable with a web hit. Proactive Execution can use a typed cascade: answer from eligible KB evidence first, fall back to web only when the threshold is unmet, and show the source decision plus re-check condition. That preserves hybrid search without silently widening authority. Maker note: Klik is pre-launch, exploring Living Memory and approval-aware Proactive Execution: https://pre.hiklik.ai/?utm_source=github&utm_medium=issue_comment&utm_campaign=retrieval_provenance&utm_content=weknora_source_priority_20260902

chengyixu avatar Sep 02 '26 07:09 chengyixu

Hi @YG52052051, are you currently working on this issue? If not, I’d be happy to take it.

My preferred approach is option 1, a KB-first cascade: search the knowledge base first and invoke web search only when KB evidence is insufficient. I’ll keep the change backward-compatible and add regression tests for KB-hit, KB-miss, and mixed-source cases.

Maintainers, would this direction be acceptable?

bigdu332 avatar Sep 27 '26 15:09 bigdu332

@/tmp/draft-comment-2984.md

vicfei avatar Nov 03 '26 07:11 vicfei