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

Use fields index directly during looping.

Kishore Nallan4b6ec9741739
diff --git a/src/field.cpp b/src/field.cpp
index 7d5e399c..3c4d2e1c 100644
--- a/src/field.cpp
+++ b/src/field.cpp
@@ -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);
}
}
diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp
index 02bef6ff..694e501f 100644
--- a/test/collection_vector_search_test.cpp
+++ b/test/collection_vector_search_test.cpp
@@ -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",