Skip to main content

Class Overview

Source: pageindex/utils.py:681

Description

The ConfigLoader class manages configuration for PageIndex, loading defaults from config.yaml and merging them with user-provided options. It provides a centralized way to handle all PageIndex settings with validation and type checking.

Constructor

__init__(default_path=None)

str
default:"None"
Path to the YAML configuration file. If None, defaults to pageindex/config.yaml in the package directory.
Example:

Methods

load(user_opt=None)

Loads configuration by merging user options with default values.
dict, config, or None
default:"None"
User-provided configuration options. Can be:
  • None: Use all defaults
  • dict: Dictionary of config keys/values
  • config (SimpleNamespace): Existing config object
Raises ValueError if unknown keys are provided. Raises TypeError if invalid type is passed.
SimpleNamespace
Configuration object with all settings as attributes. Contains:
  • model: OpenAI model name
  • toc_check_page_num: Pages to check for TOC
  • max_page_num_each_node: Max pages per node
  • max_token_num_each_node: Max tokens per node
  • if_add_node_id: Add node IDs (“yes”/“no”)
  • if_add_node_summary: Generate summaries (“yes”/“no”)
  • if_add_doc_description: Generate doc description (“yes”/“no”)
  • if_add_node_text: Include text (“yes”/“no”)

Default Configuration

The default config.yaml contains:
Source: pageindex/config.yaml:1-8

Configuration Parameters

str
default:"gpt-4o-2024-11-20"
OpenAI model for processing. Supported models:
  • "gpt-4o-2024-11-20" (recommended)
  • "gpt-4o"
  • "gpt-4.1"
  • Other OpenAI chat models
int
default:"20"
Number of pages to scan for table of contents. Increase for documents with TOC appearing later.
int
default:"10"
Maximum pages per node. Larger nodes are recursively subdivided.
int
default:"20000"
Maximum token count per node. Used with max_page_num_each_node to trigger subdivision.
str
default:"yes"
Add sequential node IDs (“0001”, “0002”, etc.). Values: "yes" or "no"
str
default:"yes"
Generate AI summaries for each node. Values: "yes" or "no"
Enabling summaries significantly increases processing time and API costs.
str
default:"no"
Generate one-sentence document description. Values: "yes" or "no"Only works if if_add_node_summary="yes"
str
default:"no"
Include full text content in each node. Values: "yes" or "no"
Including text increases memory usage and output file size significantly.

Example Usage

Basic Usage - All Defaults

Partial Override

Custom Config File

Validation

Accessing Configuration

Creating Config from Scratch

Creating Custom config.yaml

You can create your own configuration file:
Then load it:

Performance Recommendations

Fast Processing (Structure Only)

Balanced (With Summaries)

Full Features (Slowest)

Error Handling

See Also