Skip to content

fix: pass Infinity vector similarity weight - #17453

Merged
JinHai-CN merged 9 commits into
infiniflow:mainfrom
Hellrakk:fix/infinity-vector-similarity-weight
Aug 19, 2026
Merged

JinHai-CN merged 9 commits into
infiniflow:mainfrom
Hellrakk:fix/infinity-vector-similarity-weight

Conversation

@Hellrakk

Copy link
Copy Markdown
Contributor

Summary

  • Pass vector_similarity_weight from Python and Go retrieval requests into Infinity's weighted fusion expression.
  • Keep fusion weights ordered as text first and vector second, with the existing default vector weight of 0.3.
  • Add tests for FusionExpr construction, direct Go search propagation, top-level Go retrieval propagation, and Python retrieval propagation.

Root Cause

Infinity's fusion expression used hard-coded weights. The configured vector similarity weight was not included in the Python retrieval request and was not propagated from Go RetrievalRequest to RetrievalSearchRequest.

Tests

  • python -m pytest -q test/unit_test/rag/nlp/test_fusion.py test/unit_test/rag/test_search_fusion_weight.py
  • python -m compileall -q rag/nlp/search.py rag/nlp/fusion.py test/unit_test/rag/test_search_fusion_weight.py
  • CGO_ENABLED=0 go test ./internal/service/nlp -count=1
  • git diff --check

The Python and Go regression tests were also verified to fail when the corresponding propagation field is temporarily removed.

Scope

This PR is limited to Infinity vector similarity weight propagation. It does not include Infinity score decomposition, live end-to-end testing, or the separate weight-format precision follow-up.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Retrieval requests now propagate configurable vector similarity weights through Go and Python search paths. Fusion helpers compute complementary term and vector weights. Tests cover defaults, boundary values, backend preservation, and propagation.

Changes

Configurable fusion weighting

Layer / File(s) Summary
Fusion expression builders
internal/service/nlp/retrieval.go, rag/nlp/fusion.py, internal/service/nlp/retrieval_test.go, test/unit_test/rag/nlp/test_fusion.py
Fusion helpers create weighted_sum expressions from complementary term and vector weights. Tests cover default, boundary, midpoint, and formatted values.
Go retrieval propagation
internal/service/nlp/retrieval.go, internal/service/nlp/retrieval_test.go
Go retrieval requests carry VectorSimilarityWeight. Search applies it for Infinity and preserves Elasticsearch’s legacy "0.05,0.95" weights.
Python retrieval propagation
rag/nlp/search.py, test/unit_test/rag/test_search_fusion_weight.py
Python retrieval forwards vector_similarity_weight to search. Infinity uses the configured weight, while Elasticsearch retains "0.001,1". Tests capture both fusion paths.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Retrieval
  participant Search
  participant FusionBuilder
  participant FusionExpr
  Retrieval->>Search: forward vector similarity weight
  Search->>FusionBuilder: build engine-specific fusion expression
  FusionBuilder->>FusionExpr: create weighted_sum with term/vector weights
  FusionExpr-->>Search: return fusion expression
Loading

Possibly related PRs

  • infiniflow/ragflow#17375: Both PRs modify NLP retrieval fusion-weight handling in rag/nlp/search.py and backend-specific search logic.

Suggested labels: 🐞 bug, 🌈 python, ♾️infinity

Poem

A rabbit tunes the weights with care,
Term and vector blend in the air.
Go and Python pass the score,
Infinity opens one path more.
Tests check each measured hop,
Legacy engines keep their stop.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: passing the Infinity vector similarity weight.
Description check ✅ Passed The description includes the required summary and provides root cause, tests, scope, and excluded work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Hellrakk

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
rag/nlp/search.py (1)

211-211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Log the resolved fusion configuration.

Direct Dealer.search callers now have configurable fusion weighting but no trace of the chosen value. Add a debug log without query content.

Proposed change
-                fusionExpr = build_fusion_expr(topk, float(req.get("vector_similarity_weight", 0.3)))
+                vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
+                logging.debug(
+                    "Dealer.search fusion: topk=%s vector_similarity_weight=%s",
+                    topk,
+                    vector_similarity_weight,
+                )
+                fusionExpr = build_fusion_expr(topk, vector_similarity_weight)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/nlp/search.py` at line 211, Add a debug log immediately around the fusion
configuration in Dealer.search, recording the resolved vector similarity weight
or fusion expression without including query content. Use the existing logging
mechanism and preserve the current build_fusion_expr behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/unit_test/rag/test_search_fusion_weight.py`:
- Around line 27-74: Move the module stubbing and engine-flag mutations
currently performed at module scope into a per-test fixture that uses
monkeypatch, covering the fake rag.nlp.*, common.settings, and token utility
entries plus DOC_ENGINE_OCEANBASE and DOC_ENGINE_INFINITY. Ensure imports and
loaded-module references are configured within that fixture, and reset any
mutable mock state per test so no fake modules or Infinity settings leak into
later tests.

---

Nitpick comments:
In `@rag/nlp/search.py`:
- Line 211: Add a debug log immediately around the fusion configuration in
Dealer.search, recording the resolved vector similarity weight or fusion
expression without including query content. Use the existing logging mechanism
and preserve the current build_fusion_expr behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f6d55746-1ab7-4f37-b496-08cd53b708d5

📥 Commits

Reviewing files that changed from the base of the PR and between 3268938 and d0c0804.

📒 Files selected for processing (6)
  • internal/service/nlp/retrieval.go
  • internal/service/nlp/retrieval_test.go
  • rag/nlp/fusion.py
  • rag/nlp/search.py
  • test/unit_test/rag/nlp/test_fusion.py
  • test/unit_test/rag/test_search_fusion_weight.py

@Hellrakk

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Hellrakk
Hellrakk marked this pull request as ready for review July 28, 2026 03:25
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 28, 2026
@JinHai-CN
JinHai-CN requested a review from qinling0210 July 28, 2026 04:14
Comment thread rag/nlp/search.py Outdated
src.append(f"q_{len(q_vec)}_vec")

fusionExpr = FusionExpr("weighted_sum", topk, {"weights": "0.001,1"})
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code change should only when it is infinity. When using elasticsearch, keep the original hardcoded weights value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b66631a. Dynamic fusion weights are now applied only when DOC_ENGINE_INFINITY is enabled, while Elasticsearch keeps the original "0.001,1" weights. Added a regression test for the Elasticsearch path.

@qinling0210 qinling0210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread internal/service/nlp/retrieval.go Outdated
TopN: topk,
FusionParams: map[string]interface{}{"weights": "0.05,0.95"},
}
fusionExpr := buildInfinityFusionExpr(topk, req.VectorSimilarityWeight)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also only limit the code change to Inifnity engine in GO, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. The Go-side dynamic fusion weight is now restricted to the Infinity engine as well.

For Elasticsearch, the original hardcoded weights (0.05,0.95) are preserved. I also added regression tests covering both Infinity and Elasticsearch paths, and checked the related Go retrieval code for similar issues.

Updated in commit 2708f6b.

@Hellrakk Hellrakk changed the title [codex] fix Infinity vector similarity weight fix: pass Infinity vector similarity weight Aug 5, 2026

@qinling0210 qinling0210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@qinling0210 qinling0210 added the ci Continue Integration label Aug 5, 2026
@qinling0210

Copy link
Copy Markdown
Contributor

@Hellrakk Please solve the test failure.

@codecov

codecov Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (d02723c) to head (fa76e2d).
⚠️ Report is 54 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17453   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Hellrakk
Hellrakk force-pushed the fix/infinity-vector-similarity-weight branch from 7b3b166 to 3dfa7fb Compare August 18, 2026 02:03
@Hellrakk
Hellrakk force-pushed the fix/infinity-vector-similarity-weight branch from 3dfa7fb to 6cc027a Compare August 18, 2026 02:22
Comment thread rag/nlp/fusion.py Resolved
@qinling0210
qinling0210 self-requested a review August 18, 2026 09:37
@Hellrakk

Copy link
Copy Markdown
Contributor Author

Addressed in commit fa76e2d.

  • Moved build_fusion_expr() into rag/nlp/search.py.
  • Removed the standalone rag/nlp/fusion.py module.
  • Kept the fusion weight tests in test/unit_test/rag/test_search_fusion_weight.py.
  • Local regression: 6 passed; preflight has passed, and the full Go/Python CI matrix is still running.

@qinling0210 qinling0210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@JinHai-CN
JinHai-CN merged commit a9323ca into infiniflow:main Aug 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants