AS AgentScopeAPI 手册 / API Reference
类class agentscope.embedding

GeminiEmbeddingModel

class GeminiEmbeddingModel(EmbeddingModelBase[str | TextBlock | DataBlock])
源码Source agentscope/embedding/_gemini/_model.py:67–487

Gemini 向量化模型,与模型服务通信并返回生成或向量化结果。位于 agentscope.embedding 包,继承自 EmbeddingModelBase[str | TextBlock | DataBlock]。

Routes to the text-only or multimodal Gemini API based on the model name.

  • Text mode (gemini-embedding-001): uses the base class's simple batch splitting + concurrent retry. The Gemini API accepts a list of strings and returns individual embeddings.
  • Multimodal mode (gemini-embedding-2): overrides __call__ with content-aware batching (respecting per-model limits on images, videos, audios, PDFs). Each input is wrapped in a Content object so the API returns separate embeddings.

Key API differences from other providers:

  • Dimensions are controlled via output_dimensionality in the config parameter (not a top-level dimensions field).
  • gemini-embedding-001 supports task_type in config; gemini-embedding-2 uses prompt prefixes instead.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(credential: CredentialBase, model: str, dimensions: int | None, parameters: 'GeminiEmbeddingModel.Paramete…
初始化 `GeminiEmbeddingModel` 实例。
Initialize the Gemini embedding model.

方法摘要Method Summary

方法Method说明Description
async def __call__(inputs: list[str | TextBlock | DataBlock], **kwargs: Any) -> EmbeddingResponseasync
以可调用对象方式执行。
Embed inputs with batching and retry.

构造器详情Constructor Detail

GeminiEmbeddingModel

def __init__(credential: CredentialBase, model: str, dimensions: int | None, parameters: 'GeminiEmbeddingModel.Parameters | None' = None, embedding_cache: EmbeddingCacheBase | None = None, context_size: int = 8192, max_retries: int = 3, retry_delay: float = 1.0) -> None

初始化 GeminiEmbeddingModel 实例。

Initialize the Gemini embedding model.

参数Parameters
名称Name类型Type说明Description
credentialCredentialBase凭证对象(类型 `CredentialBase`)。A :class:`~agentscope.credential.GeminiCredential` instance providing the API key.
modelstr模型实例(类型 `str`)。The embedding model name (e.g. `"gemini-embedding-001"` or `"gemini-embedding-2"`).
dimensionsint | None向量维度(类型 `int | None`)。The output embedding vector dimensions. Required at the contract level — see :class:`EmbeddingModelBase` for the rationale. `None` is accepted only for backward compatibility with legacy configs that persisted `dimensions` inside `parameters`.
parameters默认default None'GeminiEmbeddingModel.Parameters | None'参数(类型 `'GeminiEmbeddingModel.Parameters | None'`)。Provider-specific non-dimensional text embedding options, such as `task_type`. Per-call options take precedence.
embedding_cache默认default NoneEmbeddingCacheBase | None向量化缓存(类型 `EmbeddingCacheBase | None`)。Optional embedding cache.
context_size默认default 8192int上下文大小(类型 `int`)。Maximum input tokens. 2048 for `gemini-embedding-001`, 8192 for `gemini-embedding-2`.
max_retries默认default 3int最大重试次数(类型 `int`)。Number of retries on transient failures.
retry_delay默认default 1.0float重试延迟(类型 `float`)。Seconds between retry attempts.
源码Source agentscope/embedding/_gemini/_model.py:93–157

方法详情Method Detail

__call__

async def __call__(inputs: list[str | TextBlock | DataBlock], **kwargs: Any) -> EmbeddingResponse
async

以可调用对象方式执行。

For text models, delegates to the base class.

参数Parameters
名称Name类型Type说明Description
inputslist[str | TextBlock | DataBlock]输入消息(类型 `list[str | TextBlock | DataBlock]`)。The input data to embed. `TextBlock` items are unpacked to their `.text` field on entry, so the remainder of the pipeline only sees `str` and `DataBlock`.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns EmbeddingResponse
返回EmbeddingResponse。`EmbeddingResponse`: Merged response for all inputs.
源码Source agentscope/embedding/_gemini/_model.py:163–209

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.