Build a Document Q&A App with Amazon Bedrock Knowledge Bases and S3 Vectors
Recently, I taught a live session to students at Information Technology University (ITU) in Lahore. The question I opened with was simple: How do you get a reliable answer out of a 200 page PDF without reading the whole thing every time? Ctrl+F finds words. It does not find meaning. And if you paste the whole document into a chat model, you pay for every page on every question, and the model may…
A live session was conducted at Information Technology University (ITU) in Lahore. The session aimed to teach students how to extract reliable answers from lengthy documents without reading the entire content. The solution was Retrieval Augmented Generation (RAG). The app developed for the session, named Poocho AI, allows users to upload PDF, DOCX, or TXT files and ask questions in plain language.
The application then retrieves relevant information from the uploaded files and displays the source page numbers. The architecture of the backend is serverless, utilizing services such as Amazon S3, Amazon SQS, AWS Lambda, Amazon Bedrock Knowledge Bases, Titan Text Embeddings V2, Amazon S3 Vectors, and Amazon Nova Micro. The process begins with a student uploading a file to a presigned URL, which is then stored in S3.
The file is split into chunks, and these chunks are transformed into embeddings using Titan Text Embeddings V2 with 1024 dimensions. These embeddings are stored in an S3 Vectors index, which utilizes cosine distance with float32 values. When a user asks a question, the system retrieves the most relevant chunks from the stored documents, combines them with the user's query, and sends the prompt to the model for generation.
The system ensures that the model only uses information from the relevant chunks, thus avoiding the issue of the model generating information from its own knowledge. The response includes the answer, source file name, and page numbers, enabling users to verify the information's accuracy.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to