|
|
@@ -3467,3 +3467,60 @@ TEST_F(ApiFixture, AFilterMatchingNothingIsAnEmptyResultNotAnError) {
|
|
|
EXPECT_TRUE(j.at("results").empty()) << j.dump();
|
|
|
EXPECT_FALSE(j.at("scan_capped").get<bool>()) << j.dump();
|
|
|
}
|
|
|
+
|
|
|
+TEST_F(ApiFixture, ADocumentInsertedWithAPlainVectorFieldMustBeFINDABLE) {
|
|
|
+ // The vector_missing guard accepts EITHER `_vector` or `vector`, but the
|
|
|
+ // documents route stores the body verbatim while a search reads `_vector`.
|
|
|
+ // So `vector` may satisfy a guard whose entire purpose is to prevent a row
|
|
|
+ // that "can never be found by a search" - which would be the exact junk
|
|
|
+ // row it was written to refuse, admitted by the guard itself.
|
|
|
+ //
|
|
|
+ // Raised by a consumer asking which field a RESTORE should write. This
|
|
|
+ // test answers it with the server rather than with the documentation,
|
|
|
+ // which has been wrong twice in this area.
|
|
|
+ auto c = admin();
|
|
|
+ const std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(),
|
|
|
+ nlohmann::json{{"name","vfield"},{"kind","vector"},
|
|
|
+ {"vector_dimension",4}}.dump(),
|
|
|
+ "application/json")->status, 201);
|
|
|
+ const std::string docs = base + "/vfield/documents";
|
|
|
+ const std::string search = base + "/vfield/search";
|
|
|
+ const nlohmann::json vec = {1.0, 0.0, 0.0, 0.0};
|
|
|
+
|
|
|
+ // a) the underscored spelling, which the message tells you to use
|
|
|
+ auto a = c.Post(docs.c_str(),
|
|
|
+ nlohmann::json{{"_vector",vec},{"tag","underscored"}}.dump(),
|
|
|
+ "application/json");
|
|
|
+ ASSERT_TRUE(a); ASSERT_EQ(a->status, 201) << a->body;
|
|
|
+
|
|
|
+ // b) the bare spelling must now be REFUSED. It used to be accepted with a
|
|
|
+ // 201 and then be findable by no search at all.
|
|
|
+ auto b = c.Post(docs.c_str(),
|
|
|
+ nlohmann::json{{"vector",vec},{"tag","bare"}}.dump(),
|
|
|
+ "application/json");
|
|
|
+ ASSERT_TRUE(b);
|
|
|
+ EXPECT_EQ(b->status, 422) << "a row that no search can find was accepted: " << b->body;
|
|
|
+ EXPECT_NE(b->body.find("vector_missing"), std::string::npos) << b->body;
|
|
|
+ // The message must name BOTH the fix and the rows already stored wrongly,
|
|
|
+ // because a caller who hit this has unfindable rows behind them.
|
|
|
+ EXPECT_NE(b->body.find("_vector"), std::string::npos) << b->body;
|
|
|
+ EXPECT_NE(b->body.find("rewrite"), std::string::npos) << b->body;
|
|
|
+
|
|
|
+ auto s = c.Post(search.c_str(),
|
|
|
+ nlohmann::json{{"query_vector",vec},{"top_k",10},
|
|
|
+ {"min_score",-1.0}}.dump(), "application/json");
|
|
|
+ ASSERT_TRUE(s); ASSERT_EQ(s->status, 200) << s->body;
|
|
|
+ const auto j = nlohmann::json::parse(s->body);
|
|
|
+
|
|
|
+ std::set<std::string> found;
|
|
|
+ for (const auto& h : j.at("results"))
|
|
|
+ if (h.at("data").contains("tag")) found.insert(h.at("data").at("tag").get<std::string>());
|
|
|
+
|
|
|
+ EXPECT_TRUE(found.count("underscored"))
|
|
|
+ << "a row written with _vector was not findable: " << j.dump();
|
|
|
+ // And nothing unfindable was stored, because the refusal above stopped it
|
|
|
+ // being written at all.
|
|
|
+ EXPECT_FALSE(found.count("bare")) << j.dump();
|
|
|
+ EXPECT_EQ(found.size(), 1u) << j.dump();
|
|
|
+}
|