Skip to content

fix(weaviate): 保留关键词检索的 BM25 分数 - #6214

Open
Shinku-Chen wants to merge 1 commit into
Tencent:mainfrom
Shinku-Chen:fix/weaviate-bm25-score
Open

Shinku-Chen wants to merge 1 commit into
Tencent:mainfrom
Shinku-Chen:fix/weaviate-bm25-score

Conversation

@Shinku-Chen

@Shinku-Chen Shinku-Chen commented Nov 30, 2026 •

Copy link
Copy Markdown

Description

Problem

Weaviate's GraphQL keyword search returns _additional.score as a string. The adapter used to leave these hits at zero and assign a constant 1.0 to scores that arrived as JSON numbers. This discarded the BM25 ordering used by keyword-only searches and by the keyword side of rank fusion.

Change

Parse string and numeric scores and pass through the original finite value. Missing, malformed, and non-finite scores keep the zero fallback. Vector certainty still uses the existing cosine conversion. This is a query-time change and works with existing collections.

#5671 is migrating the transport to gRPC. If it lands later, its score handling should also preserve the BM25 value carried by the response.

Impact

  • Keyword-only retrieval keeps the original BM25 order instead of collapsing every hit into ties.
  • Hybrid retrieval feeds the real keyword scores into the existing rank fusion.
  • No reindex, schema change, or collection migration is required.
  • Vector score handling is unchanged.

Limitations

  • The fix covers the Weaviate GraphQL adapter. The gRPC migration in feat(weaviate): migrate to weaviate-go-client v6 #5671 is still open and must preserve the BM25 value separately.
  • Validation is scoped to the adapter and fusion tests. Full-repository checks were not run for this change.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

Fixes #6213.

Testing

  • The new regression test fails on the old code with scores 0 and 1 and passes with the original values 9.205988 and 2.5. It also covers zero, missing, null, malformed, and non-finite scores.
  • go test -count=1 ./internal/application/repository/retriever/weaviate
  • go test -count=1 ./internal/application/service -run 'TestFuseOrDeduplicate_'
  • golangci-lint run --new-from-rev=upstream/main ./internal/application/repository/retriever/weaviate (v2.12.2, 0 issues)

Validation was scoped to the adapter and fusion tests.

  • GitHub checks on ac4d9dc2: the Tencent open-source scan passed; App and Go Lint are action_required (awaiting approval for the fork PR).

Checklist

  • git diff --check upstream/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes for the changed Go package
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.)
  • Breaking changes are clearly called out in the description above

Screenshots / Recordings

N/A. Backend scoring only.

Assisted-by: Cindy (https://cindy.app)

Preserve finite BM25 scores returned as strings or JSON numbers so
keyword sorting and rank fusion can use their original order.

Refs: Tencent#6213
Assisted-by: Cindy (https://cindy.app)

This branch has not been deployed

No deployments
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.

fix(weaviate): 保留关键词检索的 BM25 分数

1 participant