Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(llm): raise a clear error for unsupported Bedrock embedding models (#16044)

Lucas Kim86edfc45a8bc
diff --git a/rag/llm/embedding_model.py b/rag/llm/embedding_model.py
index 3ffc61513e..9d0d6596a0 100644
--- a/rag/llm/embedding_model.py
+++ b/rag/llm/embedding_model.py
@@ -758,6 +758,8 @@ class BedrockEmbed(Base):
body = {"inputText": text}
elif self.is_cohere:
body = {"texts": [text], "input_type": "search_document"}
+ else:
+ raise EmbeddingError(f"BedrockEmbed: unsupported embedding model '{self.model_name}' (expected an 'amazon.' or 'cohere.' model)")
response = self.client.invoke_model(modelId=self.model_name, body=json.dumps(body))
model_response = json.loads(response["body"].read())
# Bedrock does not report token usage; count locally.
@@ -772,6 +774,8 @@ class BedrockEmbed(Base):
body = {"inputText": text}
elif self.is_cohere:
body = {"texts": [text], "input_type": "search_query"}
+ else:
+ raise EmbeddingError(f"BedrockEmbed: unsupported embedding model '{self.model_name}' (expected an 'amazon.' or 'cohere.' model)")
try:
response = self.client.invoke_model(modelId=self.model_name, body=json.dumps(body))
model_response = json.loads(response["body"].read())
diff --git a/test/unit_test/rag/llm/test_embedding_model.py b/test/unit_test/rag/llm/test_embedding_model.py
index cb879684ca..98fec1393b 100644
--- a/test/unit_test/rag/llm/test_embedding_model.py
+++ b/test/unit_test/rag/llm/test_embedding_model.py
@@ -408,6 +408,22 @@ class TestBedrockResponseParsing:
vector, _ = embed.encode_queries("q")
np.testing.assert_array_equal(vector, np.array([5.0, 6.0]))
+ # The message must name the offending model and the expected prefixes so the
+ # error stays actionable; assert on it to catch future wording regressions.
+ _UNSUPPORTED_MSG = r"unsupported embedding model 'meta\.embed-model'.*amazon\..*cohere\."
+
+ def test_unknown_provider_raises_embedding_error(self):
+ # A model that is neither amazon.* nor cohere.* must surface a clear
+ # EmbeddingError instead of an UnboundLocalError on the unset `body`.
+ embed = self._make("meta")
+ with pytest.raises(EmbeddingError, match=self._UNSUPPORTED_MSG):
+ embed.encode(["hello"])
+
+ def test_unknown_provider_query_raises_embedding_error(self):
+ embed = self._make("meta")
+ with pytest.raises(EmbeddingError, match=self._UNSUPPORTED_MSG):
+ embed.encode_queries("q")
+
@pytest.mark.p2
class TestBaiduYiyanResponseParsing: