Skip to content

RAG Pipeline

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.

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.

AspectPure LLMRAG
FreshnessFrozen at training cutoffAs current as ingested documents
AccuracyMay hallucinate confidentlyGrounded in retrieved source text
VerifiabilityNo source attributionCites specific documents with URLs
CostRequires fine-tuning for new dataAdd documents without retraining
Private dataNot available unless fine-tunedWorks with any ingested corpus

This project implements a four-phase RAG pipeline:

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.

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).

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.
.

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.

RAG retrieval pipeline — from RSS feeds through embedding, storage, search, and answer generation

ComponentRole in pipelineAWS service
Ingest LambdaFetches RSS, prepares documents, embeds, stores vectorsAWS Lambda
Query LambdaEmbeds question, searches vectors, builds context, calls LLMAWS Lambda
S3 VectorsStores and searches 1024-dim embeddings with metadataAmazon S3 Vectors
S3 (documents)Stores full article text for context retrievalAmazon S3
Bedrock (Titan V2)Generates embeddings for both documents and queriesAmazon Bedrock
Bedrock (Claude)Generates structured answers from retrieved contextAmazon Bedrock
API GatewayRoutes authenticated requests to Query LambdaAmazon API Gateway
EventBridge
Amazon EventBridge — a serverless event bus. Used here for the daily scheduled corpus ingest cron trigger.
Triggers daily corpus refreshAmazon EventBridge

Request flow — from user question through API Gateway, Lambda, S3 Vectors, and Bedrock to structured answer

A complete request lifecycle:

  1. User types a question in the web UI
  2. 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
  3. 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
  4. Query Lambda embeds the question using Titan V2 (same model used at ingest time)
  5. 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
  6. Full document bodies are loaded from S3
  7. Documents are scored (80% similarity + 20% recency) and ranked
  8. Top documents are assembled into a context prompt
  9. Claude generates a structured answer citing specific sources
  10. Response returns to the browser with answer and source links