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 hanging when PaLM API is down

ozanarmagane0f5c7485744
diff --git a/src/text_embedder_remote.cpp b/src/text_embedder_remote.cpp
index 74226db2..b8908baf 100644
--- a/src/text_embedder_remote.cpp
+++ b/src/text_embedder_remote.cpp
@@ -372,8 +372,19 @@ embedding_res_t GoogleEmbedder::Embed(const std::string& text, const size_t remo
std::vector<embedding_res_t> GoogleEmbedder::batch_embed(const std::vector<std::string>& inputs, const size_t remote_embedding_batch_size) {
std::vector<embedding_res_t> outputs;
+ bool timeout_prev = false;
for(auto& input : inputs) {
auto res = Embed(input);
+ if(res.status_code == 408) {
+ if(timeout_prev) {
+ // fail whole batch if two consecutive timeouts,
+ nlohmann::json req_body;
+ req_body["text"] = input;
+ return std::vector<embedding_res_t>(inputs.size(), embedding_res_t(408, get_error_json(req_body, 408, "")));
+ }
+ timeout_prev = true;
+ }
+ timeout_prev = false;
outputs.push_back(res);
}