Document Summarisation
Generate a one-paragraph summary of extracted documents for search snippets, indexing, or quick reviews. Choose extractive summarization for deterministic, network-free local processing, or abstractive for fluent, AI-generated prose.
Backends
Section titled “Backends”| Strategy | Cargo feature | Network | Quality | Latency |
|---|---|---|---|---|
Extractive (default) |
summarization |
None — fully local | Sentence-level selection from source | < 100 ms typical |
Abstractive |
summarization-llm |
LLM provider | Generates novel prose, can summarise across sentences | Provider-dependent |
When to Use
Section titled “When to Use”- You need a one-paragraph TL;DR for indexing or search snippets.
- You need a deterministic, network-free summary (extractive only).
- You need a fluent abstractive summary for downstream LLM consumption.
When Not to Use
Section titled “When Not to Use”- You need full per-section summaries. Chunk the document first and summarise each chunk separately.
- You need cross-document summarisation. Summarise per document, then summarise the summaries with the LLM backend.
Configuration
Section titled “Configuration”import asynciofrom xberg import ExtractInput, extract, ExtractionConfig, SummarizationConfig
async def main() -> None: config = ExtractionConfig( summarization=SummarizationConfig( strategy="extractive", max_tokens=200, ), ) result = await extract(ExtractInput(uri="report.pdf"), config) if result.results[0].summary: print(result.results[0].summary.text)
asyncio.run(main())import { extract } from '@xberg-io/xberg';
const output = await extract({ kind: "uri", uri: "report.pdf",}, { summarization: { strategy: "extractive", maxTokens: 200, },});if (output.results[0].summary) { console.log(output.results[0].summary.text);}use xberg::{extract, ExtractionConfig, ExtractInput, SummarizationConfig};use xberg::types::summary::SummaryStrategy;
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let config = ExtractionConfig { summarization: Some(SummarizationConfig { strategy: SummaryStrategy::Extractive, max_tokens: Some(200), llm: None, }), ..Default::default() }; let output = extract(ExtractInput::from_uri("report.pdf"), &config).await?; if let Some(summary) = &output.results[0].summary { println!("{}", summary.text); } Ok(())}[summarization]strategy = "extractive"max_tokens = 200Abstractive Backend
Section titled “Abstractive Backend”Switch the strategy and attach an LlmConfig:
import asynciofrom xberg import ExtractInput, extract, ExtractionConfig, SummarizationConfig, LlmConfig
async def main() -> None: config = ExtractionConfig( summarization=SummarizationConfig( strategy="abstractive", max_tokens=300, llm=LlmConfig(model="openai/gpt-4o-mini"), ), ) result = await extract(ExtractInput(uri="report.pdf"), config) if result.results[0].summary: print(result.results[0].summary.text)
asyncio.run(main())The model receives the extracted content and returns the summary verbatim. Token usage records in ExtractedDocument.llm_usage with source = "summarisation_abstractive".
max_tokens Semantics
Section titled “max_tokens Semantics”| Strategy | What max_tokens caps |
|---|---|
Extractive |
Loose whitespace tokens in the output summary. The TextRank selector stops appending sentences once it would exceed the cap. |
Abstractive |
A prompt hint asking the model for approximately this many tokens — not a provider hard cap. The provider’s request limit comes separately from SummarizationConfig.llm.max_tokens. |
Leave None to let the backend pick a sensible default.
Output Shape
Section titled “Output Shape”{ "summary": { "text": "The contract sets out a 3-year support agreement with quarterly billing and a fixed escalation cap of 4%.", "strategy": "extractive", "token_count": 19 }}Provider Setup (Abstractive Only)
Section titled “Provider Setup (Abstractive Only)”Pick any liter-llm provider — see LLM Integration. For most documents, gpt-4o-mini, claude-3-5-haiku, or google/gemini-2.0-flash give good cost / quality trade-offs.
API-key precedence:
SummarizationConfig.llm.api_keyXBERG_LLM_API_KEY- Per-provider env var
Related
Section titled “Related”- LLM Integration — provider matrix, API-key precedence
- Document Translation — sibling LLM post-processor
- Configuration Reference