Skip to content

Commit bed1a07

Browse files
fix(local): honor lookup_from for relevance feedback (#1630)
* fix(local): honor feedback lookup_from * test(local): cover feedback lookup contracts * tests: replace local feedback lookup tests with a congruence case --------- Co-authored-by: George Panchuk <george.panchuk@qdrant.tech>
1 parent 37c9a97 commit bed1a07

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎qdrant_client/local/async_qdrant_local.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ def input_into_vector(vector_input: types.VectorInput) -> types.VectorInput:
361361
)
362362
for pair in pairs
363363
]
364+
elif isinstance(query, rest_models.RelevanceFeedbackQuery):
365+
query.relevance_feedback.target = input_into_vector(query.relevance_feedback.target)
366+
for item in query.relevance_feedback.feedback:
367+
item.example = input_into_vector(item.example)
364368
elif isinstance(query, rest_models.OrderByQuery):
365369
pass
366370
elif isinstance(query, rest_models.FusionQuery):

‎qdrant_client/local/qdrant_local.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ def input_into_vector(
397397
)
398398
for pair in pairs
399399
]
400+
elif isinstance(query, rest_models.RelevanceFeedbackQuery):
401+
query.relevance_feedback.target = input_into_vector(query.relevance_feedback.target)
402+
for item in query.relevance_feedback.feedback:
403+
item.example = input_into_vector(item.example)
400404
elif isinstance(query, rest_models.OrderByQuery):
401405
pass
402406
elif isinstance(query, rest_models.FusionQuery):

‎tests/congruence_tests/test_query.py‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,29 @@ def dense_query_lookup_from(
10621062
lookup_from=lookup_from,
10631063
)
10641064

1065+
@classmethod
1066+
def relevance_feedback_query_lookup_from(
1067+
cls, client: QdrantBase, lookup_from: models.LookupLocation
1068+
) -> models.QueryResponse:
1069+
return client.query_points(
1070+
collection_name=COLLECTION_NAME,
1071+
query=models.RelevanceFeedbackQuery(
1072+
relevance_feedback=models.RelevanceFeedbackInput(
1073+
target=1,
1074+
feedback=[
1075+
models.FeedbackItem(example=2, score=0.9),
1076+
models.FeedbackItem(example=3, score=0.1),
1077+
],
1078+
strategy=models.NaiveFeedbackStrategy(
1079+
naive=models.NaiveFeedbackStrategyParams(a=0.5, b=1.0, c=0.7)
1080+
),
1081+
)
1082+
),
1083+
using="text",
1084+
limit=10,
1085+
lookup_from=lookup_from,
1086+
)
1087+
10651088
@classmethod
10661089
def no_query_no_prefetch(cls, client: QdrantBase) -> models.QueryResponse:
10671090
return client.query_points(collection_name=COLLECTION_NAME, limit=10)
@@ -1365,13 +1388,11 @@ def test_dense_query_lookup_from_another_collection():
13651388
init_client(local_client, secondary_collection_points, SECONDARY_COLLECTION_NAME)
13661389
init_client(http_client, secondary_collection_points, SECONDARY_COLLECTION_NAME)
13671390

1368-
compare_clients_results(
1369-
local_client,
1370-
http_client,
1371-
grpc_client,
1372-
searcher.dense_query_lookup_from,
1373-
lookup_from=models.LookupLocation(collection=SECONDARY_COLLECTION_NAME, vector="text"),
1374-
)
1391+
lookup_from = models.LookupLocation(collection=SECONDARY_COLLECTION_NAME, vector="text")
1392+
for query in (searcher.dense_query_lookup_from, searcher.relevance_feedback_query_lookup_from):
1393+
compare_clients_results(
1394+
local_client, http_client, grpc_client, query, lookup_from=lookup_from
1395+
)
13751396

13761397

13771398
def test_dense_query_lookup_from_negative():

0 commit comments

Comments
 (0)