fix(gemini-embedding): wrap batch embedding texts in Content to avoid collapse on gemini-embedding-2 (#8537)

* fix(provider): wrap batch embedding texts in Content to avoid collapse on gemini-embedding-2

* fix(gemini_embedding): format list comprehension for better readability

---------

Co-authored-by: Rat0323 <Rat0323@users.noreply.github.com>
Co-authored-by: Soulter <905617992@qq.com>
This commit is contained in:
Rat
2026-06-03 10:42:04 +08:00
committed by GitHub
parent 072691877d
commit f01dc474ef

View File

@@ -1,4 +1,3 @@
from typing import cast
from google import genai
from google.genai import types
@@ -61,9 +60,12 @@ class GeminiEmbeddingProvider(EmbeddingProvider):
async def get_embeddings(self, text: list[str]) -> list[list[float]]:
"""批量获取文本的嵌入"""
try:
contents = [
types.Content(parts=[types.Part.from_text(text=s)]) for s in text
]
result = await self.client.models.embed_content(
model=self.model,
contents=cast(types.ContentListUnion, text),
contents=contents,
config=types.EmbedContentConfig(
output_dimensionality=self.get_dim(),
),