Repository navigation
fix(agent): pass top_k and fix similarity weight slider behavior - #14760
Conversation
📝 WalkthroughWalkthroughThe PR refactors the ChangesSimilarity Weight Type Refactor & Retriever Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
web/src/components/similarity-slider/index.tsx (3)
53-53: 💤 Low valuePrefer
useTranslationfromreact-i18next.As per coding guidelines, "Prefer
useTranslationfromreact-i18nextover project-wrapped utilities likeuseTranslate." The existinguseTranslate('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 valueHelper functions are simple and correctly symmetric.
The conversion is involutive (
getStoredWeightandgetVectorWeightare identical functions), which correctly handles bothvectorandkeywordstorage modes. Note thatnormalizeWeightreturns aNumber, so callers receive a numeric value with two-decimal precision baked in.One nit: since
normalizeWeightalready rounds to two decimals viaNumber(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
Numberdrops trailing zeros (e.g.,0.5instead of0.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 valueConfirm:
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: ViaformMethods.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
📒 Files selected for processing (5)
agent/tools/retrieval.pyweb/src/components/similarity-slider/index.tsxweb/src/pages/agent/form/retrieval-form/next.tsxweb/src/pages/agent/form/tool-form/retrieval-form/index.tsxweb/src/pages/next-search/search-setting.tsx
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
This PR fixes two issues in Agent Retrieval behavior and configuration UX:
top_kconfigured in Agent Retrieval was not passed down to the backend retriever call, so retrieval could ignore the configured vector recall limit.keywords_similarity_weightwhile 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