agentscope.ragParserBase
class ParserBase(ABC)
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_types | list[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.
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.
agentscope/rag/_parser/_base.py:44–71parse
async def parse(file: bytes | str, filename: str) -> list[Section]
执行解析相关操作。
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file | bytes | str | 文件(类型 `bytes | str`)。The file content or a path to it (see above). |
filename | str | filename(类型 `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. |
- 可能抛出 `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.
agentscope/rag/_parser/_base.py:74–116