Skip to content

fix(baiduvectordb): return L2 distances as higher-is-better similarities - #23737

Open
ninglinLiu wants to merge 1 commit into
run-llama:mainfrom
ninglinLiu:fix/baiduvectordb-l2-similarity
Open

ninglinLiu wants to merge 1 commit into
run-llama:mainfrom
ninglinLiu:fix/baiduvectordb-l2-similarity

Conversation

@ninglinLiu

Copy link
Copy Markdown

BaiduVectorDB.query()/aquery() passed Mochow's raw distance straight into VectorStoreQueryResult.similarities. On the store's default L2 metric that distance is lower-is-closer, so the best match got the lowest similarity and similarity cutoffs / score-based reranking ran backwards. COSINE and IP distances already grow with similarity (Baidu VDB docs).

The store now remembers the table's configured metric and maps L2 distances to 1 / (1 + distance) (same conversion mem0 adopted for its Baidu provider in mem0ai/mem0#6435); COSINE/IP values pass through unchanged. Result order is unchanged.

  • Adds mocked-table tests for L2 (closest scores highest) and COSINE/IP pass-through; the L2 test fails on main.
  • Bumps the package to 0.8.1.

Fixes #23736

AI disclosure: I used an AI assistant to help locate this and draft the change. I reviewed the diff, checked the metric semantics against Baidu's docs, and ran the package tests plus ruff check/ruff format --check locally.

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]: BaiduVectorDB returns raw L2 distances as similarities (closest match scores lowest)

1 participant