Summarize a document
POST/v2/corpora/:corpus_key/documents/:document_id/summarize
Generates a concise summary of a single document. The summary captures essential insights without requiring you to review the entire document manually. This API is a tech preview.
- Enable streaming for large documents to receive summaries incrementally.
- Customize
prompt_templateto fine-tune summary output for specific domains. - Use standard responses for small documents where streaming is unnecessary.
- Monitor streaming events to track the progress of real-time summarization.
The document length is limited by the context window of your selected LLM.
Response formats
The platform supports two response modes:
- Standard: Returns a complete summary in one response.
- Streaming: Returns incremental responses using Server-Sent Events (SSE).
Non-streaming response
In standard mode, the platform returns a structured response that contains the complete summary of the document. The summary field contains the generated text.
Streaming response
For streaming responses, the platform returns Server-Sent Events (SSE). The first event begins streaming partial results as soon as they are available. The final event marks the end of the summarization process.
The streamed response consists of multiple events:
generation_info: Contains therendered_promptwhich is the compiled prompt sent to the LLM for document summarization.generation_chunk: Returns a partial chunk of the generated summary.generation_end: Marks the completion of the summary generation.error: Returns an error message if summarization fails.end: Indicates the end of the streaming session.
Prompt template example
When you craft a prompt, you can access your document with the $vectaraDocument field. This example shows a simple prompt:
{
"role": "user",
"content": "Summarize the document: \$vectaraDocument.json()"
}
The document also has the following methods to support custom prompts.
$vectaraDocument.json(): Returns a JSON representation of the whole document.$vectaraDocument.id(): Returns the unique identifier of the document (document_id).$vectaraDocument.metadata(): Returns metadata from the document.
For example,$vectaraDocument.metadata().get("key")retrieves a specific metadata value by key.$vectaraDocument.parts(): Returns an array of document parts that you can loop through.
For example,#foreach ($part in $vectaraDocument.parts()).$part.text(): Returns the text of the part.$part.metadata(): Returns the metadata of a part.$part.hasTable(): Indicates whether the part contains a table.$part.table(): Returns the table within the part. For example, use$part.table().json()to retrieve the table in JSON format.
Request
Responses
- 200
- 403
- 404
Document summarization response on success.
Permissions do not allow summarizing a document in the corpus.
Corpus or document not found.