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 creation of multiple collections with remote embedding.

Kishore Nallan876e998cfe9e
diff --git a/src/text_embedder.cpp b/src/text_embedder.cpp
index 7e1b1b4d..cdfa5eba 100644
--- a/src/text_embedder.cpp
+++ b/src/text_embedder.cpp
@@ -56,8 +56,8 @@ TextEmbedder::TextEmbedder(const std::string& model_name) {
}
TextEmbedder::TextEmbedder(const nlohmann::json& model_config) {
- auto model_name = model_config["model_name"].get<std::string>();
- LOG(INFO) << "Initializing remote embedding model: " << model_name;
+ const std::string& model_name = model_config["model_name"].get<std::string>();
+ LOG(INFO) << "Initializing embedding model: " << model_name;
auto model_namespace = TextEmbedderManager::get_model_namespace(model_name);
if(model_namespace == "openai") {
diff --git a/src/text_embedder_manager.cpp b/src/text_embedder_manager.cpp
index 372833e3..392fc61e 100644
--- a/src/text_embedder_manager.cpp
+++ b/src/text_embedder_manager.cpp
@@ -114,11 +114,6 @@ Option<bool> TextEmbedderManager::init_text_embedder(const nlohmann::json& model
text_embedders.emplace(model_name, embedder);
}
- } else {
- auto validate_op = text_embedder_it->second->validate(num_dim);
- if(!validate_op.ok()) {
- return validate_op;
- }
}
return Option<bool>(true);
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 8211f962..9c49bcd3 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -4983,12 +4983,12 @@ TEST_F(CollectionTest, UpdateEmbeddingsForUpdatedDocument) {
TEST_F(CollectionTest, CreateCollectionWithOpenAI) {
nlohmann::json schema = R"({
- "name": "objects",
- "fields": [
- {"name": "name", "type": "string"},
- {"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "openai/text-embedding-ada-002"}}}
- ]
- })"_json;
+ "name": "objects",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "openai/text-embedding-ada-002"}}}
+ ]
+ })"_json;
if (std::getenv("api_key") == nullptr) {
LOG(INFO) << "Skipping test as api_key is not set.";
@@ -5000,8 +5000,19 @@ TEST_F(CollectionTest, CreateCollectionWithOpenAI) {
TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
-}
+ // create one more collection
+ schema = R"({
+ "name": "objects2",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "embedding", "type":"float[]", "embed":{"from": ["name"], "model_config": {"model_name": "openai/text-embedding-ada-002"}}}
+ ]
+ })"_json;
+ schema["fields"][1]["embed"]["model_config"]["api_key"] = api_key;
+ op = collectionManager.create_collection(schema);
+ ASSERT_TRUE(op.ok());
+}
TEST_F(CollectionTest, CreateOpenAIEmbeddingField) {
nlohmann::json schema = R"({