Skip to main content
The Split.Run() method divides documents into sections based on descriptions you provide. You define what sections to look for, and Split identifies which pages belong to each section.
The Go SDK (v0.1.0-alpha.1) has a type definition mismatch for Split responses. The splits array is returned in the API response but not typed in the SDK. Use the raw JSON to access split results reliably.

Basic Usage

package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    
    reducto "github.com/reductoai/reducto-go-sdk"
    "github.com/reductoai/reducto-go-sdk/option"
    "github.com/reductoai/reducto-go-sdk/shared"
)

func main() {
    client := reducto.NewClient(option.WithAPIKey(os.Getenv("REDUCTO_API_KEY")))
    
    // Split the document - split_description is required
    result, err := client.Split.Run(context.Background(), reducto.SplitRunParams{
        DocumentURL: reducto.F[reducto.SplitRunParamsDocumentURLUnion](
            shared.UnionString("https://example.com/document.pdf"),
        ),
        SplitDescription: reducto.F([]shared.SplitCategoryParam{
            {
                Name:        reducto.F("Summary"),
                Description: reducto.F("Executive summary or overview section"),
            },
            {
                Name:        reducto.F("Financial Data"),
                Description: reducto.F("Tables with financial figures"),
            },
        }),
    })
    if err != nil {
        fmt.Printf("Split error: %v\n", err)
        return
    }
    
    // Parse raw JSON to access splits (SDK type limitation workaround)
    var splitResult struct {
        Splits []struct {
            Name       string  `json:"name"`
            Pages      []int64 `json:"pages"`
            Conf       string  `json:"conf"`
            Partitions []interface{} `json:"partitions"`
        } `json:"splits"`
    }
    
    rawJSON := result.JSON.RawJSON()
    // Extract the result portion
    var fullResult map[string]json.RawMessage
    json.Unmarshal([]byte(rawJSON), &fullResult)
    json.Unmarshal(fullResult["result"], &splitResult)
    
    // Access splits
    for _, split := range splitResult.Splits {
        fmt.Printf("Section: %s\n", split.Name)
        fmt.Printf("Pages: %v\n", split.Pages)
        fmt.Printf("Confidence: %s\n", split.Conf)
    }
}

Method Signatures

Synchronous Split

func (s *SplitService) Run(
    ctx context.Context,
    body SplitRunParams,
    opts ...option.RequestOption,
) (*shared.SplitResponse, error)

Asynchronous Split

func (s *SplitService) RunJob(
    ctx context.Context,
    body SplitRunJobParams,
    opts ...option.RequestOption,
) (*SplitRunJobResponse, error)

Parameters

SplitRunParams

FieldTypeRequiredDescription
DocumentURLSplitRunParamsDocumentURLUnionYesFile URL, reducto:// file ID, or jobid:// reference
SplitDescription[]shared.SplitCategoryParamYesList of sections to identify
SplitRulesstringNoNatural language prompt for classification rules
AdvancedOptionsshared.AdvancedProcessingOptionsParamNoAdvanced processing options
Optionsshared.BaseProcessingOptionsParamNoBase processing options

SplitCategoryParam

Each split category requires:
shared.SplitCategoryParam{
    Name:         reducto.F("Section Name"),
    Description:  reducto.F("Description of what this section contains"),
    PartitionKey: reducto.F("optional_partition_key"),  // Optional
}

Configuration Examples

With Partition Key

Use PartitionKey when a section type repeats multiple times:
result, err := client.Split.Run(context.Background(), reducto.SplitRunParams{
    DocumentURL: reducto.F[reducto.SplitRunParamsDocumentURLUnion](
        shared.UnionString(upload.FileID),
    ),
    SplitDescription: reducto.F([]shared.SplitCategoryParam{
        {
            Name:         reducto.F("Invoice"),
            Description:  reducto.F("Individual invoice with line items"),
            PartitionKey: reducto.F("invoice_number"),
        },
    }),
})

With Split Rules

result, err := client.Split.Run(context.Background(), reducto.SplitRunParams{
    DocumentURL: reducto.F[reducto.SplitRunParamsDocumentURLUnion](
        shared.UnionString(upload.FileID),
    ),
    SplitDescription: reducto.F([]shared.SplitCategoryParam{
        {Name: reducto.F("Summary"), Description: reducto.F("Executive summary")},
        {Name: reducto.F("Details"), Description: reducto.F("Detailed content")},
    }),
    SplitRules: reducto.F("Pages can belong to multiple sections if they contain content from both."),
})

Response Structure

Due to SDK type limitations, access the response via raw JSON:
// API Response structure (access via raw JSON)
type SplitResult struct {
    Splits []struct {
        Name       string        `json:"name"`       // Section name you defined
        Pages      []int64       `json:"pages"`      // Page numbers (1-indexed)
        Conf       string        `json:"conf"`       // "high" or "low"
        Partitions []interface{} `json:"partitions"` // Sub-sections (if partition_key used)
    } `json:"splits"`
}

Error Handling

result, err := client.Split.Run(context.Background(), params)
if err != nil {
    fmt.Printf("Split failed: %v\n", err)
    return
}

Next Steps