Class CitationDocument
java.lang.Object
org.springframework.ai.anthropic.api.CitationDocument
Builder class for creating citation-enabled documents. Provides a fluent API for
constructing documents of different types that can be converted to ContentBlocks for
the Anthropic API.
Citations allow Claude to reference specific parts of provided documents in its responses. When a citation document is included in a prompt, Claude can cite the source material, and citation metadata (character ranges, page numbers, or content blocks) is returned in the response.
Usage Examples
Plain Text Document:
CitationDocument document = CitationDocument.builder()
.plainText("The Eiffel Tower was completed in 1889 in Paris, France.")
.title("Eiffel Tower Facts")
.build();
AnthropicChatOptions options = AnthropicChatOptions.builder()
.model(AnthropicApi.ChatModel.CLAUDE_3_7_SONNET.getName())
.citationDocuments(document)
.build();
ChatResponse response = chatModel.call(new Prompt("When was the Eiffel Tower built?", options));
// Citations are available in response metadata
List<Citation> citations = (List<Citation>) response.getMetadata().get("citations");
PDF Document:
CitationDocument document = CitationDocument.builder()
.pdfFile("path/to/document.pdf")
.title("Technical Specification")
.build();
// PDF citations include page numbers
Custom Content Blocks:
CitationDocument document = CitationDocument.builder()
.customContent(
"Fact 1: The Great Wall spans 21,196 kilometers.",
"Fact 2: Construction began in the 7th century BC.",
"Fact 3: It was built to protect Chinese states."
)
.title("Great Wall Facts")
.build();
// Custom content citations reference specific content blocks
- Since:
- 1.1.0
- Author:
- Soby Chacko
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for CitationDocument.static enumDocument types supported by Anthropic Citations API. -
Method Summary
Modifier and TypeMethodDescriptionstatic CitationDocument.Builderbuilder()booleanConvert this CitationDocument to a ContentBlock for API usage.
-
Method Details
-
builder
-
toContentBlock
Convert this CitationDocument to a ContentBlock for API usage.- Returns:
- ContentBlock configured for citations
-
isCitationsEnabled
public boolean isCitationsEnabled()
-