This repository contains a full RAG application using AWS CDK as IaC, LlamaIndex framework, Qdrant as a vector database, and deployment on AWS using a FastAPI app and Dockerfile.
For detailed project descriptions, refer to this Medium article.
Main Steps
- Data Ingestion: Load data to an s3 bucket
- Indexing: Use SentenceSplitter for indexing in nodes
- Embedding and Model: OpenAI
- Vector Store: Use Qdrant for inserting metadata
- FastAPI and AWS: Handle requests via the FastAPI app deployed on AWS
- IaC: AWS CDK
Feel free to ⭐ and clone this repo 😉
The project has been structured with the following files:
app:
app logic withDockerfile
tests
: unittestapp.py:
AWS CDK synthesizeraws_cdk_rag_fargate:
script to create the constructs and stackscripts:
scripts to puch the documents to s3 and create the Qdrant collection.env:
environmental variablesrequirements.txt:
project requirements
The Python version used for this project is Python 3.11. You can follow along the medium article.
-
Create an empty respository locally. This is necessary to initialize CDK. Afterwards you can copy the files from this repository.
-
Initialize AWS CDK to create the project structure:
cdk init app --language python
-
Create the virtual environment named
main-env
using Conda with Python version 3.11:conda create -n main-env python=3.11 conda activate main-env
-
Install the requirements.txt:
pip install -r requirements.txt
-
Make sure the
.env
file is complete:QDRANT_URL= QDRANT_API_KEY= DOCUMENT_BUCKET= OPENAI_API_KEY=
-
Synthesize the app:
cdk synth
-
Bootstrap the app to provision s3, ECR and IAM roles:
cdk bootstrap aws://{Account ID:}/{region}
-
Create Qdrant Collection by running the script under
scripts
:python s3_uploader.py python qdrant_setup.py
-
Deploy the app on AWS CDK
cdk deploy
-
Get the DNS Name
aws cloudformation describe-stacks --stack-name AwsCdkRagFargateStack --query "Stacks[0].Outputs[? OutputKey=='LoadBalancerDNS'].OutputValue" --output text # Output AwsCdk-RagFa-a1TpSwcX5iaS-653394042.eu-central-1.elb.amazonaws.com
-
Send a POST request to test the app
curl -X POST -H "Content-Type: application/json" -d '{"question":"What is a transformer?"}' http://AwsCdk-RagFa-a1TpSwcX5iaS-653394042.eu-central-1.elb.amazonaws.com/query
-
Clean up
cdk destroy