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

EmbeddingModelBase

class EmbeddingModelBase(Generic[InputT])
源码Source agentscope/embedding/_embedding_base.py:34–457

向量化模型的基类。位于 agentscope.embedding 包,继承自 Generic[InputT]。核心成员包括 list_models。

Generic over :data:InputT so that text-only subclasses (EmbeddingModelBase[str]) and multimodal subclasses (EmbeddingModelBase[str | TextBlock | DataBlock]) expose the correct inputs type to the IDE.

Follows the same pattern as :class:~agentscope.model.ChatModelBase:

  • __call__ splits inputs into batches of size :attr:batch_size, calls :meth:_call_api for each batch concurrently via :func:asyncio.gather, and merges the results. Each batch call is wrapped with retry logic.
  • Subclasses only implement :meth:_call_api for a single batch — no batching or retry code needed.
  • Each subclass may override :meth:_get_retryable_exceptions to declare provider-specific retriable errors.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Parameters类class
参数,与模型服务通信并返回生成或向量化结果。
Provider-specific tunables for embedding models.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(credential: CredentialBase, model: str, dimensions: int | None, parameters: BaseModel | None, context_size…
初始化向量化模型基类。
Initialize the embedding model base class.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
credentialCredentialBase
凭证字段。
—
modelstr
模型字段。
—
dimensionsint
维度字段。
—
context_sizeint
上下文大小字段。
—
batch_sizeint
`batch_size` 字段。
—
max_retriesint
最大重试字段。
—
retry_delayfloat
重试延迟字段。
—
supports_multimodalbool
支持多模态字段。
False

方法摘要Method Summary

方法Method说明Description
async def __call__(inputs: list[InputT], **kwargs: Any) -> EmbeddingResponseasync
以可调用对象方式执行。
Embed a list of inputs with automatic batching and retry.
def list_models(custom_yaml_dir: str | None = None) -> list[EmbeddingModelCard]
列出模型。
List candidate embedding models from YAML files.

构造器详情Constructor Detail

EmbeddingModelBase

def __init__(credential: CredentialBase, model: str, dimensions: int | None, parameters: BaseModel | None, context_size: int, batch_size: int, max_retries: int, retry_delay: float) -> None

初始化向量化模型基类。

Initialize the embedding model base class.

参数Parameters
名称Name类型Type说明Description
credentialCredentialBase凭证对象(类型 `CredentialBase`)。The API credential used for authentication.
modelstr向量化模型的名称。The name of the embedding model.
dimensionsint | None向量维度(类型 `int | None`)。The output embedding vector dimensions for this instance. Required and first-class — see the class docstring for the rationale of keeping `dimensions` outside :class:`Parameters`. For backward compatibility with older configs that stored `dimensions` inside :class:`Parameters`, `None` is accepted at the signature level and is back-filled from `parameters.dimensions` when present.
parametersBaseModel | None参数(类型 `BaseModel | None`)。Provider-specific non-dimensional parameters. When `None`, the default `Parameters()` is used.
context_sizeint上下文大小(类型 `int`)。Maximum input length (in tokens) per single input item.
batch_sizeintbatch 大小(类型 `int`)。Maximum number of input items per API call. When `__call__` receives more items, it splits them into batches and calls :meth:`_call_api` concurrently.
max_retriesint最大重试次数(类型 `int`)。The maximum number of retries for each batch API call. Only exceptions listed in :meth:`_get_retryable_exceptions` count against this budget.
retry_delayfloat重试延迟(类型 `float`)。Seconds to sleep between retry attempts.
源码Source agentscope/embedding/_embedding_base.py:104–182

属性详情Attribute Detail

credential

CredentialBase

凭证字段。声明为 CredentialBase。

The credential field.

源码Source agentscope/embedding/_embedding_base.py:72

model

str

模型字段。声明为 str。

The model field.

源码Source agentscope/embedding/_embedding_base.py:75

dimensions

int

维度字段。声明为 int。

The dimensions field.

源码Source agentscope/embedding/_embedding_base.py:78

context_size

int

上下文大小字段。声明为 int。

The context size field.

源码Source agentscope/embedding/_embedding_base.py:86

batch_size

int

batch_size 字段。声明为 int。

The batch size field.

源码Source agentscope/embedding/_embedding_base.py:89

max_retries

int

最大重试字段。声明为 int。

The max retries field.

源码Source agentscope/embedding/_embedding_base.py:92

retry_delay

float

重试延迟字段。声明为 float。

The retry delay field.

源码Source agentscope/embedding/_embedding_base.py:95

supports_multimodal

bool = False

支持多模态字段。声明为 bool。

The supports multimodal field.

源码Source agentscope/embedding/_embedding_base.py:98

方法详情Method Detail

__call__

async def __call__(inputs: list[InputT], **kwargs: Any) -> EmbeddingResponse
async

以可调用对象方式执行。

The inputs are split into chunks of :attr:batch_size.

参数Parameters
名称Name类型Type说明Description
inputslist[InputT]输入消息(类型 `list[InputT]`)。The input data to embed. For text-only models this is `list[str]`; for multimodal models it is `list[str | TextBlock | DataBlock]`. Any :class:`TextBlock` items are transparently unpacked to their `.text` field on entry, so subclasses' batching and `_call_api` only have to handle `str` (and `DataBlock` for multimodal variants).
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns EmbeddingResponse
返回EmbeddingResponse。`EmbeddingResponse`:
源码Source agentscope/embedding/_embedding_base.py:197–260

list_models

def list_models(custom_yaml_dir: str | None = None) -> list[EmbeddingModelCard]

列出模型。

Each concrete subclass should live in its own provider subdirectory (e.g.

参数Parameters
名称Name类型Type说明Description
custom_yaml_dir默认default Nonestr | None自定义 yaml 目录(类型 `str | None`)。Override the YAML directory.
返回Returns list[EmbeddingModelCard]
返回EmbeddingModelCard列表。`list[EmbeddingModelCard]`:
源码Source agentscope/embedding/_embedding_base.py:411–457

嵌套类详情Nested Class Detail

Parameters

class Parameters

参数,与模型服务通信并返回生成或向量化结果。位于 agentscope.embedding 包。

Intentionally empty in the base — dimensions is a contract property of an embedding model (its output vector size), not a tunable knob, so it lives directly on the instance via the required :paramref:__init__.dimensions argument. Subclasses extend this class to expose non-dimensional knobs (e.g. Gemini's task_type, Dashscope's text_type).

extra="allow" is set so old persisted configs (where dimensions lived in parameters) keep deserialising without raising; :meth:EmbeddingModelBase.__init__ extracts it back out for backward compatibility.

基于官方固定版本源码静态生成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.