mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-02 18:22:40 +01:00
s3vectors: report the Euclidean distance, not its square (#12318)
A euclidean index answered QueryVectors with Lance's L2 distance, which is the squared Euclidean distance: [3, 4] was 25 from the origin, not 5. AWS defines the metric as the straight-line distance between the vectors. The gateway now returns its square root, so the single engine and the enterprise coordinator, which both hand back the raw Lance value, report the same distance. Ordering is unchanged. Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d6c0d728e4
commit
ff7045a4e5
3 files changed
+67
-2
No files matched your search
@@ -58,7 +58,7 @@ def test_vector_lifecycle(vectors):
|
||||
assert [h["key"] for h in hits] == ["a", "c"]
|
||||
distances = {h["key"]: h["distance"] for h in hits}
|
||||
assert distances["a"] == pytest.approx(0.0, abs=1e-6)
|
||||
assert distances["c"] == pytest.approx(0.02, abs=1e-4)
|
||||
assert distances["c"] == pytest.approx(0.02 ** 0.5, abs=1e-4)
|
||||
assert all(h["metadata"]["color"] == "red" for h in hits)
|
||||
|
||||
vectors.delete_vectors(vectorBucketName=BUCKET, indexName=INDEX, keys=["b"])
|
||||
@@ -223,6 +223,13 @@ def test_filter_arrays(vectors, index):
|
||||
assert matches({"$nin": [1, "2.5"]}) == ["flag", "scalar", "space"]
|
||||
|
||||
|
||||
def test_euclidean_distance(vectors, index):
|
||||
vectors.put_vectors(**index, vectors=[{"key": "p", "data": {"float32": [3, 4, 0, 0]}}])
|
||||
result = vectors.query_vectors(**index, queryVector={"float32": [0, 0, 0, 0]}, topK=1, returnDistance=True)
|
||||
assert result["distanceMetric"] == "euclidean"
|
||||
assert result["vectors"][0]["distance"] == pytest.approx(5.0)
|
||||
|
||||
|
||||
def test_cosine_metric(vectors):
|
||||
bucket = "cosine-" + uuid.uuid4().hex[:16]
|
||||
vectors.create_vector_bucket(vectorBucketName=bucket)
|
||||
|
||||
Reference in new issue
Block a user