Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(search): Add __vector_score alias #3186

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/search/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ struct BasicSearch {

// Skip sorting again for KNN queries, reverse if needed will be applied on aggregation
if (auto knn = get_if<AstKnnNode>(&node.filter->Variant());
knn && knn->score_alias == node.field) {
knn && (knn->score_alias == node.field || "__vector_score" == node.field)) {
return sub_results;
}

Expand Down
8 changes: 7 additions & 1 deletion src/server/search/search_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,14 @@ TEST_F(SearchFamilyTest, TestReturn) {
resp = Run({"ft.search", "i1", "@justA:0", "return", "1", "nothere"});
EXPECT_THAT(resp, MatchEntry("k0", "nothere", ""));

// Checl implcit __vector_score is provided
float score = 20;
resp = Run({"ft.search", "i1", "@justA:0 => [KNN 20 @vector $vector]", "SORTBY", "__vector_score",
"DESC", "RETURN", "1", "longA", "PARAMS", "2", "vector", floatsv(&score)});
EXPECT_THAT(resp, MatchEntry("k0", "longA", "0"));

// Check sort doesn't shadow knn return alias
const float score = 20;
score = 20;
resp = Run({"ft.search", "i1", "@justA:0 => [KNN 20 @vector $vector AS vec_return]", "SORTBY",
"vec_return", "DESC", "RETURN", "1", "vec_return", "PARAMS", "2", "vector",
floatsv(&score)});
Expand Down
Loading