RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(embedding): use Replicate run API for query embeddings (#19405)
Fei Haihao2c1af18d62a6
diff --git a/rag/llm/embedding_model.py b/rag/llm/embedding_model.pyindex 9d0d6596a0..208eda97ce 100644--- a/rag/llm/embedding_model.py+++ b/rag/llm/embedding_model.py@@ -1130,8 +1130,8 @@ class ReplicateEmbed(Base):return np.array(ress), token_countdef encode_queries(self, text):- res = self.client.embed(self.model_name, input={"texts": [text]})- return np.array(res), num_tokens_from_string(text)+ vectors, token_count = self.encode([text])+ return vectors[0], token_countclass BaiduYiyanEmbed(Base):diff --git a/test/unit_test/rag/llm/test_embedding_model.py b/test/unit_test/rag/llm/test_embedding_model.pyindex 98fec1393b..4b32ee8583 100644--- a/test/unit_test/rag/llm/test_embedding_model.py+++ b/test/unit_test/rag/llm/test_embedding_model.py@@ -45,6 +45,7 @@ from rag.llm.embedding_model import (NvidiaEmbed,OllamaEmbed,OpenAIEmbed,+ ReplicateEmbed,ZhipuEmbed,)from common.exceptions import ModelException@@ -369,6 +370,22 @@ class TestNvidiaInputType:assert post.call_args.kwargs["json"]["input_type"] == "query"+class TestReplicateEmbedding:+ def test_query_uses_run_and_returns_single_vector(self):+ embed = ReplicateEmbed.__new__(ReplicateEmbed)+ embed.model_name = "owner/model:version"+ embed.client = MagicMock(spec=["run"])+ embed.client.run.return_value = [[1.0, 2.0, 3.0]]++ vector, tokens = embed.encode_queries("hello")++ embed.client.run.assert_called_once_with("owner/model:version", input={"texts": ["hello"]})+ assert vector.shape == (3,)+ np.testing.assert_array_equal(vector, np.array([1.0, 2.0, 3.0]))+ assert tokens == num_tokens_from_string("hello")++@pytest.mark.p2class TestBedrockResponseParsing:"""Bedrock Titan returns {"embedding": [...]}; Cohere returns