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

Add assert for `.flat`

ozanarmagan88f53c7f32d7
diff --git a/src/validator.cpp b/src/validator.cpp
index 4f3df1aa..b18af4f1 100644
--- a/src/validator.cpp
+++ b/src/validator.cpp
@@ -53,9 +53,9 @@ Option<uint32_t> validator_t::coerce_element(const field& a_field, nlohmann::jso
}
} else if(a_field.is_array()) {
if(!doc_ele.is_array()) {
- bool is_embedding_field = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
+ bool is_auto_embedding = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
if((a_field.optional && (dirty_values == DIRTY_VALUES::DROP ||
- dirty_values == DIRTY_VALUES::COERCE_OR_DROP)) || is_embedding_field) {
+ dirty_values == DIRTY_VALUES::COERCE_OR_DROP)) || is_auto_embedding) {
document.erase(field_name);
return Option<uint32_t>(200);
} else {
@@ -631,9 +631,9 @@ Option<uint32_t> validator_t::validate_index_in_memory(nlohmann::json& document,
continue;
}
- bool is_embedding_field = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
+ bool is_auto_embedding = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
- if(document.count(field_name) == 0 && !is_embedding_field) {
+ if(document.count(field_name) == 0 && !is_auto_embedding) {
return Option<>(400, "Field `" + field_name + "` has been declared in the schema, "
"but is not found in the document.");
}
diff --git a/test/collection_schema_change_test.cpp b/test/collection_schema_change_test.cpp
index 858818fc..7e454860 100644
--- a/test/collection_schema_change_test.cpp
+++ b/test/collection_schema_change_test.cpp
@@ -1799,8 +1799,10 @@ TEST_F(CollectionSchemaChangeTest, EmbeddingFieldAlterUpdateOldDocs) {
nlohmann::json schema = R"({
"name": "objects",
"fields": [
- {"name": "title", "type": "string"}
- ]
+ {"name": "title", "type": "string"},
+ {"name": "nested", "type": "object"}
+ ],
+ "enable_nested_fields": true
})"_json;
TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
@@ -1811,6 +1813,8 @@ TEST_F(CollectionSchemaChangeTest, EmbeddingFieldAlterUpdateOldDocs) {
nlohmann::json doc;
doc["title"] = "hello";
+ doc["nested"] = nlohmann::json::object();
+ doc["nested"]["hello"] = "world";
auto add_op = coll->add(doc.dump());
ASSERT_TRUE(add_op.ok());
@@ -1828,4 +1832,7 @@ TEST_F(CollectionSchemaChangeTest, EmbeddingFieldAlterUpdateOldDocs) {
ASSERT_EQ(1, search_res.get()["found"].get<size_t>());
ASSERT_EQ(384, search_res.get()["hits"][0]["document"]["embedding"].get<std::vector<float>>().size());
+ ASSERT_EQ(1, search_res.get()["hits"][0]["document"]["nested"].size());
+ ASSERT_EQ(0, search_res.get()["hits"][0]["document"].count(".flat"));
+ ASSERT_EQ(0, search_res.get()["hits"][0]["document"].count("nested.hello"));
}