|
@@ -251,6 +251,40 @@ static int upgrade2() {
|
|
|
(void)c.createCollection("aliased", 0, true, 0, 0);
|
|
(void)c.createCollection("aliased", 0, true, 0, 0);
|
|
|
ck(c.verifyEncryption("aliased").atRestSealed,
|
|
ck(c.verifyEncryption("aliased").atRestSealed,
|
|
|
"a flag switched on over values already encrypted requests no reseal");
|
|
"a flag switched on over values already encrypted requests no reseal");
|
|
|
|
|
+ // v2.17.2 - vectors in an encrypted collection. The embedding is never
|
|
|
|
|
+ // encrypted (search compares numbers); every other value is. 2.17.0/2.17.1
|
|
|
|
|
+ // refused every insert carrying a vector into an encrypted collection.
|
|
|
|
|
+ {
|
|
|
|
|
+ ck(c.createCollection("vvec", 0, true, 0, 4), "an encrypted vector collection is created");
|
|
|
|
|
+ bool inserted = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ c.insert("vvec", {{"text", "CANARY-VEC-TEXT-5150"}, {"_vector", std::vector<float>{1, 0, 0, 0}}}, "v1");
|
|
|
|
|
+ c.insert("vvec", {{"text", "other"}, {"_vector", std::vector<float>{0, 1, 0, 0}}}, "v2");
|
|
|
|
|
+ } catch (const std::exception& e) {
|
|
|
|
|
+ inserted = false;
|
|
|
|
|
+ std::cerr << " (" << e.what() << ")\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ ck(inserted, "inserts carrying a vector into an encrypted collection are accepted");
|
|
|
|
|
+ auto hits = c.similaritySearch("vvec", {1, 0, 0, 0}, 2, -1.f);
|
|
|
|
|
+ ck(!hits.empty() && hits[0].id == "v1" && hits[0].score > 0.999f,
|
|
|
|
|
+ "similarity search on an encrypted collection finds the row at 1.0");
|
|
|
|
|
+ auto d = c.get("vvec", "v1", Client::WithVector{});
|
|
|
|
|
+ ck(d && d->value("text", "") == "CANARY-VEC-TEXT-5150" && (*d)["_vector"].is_array() &&
|
|
|
|
|
+ (*d)["_vector"].size() == 4 && (*d)["_vector"][0].get<float>() == 1.0f,
|
|
|
|
|
+ "get returns the decrypted text and the numeric vector");
|
|
|
|
|
+ // A plain vector collection switched to encrypted keeps taking vectors.
|
|
|
|
|
+ c.createCollection("vflip", 0, false, 0, 4);
|
|
|
|
|
+ c.insert("vflip", {{"text", "before"}, {"_vector", std::vector<float>{1, 0, 0, 0}}}, "a");
|
|
|
|
|
+ (void)c.createCollection("vflip", 0, true, 0, 4);
|
|
|
|
|
+ bool after = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ c.insert("vflip", {{"text", "after"}, {"_vector", std::vector<float>{0, 1, 0, 0}}}, "b");
|
|
|
|
|
+ } catch (const std::exception&) { after = false; }
|
|
|
|
|
+ auto h2 = c.similaritySearch("vflip", {0, 1, 0, 0}, 1, -1.f);
|
|
|
|
|
+ ck(after && !h2.empty() && h2[0].id == "b" && h2[0].score > 0.999f,
|
|
|
|
|
+ "after switching a vector collection to encrypted, a new vector is stored and found");
|
|
|
|
|
+ verifyClean(c, "vectors", false); // vflip's online upgrade requests a reseal
|
|
|
|
|
+ }
|
|
|
ck(!c.verifyEncryption("late").collections.empty(), "late is audited");
|
|
ck(!c.verifyEncryption("late").collections.empty(), "late is audited");
|
|
|
ck(!c.createCollection("late", 0, true, 0, 0), "createCollection on existing late returns false");
|
|
ck(!c.createCollection("late", 0, true, 0, 0), "createCollection on existing late returns false");
|
|
|
auto r = c.verifyEncryption("late");
|
|
auto r = c.verifyEncryption("late");
|