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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Use std::lock_guard to lock the mutex in text embedder
ozanarmagan229d536107b0
diff --git a/include/text_embedder.h b/include/text_embedder.hindex 50f635fb..38666a2e 100644--- a/include/text_embedder.h+++ b/include/text_embedder.h@@ -34,4 +34,5 @@ class TextEmbedder {std::string output_tensor_name;static Option<bool> validate_remote_model(const nlohmann::json& model_config, unsigned int& num_dims);static Option<bool> validate_local_or_public_model(const nlohmann::json& model_config, unsigned int& num_dims);+ std::mutex mutex_;};diff --git a/src/text_embedder.cpp b/src/text_embedder.cppindex e27fcb76..a29c4062 100644--- a/src/text_embedder.cpp+++ b/src/text_embedder.cpp@@ -79,6 +79,8 @@ Option<std::vector<float>> TextEmbedder::Embed(const std::string& text) {if(is_remote()) {return remote_embedder_->Embed(text);} else {+ // Cannot run same model in parallel, so lock the mutex+ std::lock_guard<std::mutex> lock(mutex_);auto encoded_input = tokenizer_->Encode(text);// create input tensor object from data valuesOrt::AllocatorWithDefaultOptions allocator;