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

FileEmbeddingCache

class FileEmbeddingCache(EmbeddingCacheBase)
源码Source agentscope/embedding/_file_cache.py:19–223

文件向量化缓存,与模型服务通信并返回生成或向量化结果。位于 agentscope.embedding 包,继承自 EmbeddingCacheBase。核心成员包括 store、retrieve、remove、clear、cache_dir。

The embedding cache class that stores each embeddings vector in binary files. Declared in agentscope.embedding. Extends EmbeddingCacheBase.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(cache_dir: str = './.cache/embeddings', max_file_number: int | None = None, max_cache_size: int | None = N…
初始化文件向量化缓存。
Initialize the file embedding cache class.

属性摘要Property Summary

属性Property说明Description
cache_dir
缓存目录其中向量化文件是已存储。
The cache directory where the embedding files are stored.

方法摘要Method Summary

方法Method说明Description
async def store(embeddings: List[Embedding], identifier: JSONSerializableObject, overwrite: bool = False, **kwargs: Any…async
执行存储相关操作。
Store the embeddings with the given identifier.
async def retrieve(identifier: JSONSerializableObject) -> List[Embedding] | Noneasync
按查询检索相关文档。
Retrieve the embeddings with the given identifier. If not found, return `None`.
async def remove(identifier: JSONSerializableObject) -> Noneasync
设置移除。
Remove the embeddings with the given identifier.
async def clear() -> Noneasync
清空或重置内部状态。
Clear the cache directory by removing all files.

构造器详情Constructor Detail

FileEmbeddingCache

def __init__(cache_dir: str = './.cache/embeddings', max_file_number: int | None = None, max_cache_size: int | None = None) -> None

初始化文件向量化缓存。

Initialize the file embedding cache class.

参数Parameters
名称Name类型Type说明Description
cache_dir默认default './.cache/embeddings'str目录到存储向量化文件。The directory to store the embedding files.
max_file_number默认default Noneint | None最大文件数量(类型 `int | None`)。The maximum number of files to keep in the cache directory. If exceeded, the oldest files will be removed. `None` leaves the file count unlimited; `0` retains no embedding files after a write.
max_cache_size默认default Noneint | None最大缓存大小(类型 `int | None`)。The maximum size of the cache directory in MB. If exceeded, the oldest files will be removed until the size is within the limit. A vector set that exceeds the limit on its own is not cached, so that storing it cannot empty the cache.
源码Source agentscope/embedding/_file_cache.py:23–47

属性详情Property Detail

cache_dir

def cache_dir() -> str

缓存目录其中向量化文件是已存储。

The cache directory where the embedding files are stored.

返回Returns str
返回字符串结果。Returns a string.
源码Source agentscope/embedding/_file_cache.py:50–54

方法详情Method Detail

store

async def store(embeddings: List[Embedding], identifier: JSONSerializableObject, overwrite: bool = False, **kwargs: Any) -> None
async

执行存储相关操作。

Store the embeddings with the given identifier.

参数Parameters
名称Name类型Type说明Description
embeddingsList[Embedding]向量到存储。The embeddings to store.
identifierJSONSerializableObjectidentifier(类型 `JSONSerializableObject`)。The identifier to distinguish the embeddings, which will be used to generate a hashable filename, so it should be JSON serializable (e.g. a string, number, list, dict).
overwrite默认default Falsebooloverwrite(类型 `bool`)。Whether to overwrite existing embeddings with the same identifier. If `True`, existing embeddings will be replaced.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/embedding/_file_cache.py:56–90

retrieve

async def retrieve(identifier: JSONSerializableObject) -> List[Embedding] | None
async

按查询检索相关文档。

Retrieve the embeddings with the given identifier.

参数Parameters
名称Name类型Type说明Description
identifierJSONSerializableObjectidentifier(类型 `JSONSerializableObject`)。The identifier to retrieve the embeddings, which will be used to generate a hashable filename, so it should be JSON serializable (e.g. a string, number, list, dict).
返回Returns List[Embedding] | None
返回向量化列表。Returns a list of embedding.
源码Source agentscope/embedding/_file_cache.py:92–110

remove

async def remove(identifier: JSONSerializableObject) -> None
async

设置移除。

Remove the embeddings with the given identifier.

参数Parameters
名称Name类型Type说明Description
identifierJSONSerializableObjectidentifier(类型 `JSONSerializableObject`)。The identifiers to remove the embeddings, which will be used to generate a hashable filename, so it should be JSON serializable (e.g. a string, number, list, dict).
返回Returns None
无返回值。No value is returned.
源码Source agentscope/embedding/_file_cache.py:112–127

clear

async def clear() -> None
async

清空或重置内部状态。

Clear the cache directory by removing all files.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/embedding/_file_cache.py:129–133
基于官方固定版本源码静态生成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.