agentscope.app.ragBlobStoreBase
class BlobStoreBase(ABC)
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
进入异步上下文并返回自身。
The default implementation is a no-op.
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
退出异步上下文并清理资源。
Exit the async context — close connections if needed.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc_type | type[BaseException] | None | exc 类型(类型 `type[BaseException] | None`)。The exc type. |
exc_val | BaseException | None | exc val(类型 `BaseException | None`)。The exc val. |
exc_tb | Any | exc tb(类型 `Any`)。The exc tb. |
agentscope/app/rag/blob_store/_base.py:70–76write_stream
async def write_stream(key: str, stream: IO[bytes]) -> str
执行写入流相关操作。
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | str | 键(类型 `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, ...). |
stream | IO[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. |
agentscope/app/rag/blob_store/_base.py:83–108open
async def open(uri: str) -> AbstractAsyncContextManager[AsyncReadable]
设置打开。
Returns an async context manager whose __aenter__ yields a stream with an awaitable read(n) method.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
uri | str | URI(类型 `str`)。A URI produced by :meth:`write_stream`. |
agentscope/app/rag/blob_store/_base.py:111–131delete
async def delete(uri: str) -> None
删除数据。
MUST be idempotent — a no-op when the blob is already gone.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
uri | str | URI(类型 `str`)。A URI produced by :meth:`write_stream`. |
agentscope/app/rag/blob_store/_base.py:134–145size
async def size(uri: str) -> int | None
设置大小。
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
uri | str | URI(类型 `str`)。A URI produced by :meth:`write_stream`. |
agentscope/app/rag/blob_store/_base.py:147–173exists
async def exists(uri: str) -> bool
判断数据是否存在。
Return whether the blob at uri is present.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
uri | str | URI(类型 `str`)。A URI produced by :meth:`write_stream`. |
agentscope/app/rag/blob_store/_base.py:176–186