查询在文档中记录的等价边界处返回零排名
def call(method, path, **kwargs): response = requests.request( method, BASE + path, timeout=30, **kwargs, ) response.raise_for_status() return response.json() if response.content else {}
def dot(left, right): return sum(a * b for a, b in zip(left, right))
def sigmoid(value): return 0.5 * (1.0 + value / (1.0 + abs(value)))
def expected(values): rows = []
for point_id, vector in values.items():
if point_id in (100, 101):
continue
positive = dot(values[100], vector)
negative = dot(values[101], vector)
# Documented rule: equality belongs to the positive zone.
rank = 1 if positive >= negative else -1
score = sigmoid(dot(TARGET, vector)) + rank
rows.append((point_id, score))
return sorted(rows, key=lambda row: (-row[1], row[0]))def query(): response = call( "POST", f"/collections/{COLLECTION}/points/query", json={ "query": { "discover": { "target": TARGET, "context": [ { "positive": 100, "negative": 101, } ], } }, "limit": 5, "params": { "exact": True, }, }, ) return [ (int(point["id"]), float(point["score"])) for point in response["result"]["points"] ]
def matches(actual, expected_rows): if [point_id for point_id, _ in actual] != [ point_id for point_id, _ in expected_rows …
内容来源: qdrant/qdrant