Skip to content

Commit

Permalink
Use fields index directly during looping.
Browse files Browse the repository at this point in the history
kishorenc committed Aug 23, 2023
1 parent f1cd603 commit 4b6ec97
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/field.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}

21 changes: 21 additions & 0 deletions test/collection_vector_search_test.cpp
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 4b6ec97

Please sign in to comment.