AS AgentScopeAPI 手册 / API Reference
包package agentscope.app.rag

agentscope.app.rag

module agentscope.app.rag

agentscope.app.rag 属于RAG 与知识库,切分、向量化、存储与检索。 该包共收录 12 个公开类型。

This subpackage groups every RAG-specific service-layer concept under one roof so the user-facing import surface stays compact:

  • :mod:.blob_store — backends storing uploaded document bytes;
  • :mod:.knowledge_base_manager — knowledge base lifecycle and the runtime :class:~agentscope.rag.KnowledgeBase handle shared between HTTP and agents;
  • :mod:.index_worker — out-of-process indexing worker entry point.

Commonly used symbols are re-exported here so the typical user import collapses to a single line::

from agentscope.app.rag import (
    LocalBlobStore,
    S3BlobStore,
    CollectionPerKbManager,
    run_worker,
)

For type-level imports or rare subclasses, use the submodules directly.

源码Source agentscope/app/rag/__init__.py:1

子包Subpackages

类Classes

AsyncReadable
类class
异步可读,把私有文档转化为可检索的知识。
Minimal async-read protocol returned by :meth:`BlobStoreBase.open`.
BlobStoreBase
类class
二进制对象存储基类,把私有文档转化为可检索的知识。
Abstract base class for blob storage backends.
CollectionPerKbManager
类class
集合每个知识库管理器,把私有文档转化为可检索的知识。
One-collection-per-KB knowledge base manager.
DimensionPolicy
类class
维度策略,把私有文档转化为可检索的知识。
The dimension policy a manager exposes to the front-end.
DimensionPolicyError
类class
维度策略错误,把私有文档转化为可检索的知识。
Raised when a create-time embedding model violates the manager's dimension policy.
DimensionPolicyKind
类class
维度策略种类,把私有文档转化为可检索的知识。
The kind of dimension policy the manager publishes.
KnowledgeBaseError
类class
知识库基类管理器错误的基类。
Base class for knowledge base manager errors.
KnowledgeBaseManagerBase
类class
知识库管理器基类,把私有文档转化为可检索的知识。
Abstract base for knowledge base managers.
KnowledgeBaseNotFoundError
类class
知识库未找到错误,把私有文档转化为可检索的知识。
Raised when a knowledge base record cannot be located.
LocalBlobStore
类class
本地二进制对象存储,负责持久化与读取数据。
Store blobs as files beneath a configurable root directory.
S3BlobStore
类class
S 3 二进制对象存储,负责持久化与读取数据。
Store blobs in an S3-compatible bucket.

函数Functions

run_worker
函数function
运行索引 worker
Run the out-of-process index worker until cancelled.

函数详情Function Details

run_worker

async def run_worker(*, storage: 'StorageBase', message_bus: 'MessageBus', blob_store: 'BlobStoreBase', knowledge_base_manager: 'KnowledgeBaseManagerBase', parsers: 'list[ParserBase] | dict[str, ParserBase]', chunkers: 'list[type[ChunkerBase]] | None' = None, node_id: str | None = None, worker_max_concurrency: int = 4, consumer_max_batch: int = 32, parser_executor: ProcessPoolExecutor | None = None, **kwargs: Any) -> None
async

持续消费索引任务,直到被取消;适合把文档向量化放到独立进程部署。

Manages the lifecycle of every passed-in backend through a single :class:AsyncExitStack.

参数Parameters
名称Name类型Type说明Description
storagekw'StorageBase'存储(类型 `'StorageBase'`)。Persistent storage backend. Lifecycle managed here.
message_buskw'MessageBus'消息总线(类型 `'MessageBus'`)。Live message bus subscribed to for index-task signals. Lifecycle managed here.
blob_storekw'BlobStoreBase'二进制对象存储(类型 `'BlobStoreBase'`)。Backend the worker reads document bytes from. Lifecycle managed here.
knowledge_base_managerkw'KnowledgeBaseManagerBase'知识库管理器(类型 `'KnowledgeBaseManagerBase'`)。Resolves :class:`KnowledgeBase` runtimes for embedding + vector store writes. Lifecycle managed here.
parserskw'list[ParserBase] | dict[str, ParserBase]'parsers(类型 `'list[ParserBase] | dict[str, ParserBase]'`)。Parsers used to dispatch uploads by IANA media type. Pass the same registry both to `create_app` and to the worker — list mode expands each parser's `supported_media_types` (later entries override earlier ones, with a warning); dict mode is used verbatim for explicit routing.
chunkerskw默认default None'list[type[ChunkerBase]] | None'chunkers(类型 `'list[type[ChunkerBase]] | None'`)。The chunker classes that can be rebuilt from a knowledge base's `chunker_config`. Defaults to `[ApproxTokenChunker]`.
node_idkw默认default Nonestr | None节点标识(类型 `str | None`)。Stable identifier for this worker process used on the storage lease. Defaults to `"{hostname}:{uuid-prefix}"` — good enough for distinguishing two workers running on the same host; override when your orchestrator has a more meaningful id (Kubernetes pod name, ECS task id, ...).
worker_max_concurrencykw默认default 4int工作进程最大 concurrency(类型 `int`)。Maximum number of documents the worker processes concurrently. See :class:`~agentscope.app._service.IndexWorker`.
consumer_max_batchkw默认default 32int消费者最大 batch(类型 `int`)。Maximum entries the consumer drains per signal. See :class:`~agentscope.app._service.IndexTaskConsumer`.
parser_executorkw默认default NoneProcessPoolExecutor | None解析器执行器(类型 `ProcessPoolExecutor | None`)。Process pool for CPU-bound parses. `None` runs parses inline (fine for text-only deployments).
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/rag/index_worker/__init__.py:80–203
基于官方固定版本源码静态生成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.