Skip to content

fix(agent): pass top_k and fix similarity weight slider behavior - #14760

Merged
KevinHuSh merged 1 commit into
infiniflow:mainfrom
yingjianzh:fix/agent-topk-similarity-slider
May 15, 2026
Merged

KevinHuSh merged 1 commit into
infiniflow:mainfrom
yingjianzh:fix/agent-topk-similarity-slider

Conversation

@yingjianzh

@yingjianzh yingjianzh commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

This PR fixes two issues in Agent Retrieval behavior and configuration UX:

  1. top_k configured in Agent Retrieval was not passed down to the backend retriever call, so retrieval could ignore the configured vector recall limit.
  2. Similarity weight slider semantics were confusing in Agent forms because the Agent field stores keywords_similarity_weight while UI interactions were interpreted as vector weight. This could cause displayed values and actual behavior to diverge.

This PR ensures Agent retrieval uses configured top_k, and makes the slider behavior consistent and explicit for both vector and keyword weight modes.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 11, 2026
@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR refactors the SimilaritySliderFormField component to accept an explicit similarityWeightType prop instead of inferring behavior from field names, adds weight normalization helpers for consistent display-to-storage mapping, updates all call sites to use the new API, and integrates the top_k parameter into the retriever invocation.

Changes

Similarity Weight Type Refactor & Retriever Integration

Layer / File(s) Summary
Component Prop Contract
web/src/components/similarity-slider/index.tsx
SimilaritySliderFormFieldProps renamed vectorSimilarityWeightName → similarityWeightName and added similarityWeightType?: 'vector' | 'keyword' to explicitly declare weight interpretation.
Weight Normalization Helpers
web/src/components/similarity-slider/index.tsx
Introduces normalizeWeight, getVectorWeight, getFullTextWeight, and getStoredWeight to transform between displayed and persisted weight values based on type.
Form Field Wiring
web/src/components/similarity-slider/index.tsx
Form control now uses similarityWeightName prop, enabling the same component to handle both vector and keyword similarity fields.
Slider & Input Display
web/src/components/similarity-slider/index.tsx
SingleFormSlider and NumberInput display transformed weights via helpers while persisting through getStoredWeight(), decoupling UI values from storage.
Component Consumer Updates
web/src/pages/agent/form/retrieval-form/next.tsx, web/src/pages/agent/form/tool-form/retrieval-form/index.tsx, web/src/pages/next-search/search-setting.tsx
All three call sites updated to pass similarityWeightName and similarityWeightType instead of vectorSimilarityWeightName.
Retriever Top-K Parameter
agent/tools/retrieval.py
Extends retriever invocation with top=self._param.top_k to enforce configured top_k limit during retrieval.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

🐞 bug

Poem

🐰 A slider reborn, with types now clear,
Vector and keyword, distinct in sphere,
Helpers transform each weight with care,
Top-k retrieves what needs to share!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the two main changes: passing top_k to the retriever and fixing similarity weight slider behavior.
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.
Description check ✅ Passed The PR description clearly explains the two bugs being fixed (top_k not passed to retriever, slider semantics confusion) and includes the required Type of change checkbox.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@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.

🧹 Nitpick comments (3)
web/src/components/similarity-slider/index.tsx (3)

53-53: 💤 Low value

Prefer useTranslation from react-i18next.

As per coding guidelines, "Prefer useTranslation from react-i18next over project-wrapped utilities like useTranslate." The existing useTranslate('knowledgeDetails') on this line is pre-existing and not introduced by this PR, but since the file is being modified, consider migrating in a follow-up for consistency with the rest of the codebase.

🤖 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 `@web/src/components/similarity-slider/index.tsx` at line 53, The file still
uses the project wrapper useTranslate; replace it with react-i18next's
useTranslation by importing useTranslation from 'react-i18next', removing the
useTranslate import, and changing the hook call from
useTranslate('knowledgeDetails') to const { t } =
useTranslation('knowledgeDetails') so the component (similarity-slider) uses the
standard translation hook and namespace; ensure any type or callsites that
referenced useTranslate are updated to use the same t function from
useTranslation.

56-62: 💤 Low value

Helper functions are simple and correctly symmetric.

The conversion is involutive (getStoredWeight and getVectorWeight are identical functions), which correctly handles both vector and keyword storage modes. Note that normalizeWeight returns a Number, so callers receive a numeric value with two-decimal precision baked in.

One nit: since normalizeWeight already rounds to two decimals via Number(weight.toFixed(2)), the explicit .toFixed(2) calls at lines 106 and 114 are redundant (they re-stringify a value that is already rounded). Not a bug, but consider:

♻️ Optional cleanup
-                        {getVectorWeight(field.value).toFixed(2)}
+                        {getVectorWeight(field.value)}
...
-                        {getFullTextWeight(field.value).toFixed(2)}
+                        {getFullTextWeight(field.value)}

Caveat: rendering Number drops trailing zeros (e.g., 0.5 instead of 0.50), so keep .toFixed(2) if you want the two-decimal visual format preserved in the UI.

🤖 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 `@web/src/components/similarity-slider/index.tsx` around lines 56 - 62, The
helper functions normalizeWeight, getVectorWeight, getFullTextWeight, and
getStoredWeight are already rounding via normalizeWeight (which uses
Number(weight.toFixed(2))), so remove redundant .toFixed(2) usage where callers
re-stringify an already-rounded value; specifically, update places that call
.toFixed(2) on values returned by normalizeWeight to just use the numeric
result, or if you require fixed two-decimal display in the UI keep the
.toFixed(2) only at the final render point rather than inside these helper
functions to avoid double stringification.

75-79: 💤 Low value

Confirm: defaultValue={0} semantics require parent form defaults.

The concern is valid: defaultValue={0} on the FormField creates a code smell. In keyword mode, a fallback of 0 would render opposite to the intended 0.7 default; in vector mode, it diverges from component defaults (0.3).

Verification confirms all five current call sites provide proper defaults via parent useForm({ defaultValues }) setup:

  • search-setting.tsx: Via formMethods.reset()
  • chat-prompt-engine.tsx: Via parent ChatSettings (vector_similarity_weight: 0.2)
  • testing-form.tsx: Via initialVectorSimilarityWeightValue (0.3)
  • tool-form/retrieval-form/index.tsx: Via useValues() with initialKeywordsSimilarityWeightValue (0.7)
  • retrieval-form/next.tsx: Via useValues() with initialKeywordsSimilarityWeightValue (0.7)

All callers are protected. However, this remains a footgun: if a future call site forgets to set defaults, the slider will silently start at an incorrect position. Consider replacing defaultValue={0} with a mode-aware constant that matches the component's actual semantics.

🤖 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 `@web/src/components/similarity-slider/index.tsx` around lines 75 - 79, The
FormField defaultValue={0} is a footgun; change it to a mode-aware constant so
the field falls back to the component's intended defaults when parents forget to
set defaults: in the SimilaritySlider component derive a fallback like const
FALLBACK_SIMILARITY = mode === 'keywords' ? 0.7 : 0.3 (or use named constants
KEYWORDS_DEFAULT_SIMILARITY and VECTOR_DEFAULT_SIMILARITY) and pass that into
the FormField's defaultValue (the FormField using form.control and
name={similarityWeightName}); keep parent-provided defaults via useForm intact
but ensure this local fallback matches the component semantics.
🤖 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.

Nitpick comments:
In `@web/src/components/similarity-slider/index.tsx`:
- Line 53: The file still uses the project wrapper useTranslate; replace it with
react-i18next's useTranslation by importing useTranslation from 'react-i18next',
removing the useTranslate import, and changing the hook call from
useTranslate('knowledgeDetails') to const { t } =
useTranslation('knowledgeDetails') so the component (similarity-slider) uses the
standard translation hook and namespace; ensure any type or callsites that
referenced useTranslate are updated to use the same t function from
useTranslation.
- Around line 56-62: The helper functions normalizeWeight, getVectorWeight,
getFullTextWeight, and getStoredWeight are already rounding via normalizeWeight
(which uses Number(weight.toFixed(2))), so remove redundant .toFixed(2) usage
where callers re-stringify an already-rounded value; specifically, update places
that call .toFixed(2) on values returned by normalizeWeight to just use the
numeric result, or if you require fixed two-decimal display in the UI keep the
.toFixed(2) only at the final render point rather than inside these helper
functions to avoid double stringification.
- Around line 75-79: The FormField defaultValue={0} is a footgun; change it to a
mode-aware constant so the field falls back to the component's intended defaults
when parents forget to set defaults: in the SimilaritySlider component derive a
fallback like const FALLBACK_SIMILARITY = mode === 'keywords' ? 0.7 : 0.3 (or
use named constants KEYWORDS_DEFAULT_SIMILARITY and VECTOR_DEFAULT_SIMILARITY)
and pass that into the FormField's defaultValue (the FormField using
form.control and name={similarityWeightName}); keep parent-provided defaults via
useForm intact but ensure this local fallback matches the component semantics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b558494c-8f61-49a6-b818-f943fc552d4e

📥 Commits

Reviewing files that changed from the base of the PR and between 08bb53b and 29609bb.

📒 Files selected for processing (5)
  • agent/tools/retrieval.py
  • web/src/components/similarity-slider/index.tsx
  • web/src/pages/agent/form/retrieval-form/next.tsx
  • web/src/pages/agent/form/tool-form/retrieval-form/index.tsx
  • web/src/pages/next-search/search-setting.tsx

@yingfeng yingfeng added the ci Continue Integration label May 13, 2026
@yingfeng
yingfeng marked this pull request as draft May 13, 2026 12:47
@yingfeng
yingfeng marked this pull request as ready for review May 13, 2026 12:47
@codecov

codecov Bot commented May 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (08bb53b) to head (29609bb).
⚠️ Report is 92 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14760   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 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.

@yingfeng
yingfeng requested a review from KevinHuSh May 15, 2026 01:48
@KevinHuSh
KevinHuSh merged commit 4c68a6b into infiniflow:main May 15, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request May 22, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants