OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Feature]: Document (and optionally expose) reranking for context-mode recall — POST /search mode="context" never reaches the reranker

Open feel-think opened this issue 1 month ago • 2 comments

Issue Origin

Observed or reproduced in a real environment

Problem Statement

With a reranker configured (rerank section in ov.conf), automatic recall never reaches the reranker, because the automatic recall request is a POST /api/v1/search/search with mode="context", which resolves to the context assembler, and the assembler retrieves through find() — and find() is hard-coded to RetrieverMode.QUICK.

The documentation reads as if enabling rerank covers search as a whole:

  • /en/api/06-retrieval find vs search table: Reranking | No | Used for text queries when a reranker is configured
  • /en/configuration/01-server: result reranking is enabled only when rerank has a usable provider configuration

Neither page mentions that mode="context" never reaches the reranker. A user who enables rerank for recall-quality reasons therefore gets no benefit on the main automatic-recall path, and still pays the global side effect that the retriever's default threshold becomes rerank.threshold (default 0.1) instead of 0.

Evidence (server v0.5.0; identical in v0.4.23):

  • openviking/server/routers/search.py:492 — if request.mode == "context": → assemble_context(...)
  • openviking/retrieve/context_assembler/gather.py:287-297 — _find(...) delegates to _safe_find(service, errors, "find", ...), i.e. service.search.find(...); every assembly scope uses find / find_skills
  • openviking/storage/viking_fs/_semantic.py:306 — mode=RetrieverMode.QUICK (the find path)
  • openviking/retrieve/hierarchical_retriever.py:124-126 — use_rerank = mode == THINKING and self._rerank_client is not None and not image_query
  • openviking/retrieve/hierarchical_retriever.py:73 — self.threshold = rerank_config.threshold if rerank_config else 0
  • Client side: @openviking/dsh-memory-plugin 0.5.26, shared/recall-core.mjs:123 sends mode: "context" (byte-identical file in 0.5.16 and 0.5.26)
  • default_search_mode is documented as a deprecated compatibility field with no runtime effect, so there is no configuration path today to change the retriever mode used by context assembly.

Proposed Solution

Either part is useful on its own:

  1. Documentation: add a mode × rerank matrix to /en/api/06-retrieval (and a note in the rerank section of /en/configuration/01-server) stating explicitly that mode="list" reranks when a reranker is configured, while mode="context" (automatic recall / context assembly) does not, because it resolves to find() and find() always runs in QUICK mode. Also document the threshold side effect.

  2. Optional configuration: an opt-in that lets context-mode recall use the reranker, e.g. retrieval.apply_rerank_to_context (default false, preserving today's behavior). Users who configure a reranker could then decide whether automatic recall pays the extra rerank latency/cost.

Alternatives Considered

  • Switching automatic recall to mode="list": changes the response from a budgeted, tiered context block to a ranked hit list, so the client would have to re-implement quotas/tiering/dedup — exactly what the assembler exists for.
  • Client-side reranking: duplicates the model call and threshold semantics outside the server.
  • Documentation only (option 1) is acceptable if the behavior is intentional; the request is that the docs state it.

Feature Area

Retrieval/Search

Use Case

Self-hosted single-user deployment (OpenViking server + dsh / Claude Code memory plugins). We want better precision on the memory block that is injected into every turn. Reading the docs, enabling rerank looked like the way to get it; source inspection shows the automatic-recall path never calls the reranker. With the opt-in we can measure injected-context quality against rerank latency and cost; with the docs note we at least know not to enable it for that reason.

Example API (Optional)

{
  "rerank": { "provider": "vikingdb", "ak": "...", "sk": "...", "host": "...", "model_name": "..." },
  "retrieval": { "enable_intent": true, "apply_rerank_to_context": true }
}

Additional Context

Related issues/PRs already in the tracker:

  • #2256 (closed) — maintainer answer: this is the find/search API division, find stays quick, search reranks when configured.
  • #5450 (merged) — implements "THINKING with a usable reranker reranks; otherwise recall is limited to limit hits".
  • #5200 (open) — reports ~12.9K rerank predictions in a 24h window attributed to auto-recall traffic. Under the current code that traffic cannot come from mode="context" assembly, so it may be worth reconciling which client path produced it.

Versions checked: server 0.4.23 (installed) and 0.5.0 (current PyPI release); dsh plugin 0.5.16 (installed) and 0.5.26 (current npm release).


中文摘要:本机自托管 OV,配了 rerank 后发现「自动召回」(插件每轮注入的记忆块)完全没吃到精排。根因是自动召回打 POST /api/v1/search/search 且 mode="context",服务端在 context 分支走 assemble_context,装配内部逐 scope 调 service.search.find(...),而 find 被硬编码为 RetrieverMode.QUICK,use_rerank 因此恒为假。文档的 find/search 对照表只讲方法层,没有说明 context 模式也会落到 find,所以读者会以为配了 rerank 就能提升自动召回质量。建议二选一或都做:① 在文档里补一张 mode × 精排的对照表(并写明阈值副作用);② 给一个默认关闭的开关,让 context 模式也能选择走精排。

feel-think avatar Oct 16 '26 12:10 feel-think

Image 我会先作为 bug 处理

MaojiaSheng avatar Oct 26 '26 02:10 MaojiaSheng

Thanks for the detailed report. The root cause is as described, and the history suggests this is an unintended side effect rather than a design decision:

  • When context mode landed in #3534, the assembler already went through find(), but find() did not pin a retriever mode at the time, so with a reranker configured it ran THINKING and reranked.
  • #4472 (for #4463, find() used as file lookup taking 20–60s) pinned find() to RetrieverMode.QUICK. It only touched find() and its test; the context assembler was not mentioned, and it lost reranking as a side effect.
  • I couldn't find any issue, PR, RFC (#3372) or code comment saying context mode should skip rerank. The RFC actually states rerank is not search-only, and docs/en/api/06-retrieval.md still says "Context mode uses that final score" (which may come from rerank).

So I agree with @MaojiaSheng on treating it as a bug. I'll take the opt-in rerank for context mode. Planned shape:

  • Opt-in, default off. A retrieval.apply_rerank_to_context flag (default false), so today's latency and cost stay unchanged. find() stays QUICK; its contract is pinned by tests and other callers rely on it.
  • One rerank call per assembly, over the merged pool. Rerank the merged, deduplicated candidates after gathering and before quota allocation / token budgeting, then let the existing quota, backfill and budget logic run on the new order. Reranking the final entries would only reorder what already survived; reranking each sub-query would multiply model calls.
  • Wide enough pool. In flat mode the pool can be exactly limit, so recall widens to 2 × limit when rerank is on (same as search()). Bucketed mode already over-fetches; the rerank input is capped per bucket to keep cost bounded.
  • Skills included. Skills go through find_skills, which never reranks, and their package abstracts are currently filled only after the cut. They'll be filled before the rerank so skills are scored on real text.
  • Same safety rails as search(). Skip for image queries, fall back to vector scores on rerank failure, keep the other-peer penalty and origin tie-break on top of the new score, and report in the assembly stats whether rerank was used.

Open question for the reporter: is a server-level flag enough for your use case, or do you also need a per-request override (e.g. a context-only rerank field on POST /search)?

Two related points, which I'd keep as separate changes:

  1. Threshold coupling. A small correction: rerank.threshold leaks into the non-rerank path even without a reranker, not only once rerank is enabled. OpenVikingConfig.rerank always defaults to a RerankConfig(), so HierarchicalRetriever.threshold is effectively always 0.1, and it filters raw vector scores on the QUICK / find_skills paths whenever the caller sends no score_threshold. Tuning rerank.threshold to the reranker's score range therefore silently drops vector hits. The rerank threshold should only apply to rerank scores.
  2. Docs. The find/search table and the context-mode section should state which paths rerank (see also #6199).

@MaojiaSheng are you already covering these two? If not, I can pick them up as well.

On #5200: under current code, context-mode assembly can't produce rerank calls. One likely source is the Hermes plugin, whose default auto-recall prefetch (recall_compress="off") sends a session-aware list-mode POST /search. That is inferred from the code, not confirmed against the reporter's setup.


中文摘要:根因确认。context mode 从 #3534 起就走 find(),当时 find() 配了 reranker 会精排;#4472 为修 find() 的延迟把它固定为 QUICK,context 顺带失去精排,没有找到"context 有意不精排"的设计依据,同意按 bug 处理。我来做 context 的可选精排:默认关闭的 retrieval.apply_rerank_to_context,在候选合并去重后、配额和 token 预算裁剪前统一精排一次(flat 模式扩大召回到 2×limit,skills 先补齐摘要再精排,图片查询跳过,失败回退向量分)。阈值耦合(未精排路径也用了 rerank.threshold,且默认就是 0.1)和文档补充建议分开处理。

t0saki avatar Oct 26 '26 05:10 t0saki