$ show aws-samples/serverless-pdf-chat
This repository implements a serverless document chat application that allows users to upload PDF documents and ask natural language questions. The backend is composed of AWS Lambda functions orchestrated by Amazon API Gateway, S3, SQS, and DynamoDB. PDF processing uses LangChain with FAISS for vector embeddings and Amazon Bedrock (Claude Sonnet) for LLM inference. The frontend is a React SPA with TypeScript, TailwindCSS, and AWS Amplify authentication. Architecture follows an event-driven serverless pattern: upload triggers S3 event → Lambda extracts PDF metadata, stores in DynamoDB, sends SQS message → another Lambda generates embeddings and stores FAISS index in S3. Chat requests invoke a Lambda that loads the FAISS index, retrieves relevant context, and uses a ConversationalRetrievalChain with DynamoDB-backed memory. The code is clean and follows AWS best practices with Powertools logging, but lacks tests and hardcodes the Bedrock region to us-east-1. It is a solid reference implementation for building a RAG-based Q&A system on AWS.
The LLM identified 2 files worth highlighting for reuse:
Implements the core Q&A response Lambda. It loads a FAISS vector index from S3, initializes a Bedrock chat model, creates a conversation buffer memory backed by DynamoDB, and uses LangChain's ConversationalRetrievalChain to answer prompts with context. This is a clean template for any serverless RAG system on AWS, demonstrating how to wire together vector search, LLM inference, and persistent chat history. It is self-contained and could be extracted as a reusable Lambda blueprint.
Handles the initial document upload from S3. Extracts metadata (page count via PyPDF2), creates a document record in DynamoDB with status 'UPLOADED', initializes a default conversation, and sends an SQS message to trigger embedding generation. This Lambda is a classic example of an S3 event-driven worker that coordinates downstream processing via message queues. The pattern is reusable for any document ingestion pipeline requiring async processing.