Skip to content

pushpsood/PDFGenAIChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless document chat application

This sample application allows you to ask natural language questions of any PDF document you upload. It combines the text generation and analysis capabilities of an LLM with a vector search of the document content. The solution uses serverless services such as Amazon Bedrock to access foundational models, AWS Lambda to run LangChain, and Amazon DynamoDB for conversational memory.

Key features

How the application works

  1. Uploads a PDF document into an Amazon S3 using pre-signed URL
  2. The new document model is created in DynamoDB (For Metadata and saving conversations)
  3. Post that metadata extraction & document embedding takes place.
  4. The process converts the text in the document into vectors. The vectors are loaded into a vector index and stored in Pinecone DB for later use.
  5. When a user chats with a PDF document and sends a prompt to the backend, a Lambda function retrieves the index from Pinecone and searches for information related to the prompt.
  6. A LLM then uses the results of this vector search, previous messages in the conversation to formulate a response to the user.

Architecture

Deployment instructions

Prerequisites

Amazon Bedrock setup

This application can be used with a variety of LLMs via Amazon Bedrock. See Supported models in Amazon Bedrock for a complete list.

By default, this application uses amazon.titan-text-express-v1 to generate embeddings and responses.

Pinecone

Create a pinecone dashboard, copy and paste the following details in constants file depending on the index name

    API_KEY : "febe9883-869a-4c4e-bb8c-356a5b356f00",
    PINECONE_ENV : "gcp-starter",
    PINECONE_INDEX_NAME : "industrility-index",

Deploy the application with AWS SAM

  1. Change to the backend directory and build the application:

    cd backend
    sam build
  2. Setup credentials using AWS Identity and Access Management

  3. Deploy the application into your AWS account:

    sam deploy --guided
  4. For Stack Name, choose serverless-pdf-chat.

  5. For the remaining options, keep the defaults by pressing the enter key.

AWS SAM will now provision the AWS resources defined in the backend/template.yaml template. Once the deployment is completed successfully, you will see a set of output values similar to the following:

CloudFormation outputs from deployed stack
-------------------------------------------------------------------------------
Outputs
-------------------------------------------------------------------------------
Key                 CognitoUserPool
Description         -
Value               us-east-1_gxKtRocFs

Key                 CognitoUserPoolClient
Description         -
Value               874ghcej99f8iuo0lgdpbrmi76k

Key                 ApiGatewayBaseUrl
Description         -
Value               https://abcd1234.execute-api.us-east-1.amazonaws.com/dev/
-------------------------------------------------------------------------------

You can find the same outputs in the Outputs tab of the serverless-pdf-chat stack in the AWS CloudFormation console. In the next section, you will use these outputs to run the React frontend locally and connect to the deployed resources in AWS.

Run the React frontend locally

Create a file named .env.development in the frontend directory. Vite will use this file to set up environment variables when we run the application locally.

Copy the following file content and replace the values with the outputs provided by AWS SAM: (You can keep them as it is, as the backend stack is up and running)

VITE_REGION=us-east-1
VITE_API_ENDPOINT=https://abcd1234.execute-api.us-east-1.amazonaws.com/dev/
VITE_USER_POOL_ID=us-east-1_gxKtRocFs
VITE_USER_POOL_CLIENT_ID=874ghcej99f8iuo0lgdpbrmi76k

Next, install the frontend's dependencies by running the following command in the frontend directory:

npm ci

Finally, to start the application locally, run the following command in the frontend directory:

npm run dev

Vite will now start the application under http://localhost:5173. As the application uses Amazon Cognito for authentication, you will be greeted by a login screen. In the next step, you will create a user to access the application.

About

Ask natural language questions of any PDF document you upload

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •