|
|
@@ -3387,3 +3387,83 @@ TEST_F(ApiFixture, IncrementNeedsTheUpdateGrant) {
|
|
|
EXPECT_EQ(nlohmann::json::parse(allowed->body)["values"]["calls"], 2);
|
|
|
db_->client().remove(keysColl_, writer.id);
|
|
|
}
|
|
|
+
|
|
|
+// --- the 2.14.0 server-side filtered search ---------------------------------
|
|
|
+
|
|
|
+TEST_F(ApiFixture, AFilteredSearchUSESTheServerSidePathAndIsExact) {
|
|
|
+ // Proves the new path actually RAN rather than inferring it from the
|
|
|
+ // server's version. `scanned` is the discriminator: the candidate walk
|
|
|
+ // always reports at least its first pass (>= 64), while the server-side
|
|
|
+ // filtered search does no walk at all and reports 0. Without this the
|
|
|
+ // suite would pass identically on the emulation and I would have tested
|
|
|
+ // nothing about the new code.
|
|
|
+ auto c = admin();
|
|
|
+ const std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(),
|
|
|
+ nlohmann::json{{"name","vfilt"},{"kind","vector"},
|
|
|
+ {"vector_dimension",4}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ const std::string vecs = base + "/vfilt/vectors";
|
|
|
+ // Distinct vectors so the ranking is a strict order, and a filter that
|
|
|
+ // selects a minority - the shape where the emulation had to walk.
|
|
|
+ for (int i = 0; i < 12; ++i)
|
|
|
+ ASSERT_EQ(c.Post(vecs.c_str(),
|
|
|
+ nlohmann::json{{"vector",{1.0 - i * 0.05, 0.1, 0.2, 0.3}},
|
|
|
+ {"metadata",{{"dept", i % 4 == 0 ? "webber" : "other"},
|
|
|
+ {"n", i}}}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+
|
|
|
+ auto r = c.Post((base + "/vfilt/search").c_str(),
|
|
|
+ nlohmann::json{{"query_vector",{1.0,0.1,0.2,0.3}},
|
|
|
+ {"top_k",3},
|
|
|
+ {"min_score",-1.0},
|
|
|
+ {"filters",{"dept:eq:webber"}}}.dump(), "application/json");
|
|
|
+ ASSERT_TRUE(r); ASSERT_EQ(r->status, 200) << r->body;
|
|
|
+ const auto j = nlohmann::json::parse(r->body);
|
|
|
+
|
|
|
+ // 0 = no walk happened, which on the server-side path is literally true
|
|
|
+ // rather than a sentinel. A non-zero value here means the emulation ran.
|
|
|
+ EXPECT_EQ(j.at("scanned"), 0) << "the candidate walk ran, so the 2.14.0 path did NOT: "
|
|
|
+ << j.dump();
|
|
|
+ // EXPLICITLY present and false, never omitted: a consumer renders an
|
|
|
+ // absent value as "completeness unknown", which would be false here.
|
|
|
+ ASSERT_TRUE(j.contains("scan_capped")) << j.dump();
|
|
|
+ EXPECT_FALSE(j.at("scan_capped").get<bool>()) << j.dump();
|
|
|
+
|
|
|
+ // And the answer is right: every hit matches the filter, and they are the
|
|
|
+ // three highest-scoring matching rows in descending order.
|
|
|
+ const auto& hits = j.at("results");
|
|
|
+ ASSERT_EQ(hits.size(), 3u) << j.dump();
|
|
|
+ double previous = 2.0;
|
|
|
+ for (const auto& h : hits) {
|
|
|
+ EXPECT_EQ(h.at("data").at("dept"), "webber") << "a non-matching row was returned: "
|
|
|
+ << h.dump();
|
|
|
+ const double score = h.at("score").get<double>();
|
|
|
+ EXPECT_LE(score, previous) << "not in descending score order: " << hits.dump();
|
|
|
+ previous = score;
|
|
|
+ }
|
|
|
+ // The matching rows are n = 0, 4 and 8, and the query favours the lowest n.
|
|
|
+ EXPECT_EQ(hits.at(0).at("data").at("n"), 0) << hits.dump();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(ApiFixture, AFilterMatchingNothingIsAnEmptyResultNotAnError) {
|
|
|
+ auto c = admin();
|
|
|
+ const std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(),
|
|
|
+ nlohmann::json{{"name","vnone"},{"kind","vector"},
|
|
|
+ {"vector_dimension",4}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ ASSERT_EQ(c.Post((base + "/vnone/vectors").c_str(),
|
|
|
+ nlohmann::json{{"vector",{1.0,0.0,0.0,0.0}},
|
|
|
+ {"metadata",{{"dept","other"}}}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ auto r = c.Post((base + "/vnone/search").c_str(),
|
|
|
+ nlohmann::json{{"query_vector",{1.0,0.0,0.0,0.0}},
|
|
|
+ {"top_k",5},
|
|
|
+ {"filters",{"dept:eq:nosuchvalue"}}}.dump(),
|
|
|
+ "application/json");
|
|
|
+ ASSERT_TRUE(r); ASSERT_EQ(r->status, 200) << r->body;
|
|
|
+ const auto j = nlohmann::json::parse(r->body);
|
|
|
+ EXPECT_TRUE(j.at("results").empty()) << j.dump();
|
|
|
+ EXPECT_FALSE(j.at("scan_capped").get<bool>()) << j.dump();
|
|
|
+}
|