Skip to main content

Overview

PageIndex can be configured through:
  1. CLI arguments when using run_pageindex.py
  2. Function parameters when using the Python API
  3. Config file (config.yaml) for default values

Configuration Methods

CLI Configuration

Programmatic Configuration (PDF)

Programmatic Configuration (Markdown)

Default Configuration File

PageIndex reads defaults from pageindex/config.yaml:

Universal Parameters

These parameters apply to both PDF and Markdown processing.

Model Configuration

string
default:"gpt-4o-2024-11-20"
The LLM model to use for structure extraction (PDF) and summary generation.Supported Models:
  • gpt-4o-2024-11-20 (recommended)
  • gpt-4o
  • gpt-4-turbo
  • Any OpenAI-compatible model endpoint
CLI:
Python (PDF):
Python (Markdown):

Content Enrichment

string
default:"yes"
Whether to add unique node IDs to each section in the tree.Options: yes, noExample Output with yes:
CLI:
Python:
Node IDs are essential for retrieval systems to reference specific sections.
string
default:"yes"
Whether to generate AI-powered summaries for each node.Options: yes, noExample Output:
CLI:
Python:
Enabling summaries increases processing time and API costs significantly (1 LLM call per node).
string
default:"no"
Whether to generate an overall description of the entire document.Options: yes, noExample Output:
CLI:
Python:
Requires if_add_node_summary=yes to function.
string
default:"no"
Whether to include the full text content of each section in the output.Options: yes, noExample Output:
CLI:
Python:
Including full text significantly increases output file size.

PDF-Only Parameters

These parameters only apply when processing PDF documents.

TOC Detection

integer
default:"20"
Number of pages to scan from the beginning for table of contents detection.CLI Name: --toc-check-pagesUse Cases:
  • Default (20): Works for most documents
  • 30-50: Documents with long, multi-page TOCs
  • 5-10: Short documents or those without TOCs
CLI:
Python:

Node Size Limits

integer
default:"10"
Maximum number of pages allowed per node before recursive subdivision.CLI Name: --max-pages-per-nodeWhen a node exceeds this page count AND the token limit, PageIndex will:
  1. Extract sub-structure from that node
  2. Recursively subdivide until all nodes are within limits
Guidelines:
  • Small (5-8 pages): Fine-grained retrieval, more nodes
  • Medium (10-15 pages): Balanced approach (recommended)
  • Large (20+ pages): Faster processing, coarser structure
CLI:
Python:
integer
default:"20000"
Maximum number of tokens allowed per node before recursive subdivision.CLI Name: --max-tokens-per-nodeThis works in conjunction with max_page_num_each_node. A node is subdivided if it exceeds BOTH limits.Guidelines:
  • Small (10000-15000 tokens): Detailed structure
  • Medium (20000-30000 tokens): Balanced (recommended)
  • Large (40000+ tokens): Minimal subdivision
CLI:
Python:
Tokens are counted using the specified model’s tokenizer.

Markdown-Only Parameters

These parameters only apply when processing Markdown documents.

Tree Thinning

string | boolean
default:"no"
Whether to apply tree thinning to merge small sections with their parents.CLI Options: yes, no
Python Options: True, False
How It Works:
  1. Calculate total tokens for each node (including all descendants)
  2. If total < threshold, merge children into parent
  3. Remove child nodes from tree structure
CLI:
Python:
Use thinning for documents with many small subsections that should be treated as cohesive units.
integer
default:"5000"
Minimum token count for keeping a section and its children separate (used with tree thinning).CLI Name: --thinning-thresholdSections with total tokens (including descendants) below this threshold will be merged into their parent.Guidelines:
  • 2000-3000: Aggressive merging, flatter tree
  • 5000-8000: Balanced approach (recommended)
  • 10000+: Minimal merging, preserve structure
CLI:
Python:
integer
default:"200"
Token threshold below which full text is used instead of generating a summary.CLI Name: --summary-token-thresholdFor short sections, the full text is often more useful than a summary. This parameter defines that threshold.Guidelines:
  • 100-150: Only very short sections use full text
  • 200-300: Balanced approach (recommended)
  • 500+: Most sections get summaries instead of full text
CLI:
Python:
Only applies when if_add_node_summary=yes.

Configuration Precedence

When parameters are specified in multiple places, PageIndex uses this priority order:
  1. CLI arguments / Function parameters (highest priority)
  2. Environment variables (if applicable)
  3. config.yaml file (lowest priority)

Example

If config.yaml has:
And you run:
Result:
  • model: gpt-4o-2024-11-20 (from config.yaml)
  • if_add_node_summary: no (from CLI argument, overrides config)

Common Configuration Patterns

Fast Processing (Minimal Enrichment)

Use Case: Quick structure extraction without summaries.
Cost: Minimal (structure extraction only)
Speed: Fast
Use Case: Good balance of detail and processing time.
Cost: Moderate (1 LLM call per node)
Speed: Moderate

Maximum Detail

Use Case: Complete extraction with all metadata.
Cost: High (many LLM calls)
Speed: Slow

Markdown with Thinning

Use Case: Simplify markdown structure by merging small sections.
Cost: Moderate
Speed: Fast (fewer nodes to summarize)

Environment Variables

PageIndex uses these environment variables:
string
required
Your OpenAI API key for LLM calls.
string
Custom API endpoint (for OpenAI-compatible services).

Tips & Best Practices

Start Simple: Begin with default settings, then adjust based on results.
Token Limits: Keep max_token_num_each_node under your model’s context window (typically 128K for GPT-4).
Cost Control: Enabling if_add_node_summary=yes can generate hundreds of LLM calls for large documents. Monitor your API usage.
Output Size: If your JSON output is too large, consider:
  • Setting if_add_node_text=no
  • Increasing node size limits to create fewer nodes
  • Using summaries instead of full text
Markdown Thinning: Experiment with thinning-threshold values. Check the output structure after thinning to ensure it meets your needs.

Next Steps