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

Fix extracting field names for two embedding fields with same prefix

ozanarmagana97612776773
diff --git a/src/collection.cpp b/src/collection.cpp
index 9140e8bb..28907b33 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -1044,6 +1044,10 @@ Option<bool> Collection::extract_field_name(const std::string& field_name,
continue;
}
+ if(!exact_key_match && text_embedding) {
+ continue;
+ }
+
if (exact_primitive_match || is_wildcard || text_embedding ||
// field_name prefix must be followed by a "." to indicate an object search
(enable_nested_fields && kv.key().size() > field_name.size() && kv.key()[field_name.size()] == '.')) {
diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp
index f000209a..cacfb978 100644
--- a/test/collection_vector_search_test.cpp
+++ b/test/collection_vector_search_test.cpp
@@ -2018,5 +2018,63 @@ TEST_F(CollectionVectorTest, TestMultilingualE5) {
1, FREQUENCY, {true},
0, spp::sparse_hash_set<std::string>());
+ ASSERT_TRUE(semantic_results.ok());
+}
+
+
+TEST_F(CollectionVectorTest, TestTwoEmbeddingFieldsSamePrefix) {
+ nlohmann::json schema = R"({
+ "name": "docs",
+ "fields": [
+ {
+ "name": "title",
+ "type": "string"
+ },
+ {
+ "name": "embedding",
+ "type": "float[]",
+ "embed": {
+ "from": [
+ "title"
+ ],
+ "model_config": {
+ "model_name": "ts/e5-small"
+ }
+ }
+ },
+ {
+ "name": "embedding_en",
+ "type": "float[]",
+ "embed": {
+ "from": [
+ "title"
+ ],
+ "model_config": {
+ "model_name": "ts/e5-small"
+ }
+ }
+ }
+ ]
+ })"_json;
+
+ TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
+
+ auto collection_create_op = collectionManager.create_collection(schema);
+
+ ASSERT_TRUE(collection_create_op.ok());
+
+ auto coll1 = collection_create_op.get();
+
+ auto add_op = coll1->add(R"({
+ "title": "john doe"
+ })"_json.dump());
+
+ ASSERT_TRUE(add_op.ok());
+
+ auto semantic_results = coll1->search("john", {"embedding"},
+ "", {}, {}, {2}, 10,
+ 1, FREQUENCY, {true},
+ 0, spp::sparse_hash_set<std::string>());
+
ASSERT_TRUE(semantic_results.ok());
}
\ No newline at end of file