RAG (Retrieval-Augmented Generation) lets you build AI systems that answer questions from your private data — without fine-tuning a model. Here's how to build one with AWS Bedrock and pgvector.
Architecture Overview
The pipeline has four stages: 1. Document ingestion — load PDFs, Word docs, databases 2. Chunking and embedding — split into chunks, generate embeddings via Bedrock 3. Storage — store vectors in PostgreSQL with pgvector extension 4. Retrieval and generation — find relevant chunks, send to Claude via Bedrock
Setting Up pgvector
Enable the extension in your PostgreSQL database:
CREATE EXTENSION vector;
CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(1536));
CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops);Generating Embeddings with Bedrock
Use Amazon Titan Embeddings via the Bedrock API to convert text chunks into vectors. Each chunk becomes a 1536-dimension vector stored in pgvector.
Using Bedrock Knowledge Bases (Managed Option)
For a fully managed approach, Bedrock Knowledge Bases handles ingestion, chunking, embedding, and storage automatically. Connect your S3 bucket and let Bedrock manage the pipeline.
Query and Generation
At query time, embed the user question, find the top-k most similar chunks using cosine similarity, then pass them as context to Claude or another Bedrock model.
InfraOpex RAG Services
We build production RAG pipelines end-to-end — from document ingestion to API deployment. Contact us to discuss your use case.