agentscope.embeddingEmbeddingModelBase
class EmbeddingModelBase(Generic[InputT])
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_apifor each batch concurrently via :func:asyncio.gather, and merges the results. Each batch call is wrapped with retry logic.- Subclasses only implement :meth:
_call_apifor a single batch — no batching or retry code needed. - Each subclass may override :meth:
_get_retryable_exceptionsto 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 |
|---|---|---|---|
credential | CredentialBase | 凭证字段。 | — |
model | str | 模型字段。 | — |
dimensions | int | 维度字段。 | — |
context_size | int | 上下文大小字段。 | — |
batch_size | int | `batch_size` 字段。 | — |
max_retries | int | 最大重试字段。 | — |
retry_delay | float | 重试延迟字段。 | — |
supports_multimodal | bool | 支持多模态字段。 | 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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
credential | CredentialBase | 凭证对象(类型 `CredentialBase`)。The API credential used for authentication. |
model | str | 向量化模型的名称。The name of the embedding model. |
dimensions | int | 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. |
parameters | BaseModel | None | 参数(类型 `BaseModel | None`)。Provider-specific non-dimensional parameters. When `None`, the default `Parameters()` is used. |
context_size | int | 上下文大小(类型 `int`)。Maximum input length (in tokens) per single input item. |
batch_size | int | batch 大小(类型 `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_retries | int | 最大重试次数(类型 `int`)。The maximum number of retries for each batch API call. Only exceptions listed in :meth:`_get_retryable_exceptions` count against this budget. |
retry_delay | float | 重试延迟(类型 `float`)。Seconds to sleep between retry attempts. |
agentscope/embedding/_embedding_base.py:104–182属性详情Attribute Detail
credential
CredentialBase凭证字段。声明为 CredentialBase。
The credential field.
agentscope/embedding/_embedding_base.py:72model
str模型字段。声明为 str。
The model field.
agentscope/embedding/_embedding_base.py:75dimensions
int维度字段。声明为 int。
The dimensions field.
agentscope/embedding/_embedding_base.py:78context_size
int上下文大小字段。声明为 int。
The context size field.
agentscope/embedding/_embedding_base.py:86batch_size
intbatch_size 字段。声明为 int。
The batch size field.
agentscope/embedding/_embedding_base.py:89max_retries
int最大重试字段。声明为 int。
The max retries field.
agentscope/embedding/_embedding_base.py:92retry_delay
float重试延迟字段。声明为 float。
The retry delay field.
agentscope/embedding/_embedding_base.py:95supports_multimodal
bool = False支持多模态字段。声明为 bool。
The supports multimodal field.
agentscope/embedding/_embedding_base.py:98方法详情Method Detail
__call__
async def __call__(inputs: list[InputT], **kwargs: Any) -> EmbeddingResponse
以可调用对象方式执行。
The inputs are split into chunks of :attr:batch_size.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
inputs | list[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). |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
agentscope/embedding/_embedding_base.py:197–260list_models
def list_models(custom_yaml_dir: str | None = None) -> list[EmbeddingModelCard]
列出模型。
Each concrete subclass should live in its own provider subdirectory (e.g.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
custom_yaml_dir默认default None | str | None | 自定义 yaml 目录(类型 `str | None`)。Override the YAML directory. |
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.