Skip to main content
Process and analyze documents across multiple pages with context preservation and cross-document correlation. Perfect for medical record processing, legal document review, multi-document workflows, and comprehensive document analysis that requires understanding relationships between different document types.

Multi-Page Document Analysis Example

Usage Example

For multi-page analysis, we highly recommend using the Structured Outputs API to get the cross-page correlations and document analysis in a structured and validated data format.
The following examples can analyze and triage multiple pages or documents, identify cross-document relationships, extract consistent information across pages, and provide comprehensive analysis with context preservation. The response schema includes page summaries, cross-document connections, and thematic analysis.
import openai

class DocumentPage(BaseModel):
  page_id: int = Field(..., description="Page number (0-indexed) of the document")
  document_type: Literal["referral", "insurance-card", "identification"] = Field(..., description="Type of the document")

class MultiPageResponse(BaseModel):
  pages: list[DocumentPage] = Field(..., description="Page numbers (0-indexed) of the document")


# Initialize the client
client = openai.OpenAI(
    base_url="https://agent.vlm.run/v1/openai",
    api_key="<VLMRUN_API_KEY>"
)

# Analyze multi-page medical documents
response = client.chat.completions.create(
    model="vlm-agent-1",
    messages=[
        {
          "role": "user",
          "content": [
            {"type": "text", "text": "Analyze this multi-page medical document set. Extract patient referral page, medical insurance card and identification form in 3 separate fields in JSON format."},
            {"type": "image_url", "image_url": {"url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.agent/multi-document-input-example.pdf", "detail": "auto"}}
          ]
        }
    ],
    response_format={"type": "json_schema", "schema": MultiPageResponse.model_json_schema()},
)

# Print the response
print(response.choices[0].message.content)
>>> {"pages": [{"page_id": 0, "document_type": "referral"}, {"page_id": 2, "document_type": "insurance-card"}, {"page_id": 3, "document_type": "identification"}]}

# Validate the response
print(MultiPageResponse.model_validate_json(response.choices[0].message.content))
>>> MultiPageResponse(pages=[DocumentPage(page_id=0, document_type="referral"), DocumentPage(page_id=2, document_type="insurance-card"), DocumentPage(page_id=3, document_type="identification")])

FAQ

  • Cross-Document Correlation: Identify relationships between different document types
  • Data Consistency Checking: Verify data matches across pages and documents
  • Theme Analysis: Track recurring themes and topics across pages
  • Reference Tracking: Follow references and citations across pages
  • Content Flow Analysis: Understand how content flows between pages
  • Medical Records: Referral forms, insurance cards, ID forms, lab reports
  • Legal Documents: Contracts, amendments, exhibits, supporting documents
  • Financial Documents: Invoices, receipts, statements, tax forms
  • Academic Papers: Research papers, appendices, references, figures
  • Business Reports: Executive summaries, detailed sections, appendices
The system identifies connections between different pages/documents by:
  • Data Matching: Finding identical or similar values across documents
  • Reference Tracking: Following explicit references between pages
  • Contextual Analysis: Understanding semantic relationships
  • Confidence Scoring: Providing reliability scores for each connection
The confidence score is a value between 0 and 1 that indicates the reliability of cross-document connections. Higher scores indicate more reliable matches and relationships between pages.
Yes, multi-page analysis can process different document types within a single PDF or across multiple uploaded documents, identifying relationships and correlations between them.