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 voice query model references and error messages

ozanarmaganeeb5f047cff7
diff --git a/bazel/whisper.BUILD b/bazel/whisper.BUILD
index d49109af..dcebdad3 100644
--- a/bazel/whisper.BUILD
+++ b/bazel/whisper.BUILD
@@ -36,6 +36,7 @@ cmake(
},
}),
build_args = [
+ "--config RelWithDebInfo",
"--", "-j8"
],
diff --git a/include/vq_model.h b/include/vq_model.h
index 5eac550a..8572eb52 100644
--- a/include/vq_model.h
+++ b/include/vq_model.h
@@ -11,7 +11,7 @@
class VQModel {
protected:
- int collection_ref_count = 1;
+ int collection_ref_count = 0;
std::shared_mutex collection_ref_count_mutex;
std::string model_name;
public:
diff --git a/src/aq_model_manager.cpp b/src/aq_model_manager.cpp
index c377d6bd..1d74a40b 100644
--- a/src/aq_model_manager.cpp
+++ b/src/aq_model_manager.cpp
@@ -70,7 +70,7 @@ Option<bool> VQModelManager::download_model(const std::string& model_name) {
auto config_json = config.get();
if (config_json.find(model_name + ".bin") == config_json.end()) {
- return Option<bool>(400, "Audio query model not found");
+ return Option<bool>(400, "Voice query model not found");
}
auto model_md5 = config_json[model_name + ".bin"].get<std::string>();
@@ -86,7 +86,7 @@ Option<bool> VQModelManager::download_model(const std::string& model_name) {
LOG(INFO) << "Downloading model " << model_name << " from " << model_url << " to " << model_path;
if (response != 200) {
LOG(INFO) << response;
- return Option<bool>(400, "Failed to download audio query model");
+ return Option<bool>(400, "Failed to download voice query model");
}
return Option<bool>(true);
@@ -109,7 +109,7 @@ Option<std::shared_ptr<VQModel>> VQModelManager::validate_and_init_model(const s
if (model_namespace == "whisper") {
auto whisper_ctx = WhisperModel::validate_and_load_model(model_path);
if (!whisper_ctx) {
- return Option<std::shared_ptr<VQModel>>(400, "Failed to load audio query model");
+ return Option<std::shared_ptr<VQModel>>(400, "Failed to load voice query model");
}
auto whisper_model = std::shared_ptr<VQModel>(new WhisperModel(whisper_ctx, model_name));
{
@@ -126,7 +126,7 @@ Option<std::shared_ptr<VQModel>> VQModelManager::get_model(const std::string& mo
std::shared_lock<std::shared_mutex> lock(models_mutex);
auto model = models.find(model_name);
if (model == models.end()) {
- return Option<std::shared_ptr<VQModel>>(400, "Audio query model not found");
+ return Option<std::shared_ptr<VQModel>>(400, "Voice query model not found");
}
return Option<std::shared_ptr<VQModel>>(model->second);
}
diff --git a/src/collection.cpp b/src/collection.cpp
index dfde66e5..d525aae8 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -66,10 +66,14 @@ Collection::~Collection() {
std::unique_lock lifecycle_lock(lifecycle_mutex);
std::unique_lock lock(mutex);
delete index;
- delete synonym_index;
+ delete synonym_index;
if (vq_model) {
vq_model->dec_collection_ref_count();
+ if (vq_model->get_collection_ref_count() == 0) {
+ LOG(INFO) << "Unloading voice query model " << vq_model->get_model_name();
+ VQModelManager::get_instance().delete_model(vq_model->get_model_name());
+ }
}
}
@@ -1774,7 +1778,7 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
std::string transcribed_query;
if(!voice_query.empty()) {
if(!vq_model) {
- return Option<nlohmann::json>(400, "Audio query is not enabled. Please set `voice_query_model` for this collection.");
+ return Option<nlohmann::json>(400, "Voice query is not enabled. Please set `voice_query_model` for this collection.");
}
auto transcribe_res = vq_model->transcribe(voice_query);
@@ -2984,8 +2988,8 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
result["request_params"]["q"] = raw_query;
if(!voice_query.empty()) {
- result["voice_query"] = nlohmann::json::object();
- result["voice_query"]["transcribed_query"] = transcribed_query;
+ result["request_params"]["voice_query"] = nlohmann::json::object();
+ result["request_params"]["voice_query"]["transcribed_query"] = transcribed_query;
}
if(!override_metadata.empty()) {
diff --git a/src/collection_manager.cpp b/src/collection_manager.cpp
index a5a45b6f..e5c94e50 100644
--- a/src/collection_manager.cpp
+++ b/src/collection_manager.cpp
@@ -157,7 +157,7 @@ Collection* CollectionManager::init_collection(const nlohmann::json & collection
std::string model_name = voice_query_model["model_name"].get<std::string>();
auto model_res = VQModelManager::get_instance().validate_and_init_model(model_name);
if(!model_res.ok()) {
- LOG(ERROR) << "Error while loading audio query model: " << model_res.error();
+ LOG(ERROR) << "Error while loading voice query model: " << model_res.error();
} else {
model = model_res.get();
}
@@ -1219,7 +1219,7 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& re
// check presence of mandatory params here
- if(req_params.count(QUERY) == 0) {
+ if(req_params.count(QUERY) == 0 && req_params.count(VOICE_QUERY) == 0) {
return Option<bool>(400, std::string("Parameter `") + QUERY + "` is required.");
}
@@ -1746,7 +1746,7 @@ Option<Collection*> CollectionManager::create_collection(nlohmann::json& req_jso
std::string model_name = voice_query_model["model_name"].get<std::string>();
auto model_res = VQModelManager::get_instance().validate_and_init_model(model_name);
if(!model_res.ok()) {
- LOG(ERROR) << "Error while loading audio query model: " << model_res.error();
+ LOG(ERROR) << "Error while loading voice query model: " << model_res.error();
return Option<Collection*>(model_res.code(), model_res.error());
} else {
model = model_res.get();
diff --git a/src/typesense_server_utils.cpp b/src/typesense_server_utils.cpp
index dcc8f136..18367fca 100644
--- a/src/typesense_server_utils.cpp
+++ b/src/typesense_server_utils.cpp
@@ -25,6 +25,7 @@
#include "stopwords_manager.h"
#include "conversation_manager.h"
#include "conversation_model_manager.h"
+#include "vq_model_manager.h"
#ifndef ASAN_BUILD
#include "jemalloc.h"
@@ -569,6 +570,9 @@ int run_server(const Config & config, const std::string & version, void (*master
LOG(INFO) << "CollectionManager dispose, this might take some time...";
+ // We have to delete the models here, before CUDA driver is unloaded.
+ VQModelManager::get_instance().delete_all_models();
+
CollectionManager::get_instance().dispose();
LOG(INFO) << "Bye.";
diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp
index 53f6a1a0..999699dc 100644
--- a/test/collection_vector_search_test.cpp
+++ b/test/collection_vector_search_test.cpp
@@ -3723,7 +3723,7 @@ TEST_F(CollectionVectorTest, TestInvalidAudioQueryModel) {
auto collection_create_op = collectionManager.create_collection(schema_json);
ASSERT_FALSE(collection_create_op.ok());
- ASSERT_EQ(collection_create_op.error(), "Audio query model not found");
+ ASSERT_EQ(collection_create_op.error(), "Voice query model not found");
schema_json = R"({
"name": "test",
@@ -3737,7 +3737,7 @@ TEST_F(CollectionVectorTest, TestInvalidAudioQueryModel) {
collection_create_op = collectionManager.create_collection(schema_json);
ASSERT_FALSE(collection_create_op.ok());
- ASSERT_EQ(collection_create_op.error(), "Audio query model not found");
+ ASSERT_EQ(collection_create_op.error(), "Voice query model not found");
schema_json = R"({
"name": "test",
@@ -3817,7 +3817,7 @@ TEST_F(CollectionVectorTest, TestAudioQuery) {
ASSERT_TRUE(results.ok());
auto results_json = results.get();
- ASSERT_EQ(results_json["voice_query"]["transcribed_query"].get<std::string>(), " This is a test recording for audio search.");
+ ASSERT_EQ(results_json["request_params"]["voice_query"]["transcribed_query"].get<std::string>(), " This is a test recording for audio search.");
}
TEST_F(CollectionVectorTest, TestInvalidAudioQuery) {