Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Handle vector value being null.

Kishore Nallan44186611ae71
diff --git a/src/index.cpp b/src/index.cpp
index 1e60a32d..e742003c 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -951,7 +951,7 @@ void Index::index_field_in_memory(const field& afield, std::vector<index_record>
size_t batch_counter = 0;
while(batch_counter < batch_len) {
auto& record = records[result_index + batch_counter];
- if(record.doc.count(afield.name) == 0) {
+ if(record.doc.count(afield.name) == 0 || !record.indexed.ok()) {
batch_counter++;
continue;
}
diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp
index 68372ac7..59bef26f 100644
--- a/test/collection_vector_search_test.cpp
+++ b/test/collection_vector_search_test.cpp
@@ -559,3 +559,37 @@ TEST_F(CollectionVectorTest, VectorSearchTestDeletion) {
ASSERT_EQ(1014, coll1->_get_index()->_get_vector_index().at("vec")->vecdex->getCurrentElementCount());
ASSERT_EQ(0, coll1->_get_index()->_get_vector_index().at("vec")->vecdex->getDeletedCount());
}
+
+TEST_F(CollectionVectorTest, VectorWithNullValue) {
+ nlohmann::json schema = R"({
+ "name": "coll1",
+ "fields": [
+ {"name": "vec", "type": "float[]", "num_dim": 4}
+ ]
+ })"_json;
+
+ Collection* coll1 = collectionManager.create_collection(schema).get();
+
+ std::vector<std::string> json_lines;
+
+ nlohmann::json doc;
+
+ doc["id"] = "0";
+ doc["vec"] = {0.1, 0.2, 0.3, 0.4};
+ json_lines.push_back(doc.dump());
+
+
+ doc["id"] = "1";
+ doc["vec"] = nullptr;
+ json_lines.push_back(doc.dump());
+
+ auto res = coll1->add_many(json_lines, doc);
+
+ ASSERT_FALSE(res["success"].get<bool>());
+ ASSERT_EQ(1, res["num_imported"].get<size_t>());
+
+ ASSERT_TRUE(nlohmann::json::parse(json_lines[0])["success"].get<bool>());
+ ASSERT_FALSE(nlohmann::json::parse(json_lines[1])["success"].get<bool>());
+ ASSERT_EQ("Field `vec` must be an array.",
+ nlohmann::json::parse(json_lines[1])["error"].get<std::string>());
+}