Skip to content

feat(recall): 配置化 RRF rank constant#279

Merged
jixua merged 1 commit into
devfrom
feature/link-218
Jul 4, 2026
Merged

feat(recall): 配置化 RRF rank constant#279
jixua merged 1 commit into
devfrom
feature/link-218

Conversation

@ottercoconut

Copy link
Copy Markdown
Collaborator

背景

实现 Linear LINK-218:将 RRF rank constant 从代码默认值提升为显式配置项,支持系统级 RECALL_RRF_K 与数据集级 recall_config.rrf_k,默认仍保持 60

主要改动

  • 新增系统级配置 RECALL_RRF_K=60,并校验为正整数。
  • RecallConfig 新增数据集级 rrf_k,通过 RecallRequest.rrf_k_override 覆盖 pipeline 装配期默认。
  • RecallPipeline 执行时按「数据集级 override > 系统级默认」选择有效 rrf_k,RRF 使用 1 / (rrf_k + rank) 计算贡献。
  • weighted_score 策略继续忽略 rrf_k,原有权重融合语义不变。
  • HTTP 请求体仍不开放 rrf_k,保持策略参数仅由服务端配置控制。

数据库迁移

  • 新增 Alembic migration:0031_20260701_dataset_recall_rrf_k.py
  • 本次不新增列,仅同步 dataset_parse_config.recall_config JSON 列 COMMENT,从 14 项更新为 15 项。
  • 已同步 scripts/db/init.sql 当前完整结构快照。

配置与文档同步

  • 同步 .env.example
  • 同步 docs/ops/configure.md
  • 同步 docs/api/schemas/mysql.md
  • 同步召回 pipeline、HTTP 入口、数据集配置等内部文档。

测试

已通过:

/Users/kawauso/Documents/Projects/LinkRag/.venv/bin/python -m pytest tests/unit/test_config_sparse_vector.py tests/unit/core/dataset_config/test_service.py tests/unit/application/test_recall_pipeline_provider.py tests/unit/application/test_recall_request_config.py tests/unit/api/test_recall_fusion_request_contract.py tests/unit/core/pipeline/recall/test_recall_pipeline_rrf.py tests/unit/core/pipeline/recall/test_recall_pipeline_weighted_score.py -q
# 98 passed

/Users/kawauso/Documents/Projects/LinkRag/.venv/bin/python -m pytest tests/acceptance/test_weighted_score_fusion.py -q
# 34 passed

/Users/kawauso/Documents/Projects/LinkRag/.venv/bin/python scripts/quality/check_docs_sync.py --staged
# OK

/Users/kawauso/Documents/Projects/LinkRag/.venv/bin/python scripts/quality/check_docs_facts.py --quiet
# passed

/Users/kawauso/Documents/Projects/LinkRag/.venv/bin/alembic heads
# 0031 (head)

git diff --check
# passed

补充说明:

/Users/kawauso/Documents/Projects/LinkRag/.venv/bin/python -m mypy src/config.py src/application/recall_pipeline_provider.py src/core/dataset_config/models.py src/core/pipeline/recall/models.py src/core/pipeline/recall/pipeline.py
# Success: no issues found in 5 source files

全量检查现状:

  • mypy src 仍有仓库既有类型问题,当前输出为 279 errors / 66 files,主要集中在 parser、MQ、SQLAlchemy model typing 等既有区域。
  • pytest tests/unit -q 当前为 813 passed, 4 failed;失败集中在未触及的 test_rag_stream_resilience.py producer 参数签名和 test_sparse_indexing_pipeline.py mock 签名。

已知风险

  • rrf_k 是 JSON 配置字段,数据库不做 JSON schema 约束;非法值由 Python RecallConfig / RecallPipeline 校验并向上抛出。
  • 多数据集混合召回仍沿用现有规则:取首个 dataset 的 recall_config

@jixua jixua merged commit 0f61127 into dev Jul 4, 2026
3 checks passed
Fang0415 added a commit that referenced this pull request Jul 4, 2026
dev 分支自 PR #279 合并起,migrations/versions/ 下就存在两个文件都声明
revision="0031"(0031_20260701_dataset_recall_rrf_k.py 与
0031_20260702_provider_icon_fields.py,均以 down_revision="0030" 分叉),
导致 alembic 出现两个并列 head,`alembic upgrade head` 报
"Multiple head revisions are present"——这个 CI 检查从 #279 起就一直是
失败状态,PR #289 合入 dev 时也踩了同一个坑,只是没有阻断合并。

本次修复:
- provider_icon_fields 顺延为 0032(down_revision 指向 0031 的 rrf_k)。
- chunk_type_contract 从 0032 顺延为 0033。
- 同步更新 scripts/db/init.sql 里两处过期的迁移号引用。

验证:起一个隔离的临时 mysql:8.0 容器(避免污染本地开发库),完整复现
CI 的步骤序列(导入 migrations/db.sql baseline → alembic stamp 0001 →
alembic upgrade head ×2 验证幂等 → alembic current),0001→0033 全部
迁移顺序应用成功,无报错;alembic heads 现在只有单一 0033 (head)。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

2 participants