# aws-samples/rag-with-amazon-bedrock-and-pgvector architecture

> Architecture diagram of the GitHub repository aws-samples/rag-with-amazon-bedrock-and-pgvector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/rag-with-amazon-bedrock-and-pgvector
- Repository: https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector

## Overview

This repository is an AWS-hosted RAG sample: users authenticate and ask questions in a Streamlit app, which retrieves relevant PGVector content and generates answers with Amazon Bedrock. A separate ingestion workflow turns knowledge-base PDFs into indexed vectors. The README documents the ingestion stages and AWS hosting/authentication; sampled code confirms key app, queue, and database-update behavior, but not every infrastructure connection.

Main entry points: [`lambda/pgvector-update/app.py`](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pgvector-update/app.py) (Vector index updater), [`rag-app/pgvec_chat_bedrock.py`](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/rag-app/pgvec_chat_bedrock.py) (Bedrock chat chain), [`lambda/pdf-processor/lambda_function.py`](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pdf-processor/lambda_function.py) (PDF text extraction), [`lib/base-infra-stack.ts`](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts) (HTTPS load balancer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_application["Question answering"]
  node_rag_app["Streamlit RAG app<br/>[app.py]"]
  node_chat_chain["Bedrock chat chain"]
  node_pgvector[("PGVector on RDS<br/>[rds-stack.ts]")]
end

subgraph group_ingestion["Document ingestion"]
  node_knowledge_bucket[("PDF knowledge bucket")]
  node_pdf_processor["PDF text extraction<br/>[lambda_function.py]"]
  node_processed_bucket[("Processed text bucket")]
  node_pgvector_trigger["Indexing event trigger<br/>[app.py]"]
  node_pgvector_queue["Indexing queue"]
  node_pgvector_update["Vector index updater<br/>[app.py]"]
end

subgraph group_platform["AWS platform"]
  node_alb["HTTPS load balancer"]
  node_cognito["Cognito authentication"]
  node_app_client_trigger["Cognito client trigger<br/>[app.py]"]
  node_callback_init["Callback URL setup<br/>[app.py]"]
  node_callback_update["Callback URL updater<br/>[app.py]"]
end

subgraph group_provisioning["Database provisioning"]
  node_ddl_bucket[("DDL source bucket")]
  node_rds_event_trigger["RDS create trigger<br/>[app.py]"]
  node_ddl_queue["RDS DDL queue"]
  node_ddl_automation["DDL automation<br/>[app.py]"]
  node_ddl_change["DDL change handler<br/>[app.py]"]
end

node_user(("User"))
node_bedrock["Amazon Bedrock"]
node_openai["OpenAI embeddings"]

node_user -->|"HTTPS request"| node_alb
node_alb -->|"authenticates"| node_cognito
node_alb -->|"routes traffic"| node_rag_app
node_rag_app -->|"runs chain"| node_chat_chain
node_chat_chain -->|"retrieves context"| node_pgvector
node_chat_chain -->|"generates answer"| node_bedrock
node_user -.->|"uploads PDFs"| node_knowledge_bucket
node_knowledge_bucket -->|"object event"| node_pdf_processor
node_pdf_processor -->|"reads PDF"| node_knowledge_bucket
node_pdf_processor -->|"writes extracted text"| node_processed_bucket
node_processed_bucket -->|"object event"| node_pgvector_trigger
node_pgvector_trigger -->|"queues file reference"| node_pgvector_queue
node_pgvector_queue -->|"dispatches message"| node_pgvector_update
node_pgvector_update -->|"loads text"| node_processed_bucket
node_pgvector_update -->|"creates embeddings"| node_openai
node_pgvector_update -->|"adds documents"| node_pgvector
node_rds_event_trigger -->|"queues database details"| node_ddl_queue
node_ddl_queue -->|"dispatches message"| node_ddl_automation
node_ddl_automation -->|"reads SQL source"| node_ddl_bucket
node_ddl_automation -.->|"applies database changes"| node_ddl_change
node_app_client_trigger -.->|"queues client details"| node_ddl_queue
node_callback_init -.->|"configures callback"| node_cognito
node_callback_update -.->|"updates callback"| node_cognito

click node_alb "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts"
click node_cognito "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts"
click node_rag_app "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/rag-app/app.py"
click node_chat_chain "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/rag-app/pgvec_chat_bedrock.py"
click node_pgvector "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/rds-stack.ts"
click node_knowledge_bucket "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts"
click node_pdf_processor "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pdf-processor/lambda_function.py"
click node_processed_bucket "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts"
click node_pgvector_trigger "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pgvector-trigger/app.py"
click node_pgvector_queue "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts"
click node_pgvector_update "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pgvector-update/app.py"
click node_ddl_bucket "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/ddl-source-rds-stack.ts"
click node_rds_event_trigger "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/rds-ddl-trigger/app.py"
click node_ddl_queue "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts"
click node_ddl_automation "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/rds-ddl-init/app.py"
click node_ddl_change "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/rds-ddl-change/app.py"
click node_app_client_trigger "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/app-client-create-trigger/app.py"
click node_callback_init "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/call-back-url-init/app.py"
click node_callback_update "https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/call-back-url-update/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rag_app,node_chat_chain,node_pgvector,node_user toneBlue
class node_knowledge_bucket,node_pdf_processor,node_processed_bucket,node_pgvector_trigger,node_pgvector_queue,node_pgvector_update toneAmber
class node_alb,node_cognito,node_app_client_trigger,node_callback_init,node_callback_update toneMint
class node_ddl_bucket,node_rds_event_trigger,node_ddl_queue,node_ddl_automation,node_ddl_change toneRose
class node_bedrock,node_openai toneIndigo
```

## Components

### Question answering

- [Streamlit RAG app](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/rag-app/app.py): `rag-app/app.py`
- [Bedrock chat chain](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/rag-app/pgvec_chat_bedrock.py): `rag-app/pgvec_chat_bedrock.py`
- [PGVector on RDS](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/rds-stack.ts): `lib/rds-stack.ts`

### Document ingestion

- [PDF knowledge bucket](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts): `lib/base-infra-stack.ts`
- [PDF text extraction](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pdf-processor/lambda_function.py): `lambda/pdf-processor/lambda_function.py`
- [Processed text bucket](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts): `lib/base-infra-stack.ts`
- [Indexing event trigger](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pgvector-trigger/app.py): `lambda/pgvector-trigger/app.py`
- [Indexing queue](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts): `lib/base-infra-stack.ts`
- [Vector index updater](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/pgvector-update/app.py): `lambda/pgvector-update/app.py`

### AWS platform

- [HTTPS load balancer](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts): `lib/base-infra-stack.ts`
- [Cognito authentication](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts): `lib/base-infra-stack.ts`
- [Cognito client trigger](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/app-client-create-trigger/app.py): `lambda/app-client-create-trigger/app.py`
- [Callback URL setup](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/call-back-url-init/app.py): `lambda/call-back-url-init/app.py`
- [Callback URL updater](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/call-back-url-update/app.py): `lambda/call-back-url-update/app.py`

### Database provisioning

- [DDL source bucket](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/ddl-source-rds-stack.ts): `lib/ddl-source-rds-stack.ts`
- [RDS create trigger](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/rds-ddl-trigger/app.py): `lambda/rds-ddl-trigger/app.py`
- [RDS DDL queue](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lib/base-infra-stack.ts): `lib/base-infra-stack.ts`
- [DDL automation](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/rds-ddl-init/app.py): `lambda/rds-ddl-init/app.py`
- [DDL change handler](https://github.com/aws-samples/rag-with-amazon-bedrock-and-pgvector/blob/main/lambda/rds-ddl-change/app.py): `lambda/rds-ddl-change/app.py`

### Other components

- **User**
- **Amazon Bedrock**
- **OpenAI embeddings**

## Connections

- User → HTTPS load balancer: HTTPS request
- HTTPS load balancer → Cognito authentication: authenticates
- HTTPS load balancer → Streamlit RAG app: routes traffic
- Streamlit RAG app → Bedrock chat chain: runs chain
- Bedrock chat chain → PGVector on RDS: retrieves context
- Bedrock chat chain → Amazon Bedrock: generates answer
- User → PDF knowledge bucket: uploads PDFs
- PDF knowledge bucket → PDF text extraction: object event
- PDF text extraction → PDF knowledge bucket: reads PDF
- PDF text extraction → Processed text bucket: writes extracted text
- Processed text bucket → Indexing event trigger: object event
- Indexing event trigger → Indexing queue: queues file reference
- Indexing queue → Vector index updater: dispatches message
- Vector index updater → Processed text bucket: loads text
- Vector index updater → OpenAI embeddings: creates embeddings
- Vector index updater → PGVector on RDS: adds documents
- RDS create trigger → RDS DDL queue: queues database details
- RDS DDL queue → DDL automation: dispatches message
- DDL automation → DDL source bucket: reads SQL source
- DDL automation → DDL change handler: applies database changes
- Cognito client trigger → RDS DDL queue: queues client details
- Callback URL setup → Cognito authentication: configures callback
- Callback URL updater → Cognito authentication: updates callback
