Skip to main content

Configuration Options

When creating a new Extraction Agent, the schema is the most important part. However, there are a few other options that can significantly impact the extraction process.

  • Extraction Mode: The mode of extraction to use. Can be either FAST, BALANCED, MULTIMODAL, or PREMIUM. The default is BALANCED. You can start here and switch to MULTIMODAL/PREMIUM for higher accuracy, if needed. FAST mode is suitable for simpler documents with no OCR and limited tabular extraction and is the fastest mode. MULTIMODAL mode is suitable for visually rich documents with a mix of text, tables, and images. PREMIUM mode does OCR, complex table/header and layout detection and is suitable for documents that require the highest accuracy.
  • System Prompt: Any additional system level instructions for the extraction agent. Note that you should use the schema descriptions to pass field-level instructions, few-shot examples, formatting instructions, etc.
  • Extraction Target: Whether to use the schema on a per-page basis or on the entire document. For the per-page mode, the schema is applied to each page of the document and an array of results is returned.
  • Page Range: Specify which pages to extract from by providing comma-separated page numbers or ranges (1-based indexing). For example, use 1,3,5-7,9 to extract pages 1, 3, pages 5 through 7, and page 9. You can also use ranges like 1-3,8-10 to extract the first three pages and pages 8 through 10. Page numbers are 1-based, meaning the first page is page 1. This option is useful when you only need to extract data from specific sections of large documents.

Advanced Options

These features are currently available under Advanced Settings in the UI.

  • Chunk Mode: Controls how the document is split for processing when dealing with large documents that exceed context limits. Choose between:

    • PAGE: Each page becomes a separate chunk for processing (default)
    • SECTION: Document is split into semantic sections based on content structure like headers and natural boundaries Use the ExtractConfig.chunk_mode argument from the SDK to configure this option.
  • High Resolution Mode: Enable high resolution processing for better accuracy on small text and fine details. This option improves OCR quality and uses higher resolution for document pages. Use the ExtractConfig.high_resolution_mode argument from the SDK to enable this feature. Warning: This can slow down extraction processing time, use only when needed.

  • Invalidate Cache: Purge cached results and rerun the full extraction. By default, LlamaExtract caches parsing results for 48 hours. Enable this option to bypass the cache and ensure fresh processing, which will incur fresh billing charges. Use the ExtractConfig.invalidate_cache argument from the SDK to enable cache invalidation.

Extensions

For additional extraction features that provide enhanced metadata and insights, see the Extensions page which covers:

  • Citations: Source tracing for extracted fields
  • Reasoning: Explanations for extraction decisions
  • Confidence Scores: Quantitative confidence measures

These extensions return additional metadata in the extraction_metadata field but may impact processing time.

Setting Configuration Options

You can configure these options when creating an extraction agent using either the REST API or Python SDK.

Python SDK

First, install the Python SDK:

pip install llama-cloud-services

Here's how to set various configuration options:

from llama_cloud_services import LlamaExtract
from llama_cloud import ExtractConfig, ExtractMode, ChunkMode, ExtractTarget

# Initialize the client
extract = LlamaExtract(api_key="YOUR_API_KEY")

# Define your schema
schema = {
"type": "object",
"properties": {
"company_name": {"type": "string", "description": "Name of the company"},
"revenue": {"type": "number", "description": "Annual revenue in USD"}
}
}

# Create extraction configuration
config = ExtractConfig(
# Basic options
extraction_mode=ExtractMode.MULTIMODAL, # FAST, BALANCED, MULTIMODAL, PREMIUM
extraction_target=ExtractTarget.PER_DOC, # PER_DOC, PER_PAGE
system_prompt="Focus on the most recent financial data",
page_range="1-5,10-15", # Extract from specific pages

# Advanced options
chunk_mode=ChunkMode.PAGE, # PAGE, SECTION
high_resolution_mode=True, # Enable for better OCR
invalidate_cache=False, # Set to True to bypass cache

# Extensions (see Extensions page for details)
cite_sources=True, # Enable citations
use_reasoning=True, # Enable reasoning (not available in FAST mode)
confidence_scores=True # Enable confidence scores (MULTIMODAL/PREMIUM only)
)

# Create extraction agent with configuration
agent = extract.create_agent(
name="Financial Data Extractor",
data_schema=schema,
config=config
)

# Extract from a document
result = agent.extract("your-document.pdf")
print(result.data)

REST API

You can also configure these options using the REST API when creating an extraction agent:

curl -X 'POST' \
'https://api.cloud.llamaindex.ai/api/v1/extraction/extraction-agents' \
-H 'accept: application/json' \
-H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"name": "Financial Data Extractor",
"data_schema": {
"type": "object",
"properties": {
"company_name": {"type": "string", "description": "Name of the company"},
"revenue": {"type": "number", "description": "Annual revenue in USD"}
}
},
"config": {
"extraction_mode": "MULTIMODAL",
"extraction_target": "PER_DOC",
"system_prompt": "Focus on the most recent financial data",
"page_range": "1-5,10-15",
"chunk_mode": "PAGE",
"high_resolution_mode": true,
"invalidate_cache": false,
"cite_sources": true,
"use_reasoning": true,
"confidence_scores": true
}
}'

Configuration Reference

OptionTypeDefaultDescription
extraction_modestring"BALANCED"Processing mode: FAST, BALANCED, MULTIMODAL, PREMIUM
extraction_targetstring"PER_DOC"Extraction scope: PER_DOC, PER_PAGE
system_promptstringnullAdditional system-level instructions
page_rangestringnullPage numbers/ranges to extract (1-based, e.g., "1,3,5-7")
chunk_modestring"PAGE"Document chunking strategy: PAGE, SECTION
high_resolution_modebooleanfalseEnable high-resolution processing
invalidate_cachebooleanfalseBypass cached results
cite_sourcesbooleanfalseEnable source citations
use_reasoningbooleanfalseEnable extraction reasoning
confidence_scoresbooleanfalseEnable confidence scores (MULTIMODAL/PREMIUM only)

Note: Some options like confidence_scores are only available in specific extraction modes. See the individual option descriptions above for details.