Use fields index directly during looping.

This commit is contained in:
Kishore Nallan 2023-08-23 12:52:36 +05:30
parent f1cd6038ea
commit 4b6ec97417
2 changed files with 22 additions and 1 deletions

View File

@ -1094,7 +1094,7 @@ Option<bool> field::json_fields_to_fields(bool enable_nested_fields, nlohmann::j
}
if(!the_fields.empty() && !the_fields.back().embed.empty()) {
embed_json_field_indices.emplace_back(i, i);
embed_json_field_indices.emplace_back(i, the_fields.size()-1);
}
}

View File

@ -1161,6 +1161,27 @@ TEST_F(CollectionVectorTest, FreshEmplaceWithOptionalEmbeddingReferencedField) {
"or make the embedding field optional.", add_op.error());
}
TEST_F(CollectionVectorTest, EmbeddingFieldWithIdFieldPrecedingInSchema) {
auto schema = R"({
"name": "objects",
"fields": [
{"name": "id", "type": "string"},
{"name": "name", "type": "string"},
{"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "ts/e5-small"}}}
]
})"_json;
TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection* coll = op.get();
auto fs = coll->get_fields();
ASSERT_EQ(2, fs.size());
ASSERT_EQ(384, fs[1].num_dim);
}
TEST_F(CollectionVectorTest, SkipEmbeddingOpWhenValueExists) {
nlohmann::json schema = R"({
"name": "objects",