|
@@ -3056,6 +3056,83 @@ TEST_F(ApiFixture, InsertingAVectorlessDocumentIntoAVectorCollectionIsRefused) {
|
|
|
ASSERT_TRUE(del);
|
|
ASSERT_TRUE(del);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+TEST_F(ApiFixture, AWrongWidthVectorOnTheDocumentsRouteIsRefusedAsDimensionMismatch) {
|
|
|
|
|
+ // The documents route guarded the PRESENCE of `_vector` and never its
|
|
|
|
|
+ // WIDTH, while both sibling write paths guarded both. The database does
|
|
|
|
|
+ // refuse it - nothing lands silently - but it refuses as a bare
|
|
|
|
|
+ // `ErrorCode::Internal` with no `reason`, so `apiErrorFor` could only map
|
|
|
|
|
+ // it to 500 `internal`: a caller's permanent, correctable mistake reported
|
|
|
|
|
+ // as our outage, on the one class of fault where no retry can ever help.
|
|
|
|
|
+ //
|
|
|
|
|
+ // Found while answering a consumer about to write 26186 vectors into two
|
|
|
|
|
+ // freshly pinned collections, where a wrong width is baked in permanently
|
|
|
|
|
+ // and the refusal is the only thing that stops it.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ const std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
|
|
+ const std::string ct = "application/json";
|
|
|
|
|
+ ASSERT_EQ(c.Post(base.c_str(),
|
|
|
|
|
+ nlohmann::json{{"name","vwide"},{"kind","vector"},
|
|
|
|
|
+ {"vector_dimension",4}}.dump(), ct)->status, 201);
|
|
|
|
|
+
|
|
|
|
|
+ auto count = [&]() {
|
|
|
|
|
+ auto r = c.Get((base + "/vwide/documents").c_str());
|
|
|
|
|
+ if (!r || r->status != 200) return std::size_t{0};
|
|
|
|
|
+ return nlohmann::json::parse(r->body)["documents"].size();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // Too short, and too long: both are the same mistake and the same slug.
|
|
|
|
|
+ for (const auto& v : {nlohmann::json{1.0, 0.0, 0.0},
|
|
|
|
|
+ nlohmann::json{1.0, 0.0, 0.0, 0.5, 0.25}}) {
|
|
|
|
|
+ auto bad = c.Post((base + "/vwide/documents").c_str(),
|
|
|
|
|
+ nlohmann::json{{"_vector", v}, {"tag", "bad"}}.dump(), ct);
|
|
|
|
|
+ ASSERT_TRUE(bad);
|
|
|
|
|
+ EXPECT_EQ(bad->status, 422) << bad->body;
|
|
|
|
|
+ EXPECT_NE(bad->body.find("dimension_mismatch"), std::string::npos) << bad->body;
|
|
|
|
|
+ // The message must name the collection's own width, because the caller
|
|
|
|
|
+ // cannot see the pin and "wrong dimension" alone does not say what to
|
|
|
|
|
+ // send instead.
|
|
|
|
|
+ EXPECT_NE(bad->body.find("4"), std::string::npos) << bad->body;
|
|
|
|
|
+ EXPECT_EQ(count(), 0u) << "a refused insert must store nothing";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // A `_vector` that is not an array at all takes the SAME slug rather than
|
|
|
|
|
+ // its own - the remedy is identical, and two codes would send a caller
|
|
|
|
|
+ // looking for two fixes.
|
|
|
|
|
+ auto notArray = c.Post((base + "/vwide/documents").c_str(),
|
|
|
|
|
+ nlohmann::json{{"_vector", "AAAA"}}.dump(), ct);
|
|
|
|
|
+ ASSERT_TRUE(notArray);
|
|
|
|
|
+ EXPECT_EQ(notArray->status, 422) << notArray->body;
|
|
|
|
|
+ EXPECT_NE(notArray->body.find("dimension_mismatch"), std::string::npos) << notArray->body;
|
|
|
|
|
+
|
|
|
|
|
+ // THE PAIRING, without which the three assertions above would pass just as
|
|
|
|
|
+ // well against a route that refused EVERY vector: the correct width is
|
|
|
|
|
+ // still accepted, and is still findable by a SEARCH rather than merely
|
|
|
|
|
+ // stored. A guard that admits a row while leaving it unsearchable is the
|
|
|
|
|
+ // defect this whole family exists to prevent.
|
|
|
|
|
+ auto good = c.Post((base + "/vwide/documents").c_str(),
|
|
|
|
|
+ nlohmann::json{{"_vector",{1.0,0.0,0.0,0.5}},{"tag","good"}}.dump(), ct);
|
|
|
|
|
+ ASSERT_TRUE(good);
|
|
|
|
|
+ ASSERT_EQ(good->status, 201) << good->body;
|
|
|
|
|
+ EXPECT_EQ(count(), 1u);
|
|
|
|
|
+ auto found = c.Post((base + "/vwide/search").c_str(),
|
|
|
|
|
+ nlohmann::json{{"query_vector",{1.0,0.0,0.0,0.5}},{"top_k",10}}.dump(), ct);
|
|
|
|
|
+ ASSERT_TRUE(found);
|
|
|
|
|
+ ASSERT_EQ(found->status, 200) << found->body;
|
|
|
|
|
+ EXPECT_EQ(nlohmann::json::parse(found->body)["results"].size(), 1u)
|
|
|
|
|
+ << "the accepted row must be retrievable by similarity, not just by a count";
|
|
|
|
|
+
|
|
|
|
|
+ // And the sibling route still answers the SAME slug for the same fault, so
|
|
|
|
|
+ // the two cannot drift apart again.
|
|
|
|
|
+ auto viaVectors = c.Post((base + "/vwide/vectors").c_str(),
|
|
|
|
|
+ nlohmann::json{{"vector",{1.0,0.0,0.0}}}.dump(), ct);
|
|
|
|
|
+ ASSERT_TRUE(viaVectors);
|
|
|
|
|
+ EXPECT_EQ(viaVectors->status, 422) << viaVectors->body;
|
|
|
|
|
+ EXPECT_NE(viaVectors->body.find("dimension_mismatch"), std::string::npos) << viaVectors->body;
|
|
|
|
|
+
|
|
|
|
|
+ auto del = c.Delete((base + "/vwide").c_str());
|
|
|
|
|
+ ASSERT_TRUE(del);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST_F(ApiFixture, ReplacingADocumentInAVectorCollectionIsRefused) {
|
|
TEST_F(ApiFixture, ReplacingADocumentInAVectorCollectionIsRefused) {
|
|
|
auto c = admin();
|
|
auto c = admin();
|
|
|
const std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
const std::string base = "/api/v1/projects/" + project_ + "/collections";
|