RAG Pipeline
What is RAG?
Section titled “What is RAG?” Retrieval-Augmented Generation
Retrieval-Augmented Generation — a pattern that combines vector similarity search with LLM generation to produce grounded answers. (RAG) is a pattern that combines
vector similarity search with LLM generation. Instead of relying solely on a model’s training data,
RAG retrieves relevant source documents at query time and feeds them as context to the
LLM
Large Language Model — Anthropic Claude accessed via Bedrock inference profile. Generates structured answers from retrieved context. .
The result: answers that are grounded in real data, cite their sources, and stay current without retraining.
Why RAG over pure LLM?
Section titled “Why RAG over pure LLM?”A pure LLM generates answers from its training data alone. This works for general knowledge but falls short for domain-specific, private, or rapidly changing information.
| Aspect | Pure LLM | RAG |
|---|---|---|
| Freshness | Frozen at training cutoff | As current as ingested documents |
| Accuracy | May hallucinate confidently | Grounded in retrieved source text |
| Verifiability | No source attribution | Cites specific documents with URLs |
| Cost | Requires fine-tuning for new data | Add documents without retraining |
| Private data | Not available unless fine-tuned | Works with any ingested corpus |
Pipeline phases
Section titled “Pipeline phases”This project implements a four-phase RAG pipeline:
1. Ingest
Section titled “1. Ingest”The Ingest Lambda
AWS Lambda — serverless compute. This project uses two functions: ingest (RSS → embed → store) and query (search → answer). fetches RSS feeds, strips HTML, and prepares article text. Each article becomes a source document stored in S3.
2. Store
Section titled “2. Store”Each document is converted into a 1024-dimensional vector embedding
A vector representation of text — a list of floating-point numbers that captures semantic meaning. Generated by an embedding model. using Titan Embeddings V2
Amazon Titan Embeddings V2 — the Bedrock foundation model used to generate 1024-dimensional text embeddings. , then stored in S3 Vectors
Amazon S3 Vectors — a purpose-built vector storage capability within S3 that enables similarity search over embeddings without a separate vector database. alongside metadata (title, URL, date, feed source).
3. Query
Section titled “3. Query”When a user asks a question, the system embeds the question into the same vector space, then searches S3 Vectors for the most similar documents using cosine similarity
Cosine similarity — a distance metric that measures the angle between two vectors. Values range from 0 (opposite) to 1 (identical direction). Preferred for text embeddings. .
4. Generate
Section titled “4. Generate”Retrieved documents are scored, ranked, and assembled into a context window. The LLM (Claude via Bedrock
Amazon Bedrock — a fully managed service for accessing foundation models (embedding and LLM) via a unified API. ) generates a structured answer grounded in the retrieved context.
Architecture
Section titled “Architecture”
Component roles
Section titled “Component roles”| Component | Role in pipeline | AWS service |
|---|---|---|
| Ingest Lambda | Fetches RSS, prepares documents, embeds, stores vectors | AWS Lambda |
| Query Lambda | Embeds question, searches vectors, builds context, calls LLM | AWS Lambda |
| S3 Vectors | Stores and searches 1024-dim embeddings with metadata | Amazon S3 Vectors |
| S3 (documents) | Stores full article text for context retrieval | Amazon S3 |
| Bedrock (Titan V2) | Generates embeddings for both documents and queries | Amazon Bedrock |
| Bedrock (Claude) | Generates structured answers from retrieved context | Amazon Bedrock |
| API Gateway | Routes authenticated requests to Query Lambda | Amazon API Gateway |
| EventBridge Amazon EventBridge — a serverless event bus. Used here for the daily scheduled corpus ingest cron trigger. | Triggers daily corpus refresh | Amazon EventBridge |
How a question becomes an answer
Section titled “How a question becomes an answer”
A complete request lifecycle:
- User types a question in the web UI
- Browser sends the question to API Gateway
Amazon API Gateway — a managed HTTP API service with JWT authorization, CORS, and throttling. Routes requests to the Query Lambda. with a JWT token - API Gateway validates the token via Cognito
Amazon Cognito — a user authentication service providing user pools, JWT tokens, and group-based authorization. and routes to Query Lambda - Query Lambda embeds the question using Titan V2 (same model used at ingest time)
- Query Lambda calls QueryVectors
S3 Vectors QueryVectors API — finds the most similar vectors to a query vector using Top-K nearest neighbor search. to find similar documents - Full document bodies are loaded from S3
- Documents are scored (80% similarity + 20% recency) and ranked
- Top documents are assembled into a context prompt
- Claude generates a structured answer citing specific sources
- Response returns to the browser with answer and source links