AS AgentScopeAPI 手册 / API Reference
类class agentscope.app.rag

BlobStoreBase

class BlobStoreBase(ABC)
源码Source agentscope/app/rag/blob_store/_base.py:46–186

二进制对象存储基类,把私有文档转化为可检索的知识。位于 agentscope.app.rag 包,继承自 ABC。核心成员包括 write_stream、open、delete、size、exists。

Lifecycle is managed via the async context manager protocol so the app lifespan can open / close connection pools or filesystem handles uniformly.

方法摘要Method Summary

方法Method说明Description
async def __aenter__() -> Selfasync
进入异步上下文并返回自身。
Enter the async context — open connections / create dirs.
async def __aexit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: Any) -> Noneasync
退出异步上下文并清理资源。
Exit the async context — close connections if needed.
async def write_stream(key: str, stream: IO[bytes]) -> strasyncabstractabstractmethod
执行写入流相关操作。
Stream-write a blob and return its URI.
async def open(uri: str) -> AbstractAsyncContextManager[AsyncReadable]asyncabstractabstractmethod
设置打开。
Stream-read a blob by URI.
async def delete(uri: str) -> Noneasyncabstractabstractmethod
删除数据。
Delete the blob at ``uri`` if it exists.
async def size(uri: str) -> int | Noneasync
设置大小。
Return the stored byte length of the blob, if measurable.
async def exists(uri: str) -> boolasyncabstractabstractmethod
判断数据是否存在。
Return whether the blob at ``uri`` is present.

方法详情Method Detail

__aenter__

async def __aenter__() -> Self
async

进入异步上下文并返回自身。

The default implementation is a no-op.

返回Returns Self
返回自身。`BlobStoreBase`:
源码Source agentscope/app/rag/blob_store/_base.py:58–68

__aexit__

async def __aexit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: Any) -> None
async

退出异步上下文并清理资源。

Exit the async context — close connections if needed.

参数Parameters
名称Name类型Type说明Description
exc_typetype[BaseException] | Noneexc 类型(类型 `type[BaseException] | None`)。The exc type.
exc_valBaseException | Noneexc val(类型 `BaseException | None`)。The exc val.
exc_tbAnyexc tb(类型 `Any`)。The exc tb.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/rag/blob_store/_base.py:70–76

write_stream

async def write_stream(key: str, stream: IO[bytes]) -> str
asyncabstractabstractmethod

执行写入流相关操作。

Implementations MUST copy the bytes in chunks (typically ~1 MB) and MUST NOT call stream.read() without a size argument — the whole point of the abstraction is that the byte payload never lives in memory all at once.

参数Parameters
名称Name类型Type说明Description
keystr键(类型 `str`)。Backend-relative key, e.g. `"kb/{kb_id}/{doc_id}"`. The caller picks the key layout; the backend turns it into a backend-native location (filesystem path, `s3://` object name, ...).
streamIO[bytes]流(类型 `IO[bytes]`)。A readable binary stream. Synchronous read API (`read(n)`) — `UploadFile.file` from FastAPI fits directly, and other binary streams are wrapped via the same protocol.
返回Returns str
返回字符串结果。`str`:
源码Source agentscope/app/rag/blob_store/_base.py:83–108

open

async def open(uri: str) -> AbstractAsyncContextManager[AsyncReadable]
asyncabstractabstractmethod

设置打开。

Returns an async context manager whose __aenter__ yields a stream with an awaitable read(n) method.

参数Parameters
名称Name类型Type说明Description
uristrURI(类型 `str`)。A URI produced by :meth:`write_stream`.
返回Returns AbstractAsyncContextManager[AsyncReadable]
返回AbstractAsyncContextManager[AsyncReadable]。`AbstractAsyncContextManager[AsyncReadable]`:
源码Source agentscope/app/rag/blob_store/_base.py:111–131

delete

async def delete(uri: str) -> None
asyncabstractabstractmethod

删除数据。

MUST be idempotent — a no-op when the blob is already gone.

参数Parameters
名称Name类型Type说明Description
uristrURI(类型 `str`)。A URI produced by :meth:`write_stream`.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/rag/blob_store/_base.py:134–145

size

async def size(uri: str) -> int | None
async

设置大小。

Callers use this to set Content-Length on a download, which is what turns a browser's progress bar from "bytes so far" into a percentage.

参数Parameters
名称Name类型Type说明Description
uristrURI(类型 `str`)。A URI produced by :meth:`write_stream`.
返回Returns int | None
返回int|None。`int | None`:
源码Source agentscope/app/rag/blob_store/_base.py:147–173

exists

async def exists(uri: str) -> bool
asyncabstractabstractmethod

判断数据是否存在。

Return whether the blob at uri is present.

参数Parameters
名称Name类型Type说明Description
uristrURI(类型 `str`)。A URI produced by :meth:`write_stream`.
返回Returns bool
返回布尔值,表示判断结果。`bool`:
源码Source agentscope/app/rag/blob_store/_base.py:176–186
基于官方固定版本源码静态生成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.