Skip to content

Token Reduction

Reduce token count while preserving meaning for LLM pipelines.

Set the reduction mode on token_reduction (a TokenReductionOptions).

Mode Effect
off No reduction; text returned as-is.
light Remove only the most common stopwords.
moderate Balanced stopword removal and redundancy filtering.
aggressive Aggressive filtering; may remove less common content words.
maximum Maximum compression; prioritizes brevity over completeness.
Python
from xberg import ExtractionConfig, TokenReductionOptions
config: ExtractionConfig = ExtractionConfig(
token_reduction=TokenReductionOptions(
mode="moderate",
preserve_important_words=True,
)
)
Python
import asyncio
from xberg import ExtractInput, extract, ExtractionConfig, TokenReductionOptions
async def main() -> None:
config: ExtractionConfig = ExtractionConfig(
token_reduction=TokenReductionOptions(
mode="moderate", preserve_important_words=True
)
)
result = await extract(ExtractInput(uri="verbose_document.pdf"), config)
print(f"Reduced content length: {len(result.results[0].content)} chars")
asyncio.run(main())