类class
agentscope.embeddingFileEmbeddingCache
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 None | int | 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 None | int | 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.
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 |
|---|---|---|
embeddings | List[Embedding] | 向量到存储。The embeddings to store. |
identifier | JSONSerializableObject | identifier(类型 `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 False | bool | overwrite(类型 `bool`)。Whether to overwrite existing embeddings with the same identifier. If `True`, existing embeddings will be replaced. |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
None
无返回值。No value is returned.
源码Source
agentscope/embedding/_file_cache.py:56–90retrieve
async def retrieve(identifier: JSONSerializableObject) -> List[Embedding] | None
async
按查询检索相关文档。
Retrieve the embeddings with the given identifier.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
identifier | JSONSerializableObject | identifier(类型 `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). |
List[Embedding] | None
返回向量化列表。Returns a list of embedding.
源码Source
agentscope/embedding/_file_cache.py:92–110remove
async def remove(identifier: JSONSerializableObject) -> None
async
设置移除。
Remove the embeddings with the given identifier.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
identifier | JSONSerializableObject | identifier(类型 `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). |
None
无返回值。No value is returned.
源码Source
agentscope/embedding/_file_cache.py:112–127clear
async def clear() -> None
async
清空或重置内部状态。
Clear the cache directory by removing all files.
None
无返回值。No value is returned.
源码Source
agentscope/embedding/_file_cache.py:129–133