grounded-rag-ingestion
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGrounded RAG Ingestion
Grounded RAG 数据摄入
Turn a document into a stream of provenance-carrying chunks — one JSONL line per chunk,
each tagged with its element type, page index, bounding box, confidence score, and
reading-order index, all traceable back to a specific region of the source page.
The differentiator is provenance, a capability frontier-LLM Markdown extraction structurally
cannot supply: a downstream system can highlight the exact region of the source document a
retrieval result came from. That is the compliance-grade requirement for RAG in finance,
healthcare, and legal workflows where "the model said so" is not an acceptable citation. This
skill does not relitigate raw Markdown quality (see the skill for that) — it
adds the provenance layer on top of Nutrient extraction.
pdf-to-markdownThis is a doer skill: a bundled -runnable Python script () drives the pipeline
end to end and emits JSONL to stdout or a file. It is embedding-agnostic — it stops at the
chunk boundary. No vector DB client, no embedding provider import.
uvchunk.py将文档转换为带有溯源信息的分块流——每个分块对应JSONL的一行,
均标记有元素类型、页码索引、边界框(bounding box)、置信度分数和
阅读顺序索引,所有信息均可追溯回源文档的特定页面区域。
其核心优势在于溯源能力,这是前沿LLM的Markdown提取功能在结构上无法提供的:下游系统可以高亮显示检索结果源自源文档的精确区域。这是金融、
医疗和法律工作流中RAG的合规级要求,在这些场景中“模型这么说的”并不算是可接受的引用。本技能不涉及原始Markdown质量的优化(相关需求请使用技能)——它在Nutrient提取的基础上添加了溯源层。
pdf-to-markdown这是一个执行类技能:一个打包好的可通过运行的Python脚本()端到端驱动流水线,并将JSONL输出到标准输出或文件中。它与嵌入方式无关——仅处理分块边界,不包含向量数据库客户端或嵌入提供商的导入。
uvchunk.pyWhen to use
使用场景
- Grounded / cited RAG: retrieval results include and
page_indexso the UI can draw a highlight box on the source document.bbox - Confidence-aware ingestion: gate on to suppress low-confidence chunks before they reach the index.
confidence >= threshold - Reading-order-aware chunking: preserve so sliding-window chunking respects the document's logical sequence.
reading_order - Auditable pipelines: regulated workflows that must prove which page region a retrieved
answer came from — the +
bboxtuple is the audit trail.page_index
Not for cheap whole-document Markdown — that stays in with
. Not for known target fields — if the request names specific
fields ("the invoice number and total", "extract these fields", "map to my schema", "return these fields cited"), use 's (one call returns your schema's fields,
each cited) instead of chunking the whole document for open-ended retrieval. Reach for this
skill when retrieval is open-ended (semantic search over the whole document), not when the
target fields are already known. Not for vector-store upsert or embedding generation — this
skill stops at the chunk JSONL.
document-extraction-api--output-format markdowndocument-extraction-apiextract- 有依据/引用式RAG:检索结果包含和
page_index,以便UI可以在源文档上绘制高亮框。bbox - 置信度感知的数据摄入:通过过滤低置信度分块,避免其进入索引。
confidence >= 阈值 - 阅读顺序感知的分块:保留,确保滑动窗口分块遵循文档的逻辑顺序。
reading_order - 可审计流水线:受监管的工作流必须证明检索答案源自文档的哪个页面区域——+
bbox组合就是审计线索。page_index
不适用场景:低成本全文档Markdown生成——此类需求请使用带参数的。不适用已知目标字段的场景——如果请求指定了特定字段(如“发票编号和总额”、“提取这些字段”、“映射到我的schema”、“返回带引用的指定字段”),请使用的接口(一次调用即可返回符合你schema的字段,且每个字段均带有引用),而非为开放式检索对全文档进行分块。当检索为开放式(对全文档进行语义搜索)而非目标字段已知时,才使用本技能。本技能不处理向量库插入或嵌入生成——仅生成分块JSONL。
--output-format markdowndocument-extraction-apidocument-extraction-apiextractDependency: document-extraction-api
document-extraction-api依赖:document-extraction-api
document-extraction-apiThis skill calls under the hood. Read that skill first for mode
selection, key setup, and credit-cost guidance. reuses its helper
and call — it does not re-implement the API call.
document-extraction-apichunk.pycreate_client()client.parse(..., output_format="spatial")The extraction skill must be present in the same plugin at
. If it lives elsewhere, set to its
directory; fails fast with a clear message if it cannot find it.
../document-extraction-api/scripts/PARSE_SCRIPT_PATHscripts/chunk.py本技能在底层调用。请先阅读该技能文档了解模式选择、密钥设置和信用成本说明。复用了其辅助函数和调用——并未重新实现API调用逻辑。
document-extraction-apichunk.pycreate_client()client.parse(..., output_format="spatial")该提取技能必须位于同一插件的目录下。如果位于其他位置,请设置指向其目录;如果找不到该目录,会快速失败并给出清晰提示。
../document-extraction-api/scripts/PARSE_SCRIPT_PATHscripts/chunk.pySetup
设置
DWS Extract is a separate product from DWS Processor and has its own API key.
- Get a Nutrient DWS Extract API key at https://dashboard.nutrient.io/.
- Export it as :
NUTRIENT_EXTRACT_API_KEYbashexport NUTRIENT_EXTRACT_API_KEY="pdf_live_..." - Run from the directory containing this SKILL.md:
bash
cd <directory containing this SKILL.md> && uv run scripts/chunk.py --help
If your tenant has migrated to global DWS API keys, a single key set as either
or works for both products.
NUTRIENT_EXTRACT_API_KEYNUTRIENT_API_KEYDWS Extract是独立于DWS Processor的产品,拥有独立的API密钥。
- 在https://dashboard.nutrient.io/获取Nutrient DWS Extract API密钥。
- 将其导出为:
NUTRIENT_EXTRACT_API_KEYbashexport NUTRIENT_EXTRACT_API_KEY="pdf_live_..." - 从包含本SKILL.md的目录运行:
bash
cd <包含本SKILL.md的目录> && uv run scripts/chunk.py --help
如果你的租户已迁移至全局DWS API密钥,设置为或的单个密钥可用于两款产品。
NUTRIENT_EXTRACT_API_KEYNUTRIENT_API_KEYMode selection
模式选择
Mode selection for this skill follows the same rules as (mode →
cost → when to use). Pass through to the parse call; the default is .
document-extraction-api--modestructure| Mode | Cost (cr/pg) | When |
|---|---|---|
| 1 | Cheapest; incompatible with spatial — not usable here (this skill requires spatial) |
| 1.5 | Default. OCR + spatial typed elements with bounds and tables |
| 9 | AI layout: required for |
| 18 | VLM: adds |
Mode-gating — important.andkeyValueRegionelements are only populated byformulamode or higher. Under the defaultunderstandmode the key-value and formula chunk paths produce nothing.structurewarns on stderr when KV/formula content would be expected but the mode is too low. To exercise key-value chunking, passchunk.py.--mode understand
本技能的模式选择遵循与相同的规则(模式→成本→适用场景)。将参数传递给解析调用;默认模式为。
document-extraction-api--modestructure| 模式 | 成本(cr/页) | 适用场景 |
|---|---|---|
| 1 | 成本最低;与空间输出不兼容——无法在此使用(本技能需要空间输出) |
| 1.5 | 默认值。OCR + 带边界和表格的空间类型元素 |
| 9 | AI布局: |
| 18 | VLM:为图片添加 |
模式限制——重要提示。和keyValueRegion元素仅在formula模式或更高版本中生成。在默认的understand模式下,键值对和公式分块路径将无输出。当预期会有键值对/公式内容但模式级别过低时,structure会在标准错误输出中发出警告。要使用键值对分块功能,请传递chunk.py参数。--mode understand
Invocation
调用方式
bash
uv run scripts/chunk.py --input doc.pdf --out chunks.jsonl \
[--doc-id ID] [--mode structure] \
[--strategy element|reading-order-window|table-row] [--window-size 512] \
[--min-confidence 0.0] [--skip-pictures] [--yes]- writes JSONL to stdout; otherwise to the named file (created with
--out -permissions — the JSONL carries extracted document text).0600 - Credit usage is printed to stderr after the parse call.
bash
uv run scripts/chunk.py --input doc.pdf --out chunks.jsonl \
[--doc-id ID] [--mode structure] \
[--strategy element|reading-order-window|table-row] [--window-size 512] \
[--min-confidence 0.0] [--skip-pictures] [--yes]- 将JSONL写入标准输出;否则写入指定文件(文件权限为
--out -——JSONL包含提取的文档文本)。0600 - 解析调用完成后,信用使用情况将打印至标准错误输出。
Provenance chunk schema
溯源分块 schema
Each JSONL line is one chunk:
| Field | Type | Source |
|---|---|---|
| string | deterministic — see below |
| string | |
| string | input basename, display-only |
| string | |
| int|null | |
| int|null | |
| object|null | |
| float|null | element-level |
| string | element text per type-dispatch rules |
| string? | present only on table span-expansion fallback chunks |
chunk_id{doc_id}__p{page_index}_r{reading_order}_e{element_index}{disc}- (the element's position in the
_e{element_index}sort) guarantees inter-element uniqueness even when(page_index, reading_order)isreading_orderor shared by two elements.null - is the intra-element discriminator for elements that emit multiple chunks:
{disc}(table-row),_tr{row}(key-value pairs),_kv{pair_index}(reading-order windows); empty for single-chunk elements._w{window_index} - is
doc_idif supplied, else a short content hash of the input bytes — never the basename, so two same-named files in different directories get disjoint IDs and upsert stays idempotent and tenant-safe.--doc-id
Full spec: .
references/provenance-chunk-schema.md每个JSONL行对应一个分块:
| 字段 | 类型 | 来源 |
|---|---|---|
| string | 确定性生成——详见下文 |
| string | |
| string | 输入文件名,仅用于显示 |
| string | |
| int|null | |
| int|null | |
| object|null | |
| float|null | 元素级别的 |
| string | 根据元素类型规则生成的元素文本 |
| string? | 仅在表格跨列扩展回退分块时出现 |
chunk_id{doc_id}__p{page_index}_r{reading_order}_e{element_index}{disc}- (元素在
_e{element_index}排序中的位置) 确保即使(page_index, reading_order)为null或两个元素共享同一reading_order,元素间仍保持唯一性。reading_order - 是生成多个分块的元素的元素内区分符:
{disc}(表格行)、_tr{row}(键值对)、_kv{pair_index}(阅读顺序窗口);单个分块的元素则为空。_w{window_index} - 若提供
doc_id参数则使用该值,否则为输入字节的短内容哈希——绝不是文件名,因此不同目录下同名文件会获得不同ID,确保插入操作具有幂等性且租户安全。--doc-id
完整规范:。
references/provenance-chunk-schema.mdChunking strategies
分块策略
- (default): one chunk per typed spatial element — the purest expression of the grounding value prop. A
--strategy elementbecomes one whole-table TSV chunk.table - : each table row becomes its own chunk (
--strategy table-row) — better precision on wide financial tables._tr{row} - : sliding window over reading-order-sorted text elements (
--strategy reading-order-windowin tokens,--window-size) — better retrieval coherence for prose, at some provenance precision (a window may span two elements' bboxes)._w{window_index}
- (默认):每个类型化空间元素对应一个分块——最纯粹地体现了溯源价值。一个
--strategy element会成为一个完整表格的TSV分块。table - :每个表格行对应一个独立分块(
--strategy table-row)——在宽幅财务表格上精度更高。_tr{row} - :对按阅读顺序排序的文本元素进行滑动窗口分块(
--strategy reading-order-window为令牌数,--window-size)——对散文类文档的检索连贯性更好,但溯源精度会有所降低(一个窗口可能跨越两个元素的bbox)。_w{window_index}
Cost gate
成本限制
chunk.pypages × mode-costremainingCredits--yes--yesunderstandagenticchunk.py页数 × 模式成本remainingCredits--yesunderstandagentic--yesIllustrative: passing chunks to an embedder
示例:将分块传递给嵌入模型
The boundary is the chunk schema. See for a minimal,
illustrative-only example of loading the JSONL and passing to an embedder while
keeping + + provenance attached to each embedding record. Swap the
provider import for your stack — no embedding library is a dependency of this skill.
examples/embed-chunks-illustrative.pytextchunk_idbboxpage_index边界为分块schema。请查看,这是一个极简的仅作示例的代码片段,展示如何加载JSONL并将传递给嵌入模型,同时将 + + 溯源信息附加到每个嵌入记录中。可根据你的技术栈替换提供商导入——本技能不依赖任何嵌入库。
examples/embed-chunks-illustrative.pytextchunk_idbboxpage_indexAnti-patterns
反模式
- Do not use this skill when raw Markdown is sufficient — use with
document-extraction-api.--output-format markdown - Do not bundle vector-DB or embedding-provider logic into — the boundary is the chunk JSONL.
chunk.py - Do not expect key-value or formula chunks under the default mode — they require
structure.--mode understand - Do not derive from the filename basename — it breaks cross-document collision safety (R15).
doc_id
- 当原始Markdown已满足需求时,请勿使用本技能——请使用带参数的
--output-format markdown。document-extraction-api - 请勿将向量数据库或嵌入提供商逻辑集成到中——边界为分块JSONL。
chunk.py - 请勿期望在默认模式下生成键值对或公式分块——这些需要
structure参数。--mode understand - 请勿从文件名派生——这会破坏跨文档冲突安全性(R15)。
doc_id
Security Hardening Addendum
安全加固补充说明
- Never store in committed files. Use process env injection at runtime (shell/export, secrets manager, or host env).
NUTRIENT_EXTRACT_API_KEY - The output JSONL carries extracted document text (potentially finance/health/legal content) and
is written with permissions. Treat it as sensitive; do not commit it.
0600 - carries the input basename, which may encode PII (e.g.
source_doc). For sensitive corpora, supply a sanitizedpatient-jsmith.pdfand be deliberate about what reaches the index.--doc-id - The script prints credit usage (the numeric cost only) to stderr and never logs the API key.
- 切勿将存储在已提交的文件中。请在运行时通过进程环境注入(shell/export、密钥管理器或主机环境)。
NUTRIENT_EXTRACT_API_KEY - 输出的JSONL包含提取的文档文本(可能包含金融/医疗/法律内容),并以权限写入。请将其视为敏感数据;请勿提交到版本控制系统。
0600 - 包含输入文件名,可能包含PII(例如
source_doc)。对于敏感语料库,请提供经过清理的patient-jsmith.pdf,并谨慎控制哪些信息进入索引。--doc-id - 脚本仅将信用使用情况(仅数字成本)打印到标准错误输出,绝不会记录API密钥。
Rules
规则
- Always require spatial output — Markdown output loses provenance and is rejected.
- Preserve the printed credit-usage summary so the operator can observe per-call cost.
- Reuse 's
document-extraction-apiandcreate_client(); do not re-implement the API call or mode-selection logic.client.parse()
- 始终要求空间输出——Markdown输出会丢失溯源信息,将被拒绝。
- 保留打印的信用使用摘要,以便操作人员查看每次调用的成本。
- 复用的
document-extraction-api和create_client();请勿重新实现API调用或模式选择逻辑。client.parse()
Reference map
参考映射
- — authoritative chunk schema,
references/provenance-chunk-schema.mdderivation, chunking strategies, table span-expansion, key-value mapping.chunk_id - — illustrative embedding snippet (not a supported script).
examples/embed-chunks-illustrative.py - Sibling — mode selection, credit costs, key setup.
document-extraction-api/SKILL.md
- ——权威分块schema、
references/provenance-chunk-schema.md生成规则、分块策略、表格跨列扩展、键值对映射。chunk_id - ——嵌入示例代码片段(非受支持脚本)。
examples/embed-chunks-illustrative.py - 同级目录的——模式选择、信用成本、密钥设置。
document-extraction-api/SKILL.md