> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jinba.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Reducto

> Reducto API でドキュメントをパース・抽出・分割する

## 概要

Reducto ツールは、[Reducto](https://reducto.ai/) API を使って PDF・画像・スプレッドシートなどのドキュメントを処理する機能を提供します。Reducto は OCR、レイアウト検出、テーブル抽出、RAG 向けに最適化されたチャンキングを提供しており、非構造化ドキュメントをフロー内でテキスト・構造化 JSON・論理的なセクションに変換できます。

## 主な機能

* `REDUCTO_UPLOAD`
  * ファイルを Reducto にアップロードし、他の Reducto ツールで使用できる `reducto://` URL を取得します。
  * 入力: `file_url`（公開 URL または署名付き URL）、任意の `extension` ヒント（例: `pdf`、`docx`）。
  * 出力: `file_id` と `reducto_url`。
* `REDUCTO_PARSE`
  * ドキュメントをパースし、レイアウトを認識したチャンキング付きでテキスト・テーブル・図表を抽出します。
  * 入力: `document_url`（公開 URL、署名付き S3 URL、または `reducto://` URL）に加え、`chunk_mode`（`variable`、`section`、`page`、`disabled`、`block`、`page_sections`。デフォルトは `disabled`）、`chunk_size`（250〜1500 文字）、`table_output_format`（`html`、`json`、`md`、`jsonbbox`、`dynamic`、`csv`。デフォルトは `dynamic`）、`add_page_markers`、`merge_tables`、`ocr_system`（`standard` / `legacy`）、`extraction_mode`（`ocr` / `hybrid`）、`page_range`（例: `"1-5"`、`"1,3,5"`、`"1-3,7-9"`）、暗号化ファイル用の `document_password` などのオプション。
  * 出力: `job_id`、`num_pages`、およびコンテンツブロックを含む `chunks` の配列。
* `REDUCTO_EXTRACT`
  * ユーザー定義の JSON Schema を使って、ドキュメントから特定のフィールドを構造化 JSON として抽出します。請求書、フォーム、契約書に最適です。
  * 入力: `document_url`、`schema`（JSON Schema 文字列）、任意の `system_prompt`、`array_extract`（請求書の明細行など繰り返しデータ向け）、`include_images`、`optimize_for_latency`、`citations_enabled`。
  * 出力: `extracted_data` に加え、`job_id`、`num_pages`、`num_fields`。
* `REDUCTO_SPLIT`
  * 自然言語のカテゴリ記述を使って、ドキュメントをセクションに分割します。
  * 入力: `document_url`、`split_description`（`{"name": ..., "description": ...}` 形式のカテゴリの JSON 配列）、任意の `split_rules`（自然言語による分割ルール）、`table_cutoff`（ページ境界のテーブルの扱い。`truncate` / `preserve`）。
  * 出力: `num_pages` と `splits`（各要素は `name`、`pages`、`confidence` を持つ）。

## 認証

すべての Reducto ツールは、各ステップの config に `api_key` として設定する Reducto API キーを必要とします。キーはシークレット（例: `REDUCTO_API_KEY`）として保存し、`{{secrets.REDUCTO_API_KEY}}` で参照してください。

**注意**: API キーは機密情報として扱い、公開リポジトリには絶対にコミットしないでください。

### 例：PDF をパースして要約する

```yaml theme={null}
- id: upload_report
  name: upload_report
  tool: REDUCTO_UPLOAD
  config:
    - name: api_key
      value: "{{secrets.REDUCTO_API_KEY}}"
  input:
    - name: file_url
      value: "{{steps.input_file.result.url}}"
    - name: extension
      value: pdf

- id: parse_report
  name: parse_report
  tool: REDUCTO_PARSE
  config:
    - name: api_key
      value: "{{secrets.REDUCTO_API_KEY}}"
  input:
    - name: document_url
      value: "{{steps.upload_report.result.reducto_url}}"
    - name: chunk_mode
      value: page
    - name: table_output_format
      value: md
    - name: add_page_markers
      value: true

- id: summarize_report
  name: summarize_report
  tool: OPENAI_INVOKE
  config:
    - name: version
      value: gpt-4
  input:
    - name: prompt
      value: |
        以下のドキュメントを要約してください。重要な数値とテーブルを強調してください。

        {{steps.parse_report.result.chunks}}
```

### 例：請求書から構造化データを抽出する

```yaml theme={null}
- id: extract_invoice
  name: extract_invoice
  tool: REDUCTO_EXTRACT
  config:
    - name: api_key
      value: "{{secrets.REDUCTO_API_KEY}}"
  input:
    - name: document_url
      value: "https://example.com/invoice.pdf"
    - name: schema
      value: '{"type":"object","properties":{"invoice_number":{"type":"string"},"total":{"type":"number"}}}'
    - name: array_extract
      value: true
```

## 注意事項

* `document_url` には公開 URL、署名付き S3 URL、`reducto://` URL を指定できます。Reducto から直接アクセスできないファイルの場合は、先に `REDUCTO_UPLOAD` を実行し、返された `reducto_url` を他のツールに渡してください。
* `REDUCTO_PARSE` のデフォルト: チャンキングは `disabled`、テーブル形式は `dynamic`、OCR システムは `standard`（多言語対応。`legacy` はゲルマン系言語のみ対応）、抽出モードは `hybrid`（OCR とネイティブテキストの組み合わせ）です。
* `page_range` は 1 始まりで、範囲指定とカンマ区切りの併用が可能です（例: `"1-3,7-9"`）。
* `schema`（`REDUCTO_EXTRACT`）と `split_description`（`REDUCTO_SPLIT`）は有効な JSON 文字列である必要があります。パースできない場合、ステップはエラーになります。
* API エラー時には、HTTP ステータスと生のレスポンスを含むエラーオブジェクトが返され、実行ログで確認できます。
