类class
agentscope.embeddingGeminiEmbeddingModel
class GeminiEmbeddingModel(EmbeddingModelBase[str | TextBlock | DataBlock])
源码Source
agentscope/embedding/_gemini/_model.py:67–487Gemini 向量化模型,与模型服务通信并返回生成或向量化结果。位于 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 aContentobject so the API returns separate embeddings.
Key API differences from other providers:
- Dimensions are controlled via
output_dimensionalityin theconfigparameter (not a top-leveldimensionsfield). gemini-embedding-001supportstask_typein config;gemini-embedding-2uses 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 |
|---|---|---|
credential | CredentialBase | 凭证对象(类型 `CredentialBase`)。A :class:`~agentscope.credential.GeminiCredential` instance providing the API key. |
model | str | 模型实例(类型 `str`)。The embedding model name (e.g. `"gemini-embedding-001"` or `"gemini-embedding-2"`). |
dimensions | int | 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 None | EmbeddingCacheBase | None | 向量化缓存(类型 `EmbeddingCacheBase | None`)。Optional embedding cache. |
context_size默认default 8192 | int | 上下文大小(类型 `int`)。Maximum input tokens. 2048 for `gemini-embedding-001`, 8192 for `gemini-embedding-2`. |
max_retries默认default 3 | int | 最大重试次数(类型 `int`)。Number of retries on transient failures. |
retry_delay默认default 1.0 | float | 重试延迟(类型 `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 |
|---|---|---|
inputs | list[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`. |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
EmbeddingResponse
返回EmbeddingResponse。`EmbeddingResponse`: Merged response for all inputs.
源码Source
agentscope/embedding/_gemini/_model.py:163–209