PwC and AWS Alliance

GenAI question-answering application using AWS serverless technologies

  • Blog
  • 15 Minute Read
  • September 30, 2023

Jayant Raj

Director, Cloud & Digital, AWS Ambassador, PwC US

Email

This post demonstrates building a basic Document Q&A Generative AI application using AWS serverless technologies, Langchain, AWS Cloud Development Kit (CDK), Poetry, OpenAI, Pinecone and Gradio.

Large Language Models (LLMs) perform quite well on general knowledge retrieval tasks because they have been trained on a large corpus of openly available internet data. However, in an enterprise environment or use cases where we need to ask questions on more specialized topics, a general purpose LLM will have issues in coming up with precise responses. LLMs can be used for more complex and knowledge-intensive tasks by using an approach called Retrieval-Augmented Generation (RAG). RAG combines retrieval-based methods with generative language models to improve the quality of generated text, especially in question answering and text generation tasks.

For the purposes of this example, we will build a simple system to do question-answering on openly available clinical trial protocol documents. To setup the knowledge base for the RAG approach, we will build a data pipeline that ingests a clinical protocol document in pdf format, converts the pdf to text format, chunks the document into smaller pieces, converts the chunks into embeddings using an embedding model and stores the embeddings in a vector database.

Now when we ask the LLM a question about the clinical trial, we can give the LLM more context by providing relevant chunks of the document as part of the prompt. This can be done by using a framework such as Langchain, that takes the user question, converts the question into a vector representation, does a semantic search against the knowledge base, retrieves the relevant chunks, ranks them by relevance and sends the chunks as context in the prompt to the LLM.

Want to see how it’s done?

Read the full details about the application

Follow us