Repository navigation
fix: pass Infinity vector similarity weight - #17453
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRetrieval 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. ChangesConfigurable fusion weighting
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
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
rag/nlp/search.py (1)
211-211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLog the resolved fusion configuration.
Direct
Dealer.searchcallers 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
📒 Files selected for processing (6)
internal/service/nlp/retrieval.gointernal/service/nlp/retrieval_test.gorag/nlp/fusion.pyrag/nlp/search.pytest/unit_test/rag/nlp/test_fusion.pytest/unit_test/rag/test_search_fusion_weight.py
|
@coderabbitai review |
✅ Action performedReview finished.
|
| 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)) |
There was a problem hiding this comment.
The code change should only when it is infinity. When using elasticsearch, keep the original hardcoded weights value.
There was a problem hiding this comment.
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.
| TopN: topk, | ||
| FusionParams: map[string]interface{}{"weights": "0.05,0.95"}, | ||
| } | ||
| fusionExpr := buildInfinityFusionExpr(topk, req.VectorSimilarityWeight) |
There was a problem hiding this comment.
We should also only limit the code change to Inifnity engine in GO, right?
There was a problem hiding this comment.
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 Please solve the test failure. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
7b3b166 to
3dfa7fb
Compare
3dfa7fb to
6cc027a
Compare
|
Addressed in commit fa76e2d.
|
Summary
vector_similarity_weightfrom Python and Go retrieval requests into Infinity's weighted fusion expression.0.3.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
RetrievalRequesttoRetrievalSearchRequest.Tests
python -m pytest -q test/unit_test/rag/nlp/test_fusion.py test/unit_test/rag/test_search_fusion_weight.pypython -m compileall -q rag/nlp/search.py rag/nlp/fusion.py test/unit_test/rag/test_search_fusion_weight.pyCGO_ENABLED=0 go test ./internal/service/nlp -count=1git diff --checkThe 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.