Skip to content

fix(agent): use the keyword weight in the agentic search tools - #21777

Open
BlueX888 wants to merge 1 commit into
infiniflow:mainfrom
BlueX888:fix/agentic-search-keyword-weight
Open

BlueX888 wants to merge 1 commit into
infiniflow:mainfrom
BlueX888:fix/agentic-search-keyword-weight

Conversation

@BlueX888

Copy link
Copy Markdown

Summary

The three agentic search tools pass their mode weight into RetrievalRequest.KeywordsSimilarityWeight. That field is the keyword share of the hybrid fusion: nlpRequestFromRetrieval derives the vector share as 1 - weight, requests the dense leg alone when the keyword share is zero, and drops the embedding model when it is one. The numbers in NewAgenticSearchTool match the Python tools' vector_similarity_weight values (1.0 for vector_search, 0 for bm25_search, 0.3 for hybrid), i.e. the vector share, so all three modes were inverted:

  • vector_search used keyword weight 1.0: the embedding model was removed, so the "vector" tool ran keyword-only.
  • bm25_search used keyword weight 0.0: the request became VectorOnly, so the "BM25" tool ran dense-only.
  • hybrid_search used keyword weight 0.3: 30% keyword / 70% vector, the inverse of Python's 30% vector / 70% keyword.

This restores the keyword shares: hybrid_search 0.7, vector_search 0.0, bm25_search 1.0. The hybrid value now also matches the other Go agentic call sites (search_chunks defaults to keyword weight 0.7).

Tests

Added TestAgenticSearchKeywordWeights in internal/agent/tool/agentic_search_test.go. It drives each mode through a capturing retrieval service and asserts both the requested KeywordsSimilarityWeight and the derived nlp request (VectorOnly, embedding presence, vector weight).

  • On the base commit (96ab55d), all three cases fail (0.3/1/0 vs 0.7/0/1).
  • With this change, the test passes; go test ./internal/agent/tool/ passes with the tokenizer table present.
  • go vet ./internal/agent/tool/, -count=5 and -shuffle=on are clean.

Notes

Found while reading the agentic search path; I did not find an existing issue for it. Happy to file one if the project wants a record.

AgenticSearchTool passes its mode weight into
RetrievalRequest.KeywordsSimilarityWeight, which is the keyword share of
the fusion. The constants were copied from the Python tools, where the
same numbers were vector_similarity_weight, so all three modes ran with
the legs inverted: vector_search dropped the embedding model,
bm25_search ran dense-only, and hybrid_search used 30/70 instead of the
Python default of 70/30.

Use keyword shares 0.7, 0.0 and 1.0 for the hybrid, vector and bm25
tools, and add a regression test that asserts both the requested weight
and the derived nlp request for every mode.
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f92a2bab-18f1-4d0c-9b28-cbcac38a1e25
Commits

Reviewing files that changed from the base of the PR and between 2fc8373 and 7b7706e.

Files selected for processing: 2
  • internal/agent/tool/agentic_search.go
  • internal/agent/tool/agentic_search_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Agentic search now assigns keyword-similarity weights of 0.7 for hybrid search, 0.0 for vector search, and 1.0 for BM25 search. A test checks these weights and related NLP request settings.

Changes: Agentic search keyword weights

Layer / File(s) Summary
Mode-specific keyword weights
internal/agent/tool/agentic_search.go, internal/agent/tool/agentic_search_test.go
The constructor and weight documentation use keyword-similarity weights for each search mode. The new test checks the weights and derived request settings.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: qinling0210, yuzhichang

Merge Risk: Minimal · up to 7b770

The search-mode weights align with their intended meanings. No merge-blocking issue is identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: correcting keyword weight usage in the agentic search tools.
Description check Passed The description includes the required Summary section and clearly explains the problem, corrected weights, affected modes, tests, and validation results.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks each search mode,
And weighs the keywords on the road.
Hybrid gets seven tenths just right,
Vector none, BM25 all bright.
Tests keep each setting in its place.

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

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