Skip to content

Feat/rag hybrid retrieval - #11

Merged
Akaliup merged 3 commits into
masterfrom
feat/rag-hybrid-retrieval
Nov 2, 2026
Merged

Akaliup merged 3 commits into
masterfrom
feat/rag-hybrid-retrieval

Conversation

@Akaliup

@Akaliup Akaliup commented Nov 2, 2026

Copy link
Copy Markdown
Owner

变更摘要

关联任务

实际验证

请只勾选实际执行过的检查,并在下方粘贴关键结果。

  • python -m pytest backend/tests -q
  • npm --prefix frontend test
  • npm --prefix frontend run build
  • python scripts/smoke.py(涉及 HTTP/前端流程时)
  • docker compose config --quiet(涉及 Compose 时)
  • 真实 LLM 调用(如执行,注明次数、模型和报告路径;自动 CI 不执行)
  • 未执行项已在下文明确标注

验证结果:

<!-- 粘贴实际输出摘要,不要粘贴 API Key、token 或 .env 内容。 -->

安全与边界

  • 未提交 .env、API Key、数据库、缓存、构建产物或本机运行数据
  • 所有执行仍为 simulation,没有真实广告、采购、支付或外部系统副作用
  • 金额仍以 USD 整数美分存储和传输
  • 服务端仍决定角色,未信任客户端角色请求头
  • 审批与执行仍依赖条件更新、事务和唯一约束
  • 未在自动 CI 中调用真实 LLM

契约与文档

  • 契约变更已同步 docs/CONTRACT.md、后端测试和前端类型
  • 涉及评测的变更已同步 docs/EVALUATION.md
  • 新增限制或未验证项已写入相关文档

审查提示

请重点检查金额守恒、证据 ID 可追溯性、LLM 失败/降级可见性、审批执行幂等和敏感信息。自动审查工具的评论只是辅助,不替代人工审查。

lz and others added 3 commits November 3, 2026 04:55
- 分工写清楚:本人负责业务口径、契约、评测门禁、验收与合并决定,编码实现由 Claude Code 完成
- 删除“接管人:Claude Code(唯一主开发)”一类表述,HANDOFF 改为交付报告与验证记录
- 新增 docs/COLLABORATION.md:分工表、本人负责的判断、AI 完成的部分、质量门禁、可核对项、不主张的事
- AGENTS.md 头部声明它是给编码 Agent 的工作约定,随代码版本管理
- 修 README 已知限制里“实际 MCP Server 未实现”的过时矛盾句
- 评测入口统一:backend/evals/rag.py 改读 rag_queries.json 的 42 条固定标注(36 可回答 / 6 不可回答),一次运行同时对比 weighted 与 hybrid_rrf
- 新增指标 MRR、nDCG@5、按 keyword/paraphrase/cross_doc/unanswerable 分层、cross_doc 的 coverage@3,以及 no_rank_regression 门禁
- 新增 backend/app/bm25.py(内存 Okapi BM25,复用同一套中文 n-gram tokenizer),检索改为三路排名 + RRF(k=60)
- score 与 confidence 分离:score 是融合排名,no_answer 只由可解释的 confidence 判定(RRF 是排名量,不能当概率用)
- 只有具备排序能力的 provider 才让稠密路投票:hashing 下实测相关片段余弦为 0.0,等权投票会把正确结果平均掉
- 新增 KNOWLEDGE_MAX_PER_DOCUMENT=2,避免 top-k 被单篇 SOP 占满;新增 KNOWLEDGE_RETRIEVAL_MODE/RRF_K/BM25_K1/BM25_B
- BGE-M3 接入:Q8_0 GGUF 导入 Ollama,42 条查询 hit@1 100%、MRR 1.0000;新增 scripts/reindex_knowledge.py 就地重嵌入旧库
- 评测新增阈值校准输出(max 不可回答 / min 可回答 / 建议值):0.15 在 bge-m3 与 qwen3-embedding 下失效,分别校准到 0.42 / 0.40
- 测试与本地 .env 解耦:conftest 增加 session 级环境覆写,避免本机 embedding 配置让整套测试调用真实模型
- update retrieval description, 42-query eval results and test counts
- document knowledge reindex and hashing/weighted equivalence
- add knowledge search, no-answer, agent trace and mobile screenshots

Co-Authored-By: Claude Code <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T21:52:26.489692Z 185fa44 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Akaliup
Akaliup merged commit 8683c60 into master Nov 2, 2026
4 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 185fa44e0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/app/schemas.py
Comment on lines +292 to +295
# Interpretable per-chunk relevance used for abstention. ``score`` is the
# ranking value (RRF in hybrid mode), which is rank-based and therefore
# cannot decide whether anything relevant exists at all.
confidence: float | None = Field(default=None, ge=0, le=1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Synchronize the retrieval API contract

The default retrieval strategy and the meaning of score change here, and search responses now include confidence, retrieval_mode, and rankers, but docs/CONTRACT.md remains unchanged. It still specifies weighted ranking, abstention based on the highest score, and the old response fields. Consumers following that contract would incorrectly interpret the normalized RRF score as relevance confidence. Update the contract alongside the implementation; AGENTS.md explicitly requires contract changes to be synchronized with docs/CONTRACT.md, backend tests, and frontend types.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

Comment thread backend/evals/rag.py
Comment on lines +252 to +254
probe = search_knowledge(
session,
KnowledgeSearchInput(query=query["query"], top_k=1),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the retrieval window in calibration probes

When a query is rejected, the calibration probe changes top_k to 1 even though production abstention uses the maximum confidence across all selected hits. RRF order is not confidence order: the committed BGE-M3 report already shows fulfillment-04 with confidences [0.4978, 0.4941, 0.5038]. At a threshold above 0.5038, this probe would record 0.4978 instead of the actual decision statistic, making the reported separation and suggested threshold unreliable. Re-run with the original top_k and only disable abstention.

Useful? React with 👍 / 👎.

Comment thread backend/evals/rag.py
Comment on lines +402 to +403
"mode": "offline_retrieval_evaluation",
"network_calls": 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record network usage for remote embedding evaluations

With the newly supported --embedding-provider openai option, corpus seeding, query retrieval, and calibration probes call the configured HTTP embedding endpoint, but the generated report still unconditionally declares network_calls: 0 and labels the run offline. This is already present in the committed BGE-M3 and Qwen3 reports, so the evaluation artifacts misrepresent how their results were obtained. Track the actual remote embedding calls, including the connectivity check, and distinguish remote-provider runs from the offline hashing baseline.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant