VectorRangeQuery denormalizes an L2 threshold with the cosine formula when normalize_vector_distance=True
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
- #878 của @sarankumar1325 — đã đóng, không merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python, redis
- Lĩnh vực
- backend-api-design, databases
Hướng nghiên cứu
Read the VectorRangeQuery threshold handling and the index code that supplies field metrics; the issue notes that #838 rewrites the same method. Reproduce with the provided L2 FLAT setup, then add an L2 test comparing range results against normalized scores, including the zero threshold case. Done when L2 thresholds use the matching distance scale and cosine behavior still matches.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
With normalize_vector_distance=True, VectorRangeQuery turns the 0 to 1 threshold back into a raw distance with denorm_cosine_distance (2 - 2t) whatever the field's metric. On an L2 field the scores come back as 1 / (1 + d), so the threshold and the returned scores use two different scales.
Repro on main 8dc9085 (redis-py 8.2.0, Redis 8.4.8, Python 3.12.14): an L2 FLAT field, query vector [1, 0], six points.
$ python repro_range.py
l2: normalized score of every doc: {'a': 1.0, 'b': 0.8, 'f': 0.7353, 'c': 0.5, 'd': 0.3333, 'e': 0.1984}
threshold 0.8: returned ['a', 'b', 'f'] | scoring >= 0.8: ['a', 'b'] | raw threshold 1/t - 1: ['a', 'b']
threshold 0.3: returned ['a', 'b', 'c', 'f'] | scoring >= 0.3: ['a', 'b', 'c', 'd', 'f'] | raw threshold 1/t - 1: ['a', 'b', 'c', 'd', 'f']
At 0.8 it returns f, scored 0.7353. At 0.3 it drops d, scored 0.3333. Cosine fields match.
#298 promised the threshold is "denormalized for execution against the database to make consistent", and the review there asked that a user's threshold match the distance they get back.
The query cannot see the metric when set_distance_threshold runs. My pick: the index hands the field's metric to the query before reading params, so batch_query and a direct search(q.query, q.params) stay correct, and L2 uses 1 / t - 1, with 0 as its own case. #838 rewrites the same method and keeps the cosine call, so I'll open that fix with an L2 test on top of it once it merges, unless you'd rather fold it into #838.
repro_range.py
from redisvl.index import SearchIndex
from redisvl.query import VectorRangeQuery, VectorQuery
from redisvl.redis.utils import array_to_buffer
idx = SearchIndex.from_dict({
"index": {"name": "e2range_l2", "prefix": "e2range_l2"},
"fields": [{"name": "v", "type": "vector", "attrs": {"dims": 2, "algorithm": "flat", "distance_metric": "l2", "datatype": "float32"}},
{"name": "n", "type": "tag"}],
}, redis_url="redis://localhost:6379")
idx.create(overwrite=True, drop=True)
pts = {"a": [1.0, 0.0], "b": [1.0, 0.5], "c": [1.0, 1.0], "d": [0.0, 1.0], "e": [-1.0, 0.2], "f": [1.0, 0.6]}
idx.load([{"n": k, "v": array_to_buffer(p, "float32")} for k, p in pts.items()])
allq = VectorQuery([1.0, 0.0], "v", return_fields=["n"], num_results=10, normalize_vector_distance=True)
scored = {r["n"]: round(float(r["vector_distance"]), 4) for r in idx.query(allq)}
print("l2: normalized score of every doc:", scored)
for t in (0.8, 0.3):
q = VectorRangeQuery([1.0, 0.0], "v", return_fields=["n"], distance_threshold=t, num_results=10, normalize_vector_distance=True)
got = sorted(r["n"] for r in idx.query(q))
want = sorted(k for k, s in scored.items() if s >= t)
raw = VectorRangeQuery([1.0, 0.0], "v", return_fields=["n"], distance_threshold=1 / t - 1, num_results=10)
print(f" threshold {t}: returned {got} | scoring >= {t}: {want} | raw threshold 1/t - 1: {sorted(r['n'] for r in idx.query(raw))}")
idx.delete(drop=True)
- Ngôn ngữ chính
- Python
- Star
- 435
- Fork
- 123
- Merge trung bình
- 8 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 39
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của redis/redis-vl-python
-
SearchIndex.drop_keys does not validate cluster hash-tag co-location (inconsistent with drop_documents)Có thể đã có người làm @Hashim1999164 đã nhận 47 ngày trước. Đang mởbug good first issue index
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
redis/redis-vl-python#601 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
redis/redis-vl-python#889 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Add image embedding to the Cohere vectorizer (Embed v4 and v5)Có thể đã có người làm @rahulsjha đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
redis/redis-vl-python#888 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
redis/redis-vl-python#887 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
GoogleGenAIVectorizer.embed_many fails on gemini-embedding-2 for batches of more than one inputCó thể đã có người làm @pcbeingused33 đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
redis/redis-vl-python#886 ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của redis/redis-vl-python
Issue tương tự
-
[Resource]: SpaicelyĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
hesreallyhim/awesome-claude-code#3875 · 1 bình luận ·
-
[Bug]: Ajax Pro login issueĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
bvis/aegis-hass#725 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xCó thể đã có người làm @NimaVaziri đã nhận hôm nay. Đang mởPytorch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA/TensorRT-LLM#23406 ·
Maintainer thường phản hồi trong vòng 1 ngày