1---2name: document-granular-decompose3description: Upload local documents to TianGong AI Unstructure `/mineru_with_images` API for fine-grained parsing and return only plain fulltext content. Use when a task needs document fulltext extraction with `return_txt=true`, strict file-type allowlist validation, API base URL/auth token from environment variables, and optional provider/model overrides.4---5
6# Document Granular Decompose
7
8## Core Goal
9- Parse a local document through `POST /mineru_with_images`.
10- Always force `return_txt=true`.
11- Read environment variables for endpoint, request identity, and model routing:
12 - `UNSTRUCTURED_API_BASE_URL` (example: `https://your-unstructured-host:7770`)
13 - `UNSTRUCTURED_AUTH_TOKEN`
14 - `UNSTRUCTURED_PROVIDER` (optional)
15 - `UNSTRUCTURED_MODEL` (optional)
16- Return only plain fulltext (prefer API `txt`; fallback to joined `result[].text`).
17
18## Triggering Conditions
19- Need robust document fulltext extraction for PDF/Office/image files.
20- Need image-aware MinerU parsing but only textual output for downstream chunking/search/summarization.
21- Need to standardize provider/model/token input via environment variables instead of ad-hoc command parameters.
22
23## Workflow
241. Prepare environment variables.
25
26```bash
27export UNSTRUCTURED_AUTH_TOKEN="your-fastapi-bearer-token"
28export UNSTRUCTURED_API_BASE_URL="https://your-unstructured-host:7770"
29# Optional routing overrides. Omit them to let the server choose its defaults.
30export UNSTRUCTURED_PROVIDER="vllm"
31export UNSTRUCTURED_MODEL="Qwen/Qwen3.5-122B-A10B-FP8"
32```
33
342. Run extraction and print fulltext to stdout.
35
36```bash
37python3 scripts/mineru_fulltext_extract.py \
38 --file "/absolute/path/to/document.pdf"
39```
40
413. Save fulltext to a local file when needed.
42
43```bash
44python3 scripts/mineru_fulltext_extract.py \
45 --file "/absolute/path/to/document.pdf" \
46 --output "/absolute/path/to/fulltext.txt"
47```
48
49## Request Contract
50- Endpoint resolution:
51 - `--api-url` if provided
52 - else `UNSTRUCTURED_API_BASE_URL + /mineru_with_images`
53 - else fail fast with missing environment variable error
54- Method: `POST` multipart form.
55- Query params:
56 - Force `return_txt=true` (always set by script).
57- Form fields sent:
58 - `file` (required)
59 - `provider` (optional, from `UNSTRUCTURED_PROVIDER` when set)
60 - `model` (optional, from `UNSTRUCTURED_MODEL` when set)
61- Header sent:
62 - `Authorization: Bearer $UNSTRUCTURED_AUTH_TOKEN`
63
64## Supported File Types (Strict)
65- Supported file types:
66 - `.bmp, .doc, .docm, .docx, .dot, .dotx, .gif, .jp2, .jpeg, .jpg, .odp, .odt, .pdf, .png, .pot, .potx, .pps, .ppsx, .ppt, .pptm, .pptx, .tiff, .webp, .xls, .xlsm, .xlsx, .xlt, .xltx`
67- Office formats:
68 - `.doc, .docm, .docx, .dot, .dotx, .odp, .odt, .pot, .potx, .pps, .ppsx, .ppt, .pptm, .pptx, .xls, .xlsm, .xlsx, .xlt, .xltx`
69- Any other extension is rejected before sending API requests.
70
71## Output Rules
72- Success output must be plain text fulltext only.
73- Normalize the confirmed upstream Markdown underscore escape (`\_` to `_`)
74 in both supported response paths; preserve other backslashes and escapes.
75- Fulltext source priority:
76 1. `response.txt`
77 2. join non-empty `response.result[].text` by blank lines
78- Do not output chunk metadata/json unless the user explicitly requests debugging.
79
80## Error Handling
81- Missing required env vars (`UNSTRUCTURED_API_BASE_URL`, `UNSTRUCTURED_AUTH_TOKEN`): fail fast with actionable message.
82- Missing `UNSTRUCTURED_PROVIDER` or `UNSTRUCTURED_MODEL`: omit the form field and let the service choose its default.
83- HTTP 401/403: report token/auth issue.
84- HTTP 4xx/5xx: print status and API error body if available.
85- Missing text in response: fail with explicit schema mismatch error.
86
87## References
88- `references/env.md`
89- `references/request-response.md`
90
91## Assets
92- `assets/config.example.env`
93
94## Scripts
95- `scripts/mineru_fulltext_extract.py`