fix: exact matches score as the worst result on Weaviate (#31531)

With Weaviate as the vector database, a chunk identical to the query (distance 0) was treated as having no distance and got a relevance score of 0. Perfect matches could land at the bottom of the results or fall below the relevance threshold. They now score 1 as expected.

Fixes #31527
This commit is contained in:
Classic298 2026-09-30 17:29:59 +02:00 • committed by GitHub
parent 52533c5675
commit 710b9f1e2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -212,7 +212,7 @@ class WeaviateClient(VectorDBBase):
# Weaviate has cosine distance, 2 (worst) -> 0 (best). Re-ordering to 0 -> 1
raw_distances = [
(obj.metadata.distance if obj.metadata and obj.metadata.distance else 2.0)
(obj.metadata.distance if obj.metadata and obj.metadata.distance is not None else 2.0)
for obj in response.objects
]
distances = [(2 - dist) / 2 for dist in raw_distances]