Skip to content

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

fix(rag): return 1-D vector from BaiduYiyan encode_queries (#16398)

Harsh Kashyapc608ea165ebc
diff --git a/rag/llm/embedding_model.py b/rag/llm/embedding_model.py
index 07eeb78ac7..f6e4eaa7d0 100644
--- a/rag/llm/embedding_model.py
+++ b/rag/llm/embedding_model.py
@@ -1155,7 +1155,7 @@ class BaiduYiyanEmbed(Base):
try:
res = self.client.do(model=self.model_name, texts=[text]).body
return (
- np.array([r["embedding"] for r in res["data"]]),
+ np.array(res["data"][0]["embedding"]),
total_token_count_from_response(res),
)
except Exception as _e:
diff --git a/test/unit_test/rag/llm/test_embedding_model.py b/test/unit_test/rag/llm/test_embedding_model.py
index 13fec627e3..13059b7a8a 100644
--- a/test/unit_test/rag/llm/test_embedding_model.py
+++ b/test/unit_test/rag/llm/test_embedding_model.py
@@ -35,6 +35,7 @@ import numpy as np
import pytest
from rag.llm.embedding_model import (
+ BaiduYiyanEmbed,
DEFAULT_MAX_TOKENS,
AzureEmbed,
BedrockEmbed,
@@ -406,3 +407,23 @@ class TestBedrockResponseParsing:
embed.client.invoke_model.return_value = self._body({"embeddings": [[5.0, 6.0]]})
vector, _ = embed.encode_queries("q")
np.testing.assert_array_equal(vector, np.array([5.0, 6.0]))
+
+
+class TestBaiduYiyanResponseParsing:
+ def test_query_returns_single_vector(self):
+ embed = BaiduYiyanEmbed.__new__(BaiduYiyanEmbed)
+ embed.model_name = "bge-large-zh"
+ embed.client = MagicMock()
+ embed.client.do.return_value = SimpleNamespace(
+ body={
+ "data": [{"embedding": [1.0, 2.0, 3.0]}],
+ "usage": {"total_tokens": 7},
+ }
+ )
+
+ vector, tokens = embed.encode_queries("hello")
+
+ assert vector.shape == (3,)
+ np.testing.assert_array_equal(vector, np.array([1.0, 2.0, 3.0]))
+ assert tokens == 7