RAG and vector index¶
Retrieval-augmented generation (RAG) combines document search with answer generation. ZITon builds a vector index in advance, then retrieves relevant passages when a user asks a question.
AWS Step Functions workflow¶
A new PDF in Amazon S3 starts the workflow through Amazon EventBridge. Step Functions invokes Lambda for orchestration steps and waits for the extraction task in AWS Fargate.
| Stage | States and outcome |
|---|---|
| Registration | RegisterAndValidate checks the PDF signature, calculates a SHA-256 hash, and records the version in DynamoDB. DuplicateDocument stops duplicate processing before extraction. |
| Profiling and extraction | ProfileDocument records the file type and size. ExtractDocumentContent runs an ECS task on Fargate and waits for it. PyMuPDF reads each page, with Tesseract OCR for pages containing little text. |
| Metadata | AnalyzeDocumentMetadata calls Amazon Nova Lite through Bedrock Converse to obtain structured document metadata. MetadataAccepted routes documents needing review through a status update before continuing file preparation. |
| Transformation and quality | TransformDocument prepares Markdown, JSON, and metadata in parallel. ValidateQuality checks that pages exist, are numbered in sequence, and contain text. QualityAccepted stops the workflow on a validation failure. |
| Publication | PublishDocument writes each nonempty page to S3 as a text file with a separate JSON file. The JSON includes a page number, a source PDF link, and available filter attributes such as municipality or document type. |
How a page embedding is created¶
Lambda does not compute vectors. StartKnowledgeBaseIngestion requests an S3 data source sync with StartIngestionJob. CheckKnowledgeBaseIngestion reads the result using GetIngestionJob.
- Read the source. Bedrock Knowledge Bases reads the published text files and their metadata. Each nonempty page is one chunk. Bedrock does not split it again (
chunking_strategy = NONE). - Compute the embedding. Amazon Titan Text Embeddings V2 converts the page text to a 1,024-dimensional vector. Amazon Nova Lite extracts metadata rather than computing this vector.
- Write to the index. Bedrock stores the
float32vector, text, and metadata in Amazon S3 Vectors. Similarity search uses cosine distance, and document attributes can narrow the results.
After starting an ingestion job, Step Functions waits 15 seconds before each status check. COMPLETE finishes the workflow. FAILED or STOPPED leads to a failure state. A SKIPPED result means this run did not start a job: metadata needs review, the source is not configured, or Bedrock is already syncing it. The workflow and the Bedrock job have separate completion statuses.
How ZITon answers a question¶
The RAG API uses the Amazon Bedrock knowledge base to retrieve passages relevant to the question. The generation model receives the question and the retrieved passages as context. Vectors support similarity search. Answer generation is a separate step.