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

ParserBase

class ParserBase(ABC)
源码Source agentscope/rag/_parser/_base.py:22–116

解析器基类,把私有文档转化为可检索的知识。位于 agentscope.rag 包,继承自 ABC。核心成员包括 supported_extensions、parse。

Each subclass handles a single file format (or a related family, e.g. all plain-text MIME types). Subclasses are typically instantiated once and reused across many parse() calls.

Subclasses should be stateless or thread-safe — a single instance may be invoked concurrently from multiple agent runs.

Subclasses must declare :attr:supported_media_types so that the KnowledgeBaseManager can route uploaded files to the right parser based on standard IANA media types (RFC 6838).

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
supported_media_typeslist[str]
`supported_media_types` 字段。
—

方法摘要Method Summary

方法Method说明Description
def supported_extensions() -> list[str]
返回 `supported_extensions` 结果。
Filename extensions (including the leading ``.``) this parser can produce uploads for.
async def parse(file: bytes | str, filename: str) -> list[Section]asyncabstractabstractmethod
执行解析相关操作。
Parse a file into a list of :class:`Section` objects.

属性详情Attribute Detail

supported_media_types

list[str]

supported_media_types 字段。声明为 list[str]。

The supported media types field.

源码Source agentscope/rag/_parser/_base.py:37

方法详情Method Detail

supported_extensions

def supported_extensions() -> list[str]

返回 supported_extensions 结果。

The base implementation derives extensions from :attr:supported_media_types via :func:mimetypes.guess_all_extensions — good enough for clean IANA types like application/pdf.

返回Returns list[str]
返回str列表。`list[str]`:
源码Source agentscope/rag/_parser/_base.py:44–71

parse

async def parse(file: bytes | str, filename: str) -> list[Section]
asyncabstractabstractmethod

执行解析相关操作。

The file argument is a union covering the three call sites a parser sees in practice: - bytes — the raw payload, as handed in by HTTP uploads and blob-store reads.

参数Parameters
名称Name类型Type说明Description
filebytes | str文件(类型 `bytes | str`)。The file content or a path to it (see above).
filenamestrfilename(类型 `str`)。The original filename (e.g. `"report.pdf"`). Used for error messages and copied into each Section's :attr:`Section.source` field for downstream display / citation.
返回Returns list[Section]
返回Section列表。`list[Section]`:
异常Raises
  • 可能抛出 `Exception`。`TypeError`: If the subclass does not accept the supplied
  • 可能抛出 `Exception`。`file` form.
  • 可能抛出 `Exception`。`FileNotFoundError`: If a binary parser is handed a
  • 可能抛出 `Exception`。`str` that does not name an existing file.
  • 可能抛出 `Exception`。`ValueError`: If the file cannot be parsed.
源码Source agentscope/rag/_parser/_base.py:74–116
基于官方固定版本源码静态生成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.