fix: support distance-based score filtering in retrieve tool#443
fix: support distance-based score filtering in retrieve tool#443kaiisfree wants to merge 1 commit into
Conversation
The filter_results_by_score function assumed scores are similarity metrics (higher = more relevant), but vector stores using cosine distance return lower scores for better matches. This adds a score_metric parameter to control filtering direction. Fixes strands-agents#417 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@kaiisfree thanks for the PR and for looking at this. The only issue I see with your solution is that it relies on the LLM reasoning about whether it's a similarity or not since the similarity parameter is exposed in the tool description. I would prefer it if the similarity/distance could be determined programmatically beforehand by the developer so that the LLM doesn't have to "understand" it as much and will either get a similarity or distance version of the tool. What do you think? I'm not sure how to achieve this, honestly. |
|
/strands |
Summary
score_metricparameter ("similarity"|"distance", default"similarity") to the retrieve toolscore_metric="distance", inverts the filter comparison (<=instead of>=) so lower scores (closer matches) are keptFixes #417
Root Cause
filter_results_by_scoreunconditionally uses>= min_score, which inverts filtering when the backing vector store returns cosine distance (0 = exact match) instead of cosine similarity (1 = exact match).Changes
score_metricenum parameter to TOOL_SPECfilter_results_by_scoreto respect metric typeTest plan
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com