Skip to content

fix(rag): normalize Milvus L2 retrieval scores - #3070

Open
liugy789 wants to merge 1 commit into
agentscope-ai:mainfrom
liugy789:fix/milvus-l2-score-normalization
Open

fix(rag): normalize Milvus L2 retrieval scores#3070
liugy789 wants to merge 1 commit into
agentscope-ai:mainfrom
liugy789:fix/milvus-l2-score-normalization

Conversation

@liugy789

@liugy789 liugy789 commented Sep 9, 2026

Copy link
Copy Markdown

Summary

  • Pass the configured metric type to the Milvus SearchReq.
  • Normalize L2 distances into higher-is-better scores.
  • Apply scoreThreshold after score normalization.
  • Add regression tests for score conversion, metric propagation, and thresholding.

Why

Milvus L2 search returns distances where smaller values indicate greater similarity. AgentScope retrieval uses a higher-is-better score contract, so raw L2 distances must be adapted before they are exposed as document scores.

This PR uses 1 / (1 + distance) as an AgentScope-side normalization formula. This formula is not a Milvus-defined conversion.

Validation

  • MilvusStoreTest: 65 tests passed.
  • RAG simple module: 449 tests passed.
  • Spotless check passed.
  • git diff --check passed.

References

Fixes #3069

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

LGTM

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.

[Bug] MilvusStore returns inverted scores for the L2 metric

2 participants