Coder Social home page Coder Social logo

benitomartin / scale-gke-qdrant-llama Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 2.0 79 KB

Scalable RAG with GKE, LlamaIndex and Qdrant

Home Page: https://medium.com/@benitomartin/find-your-code-scaling-a-llamaindex-and-qdrant-application-with-google-kubernetes-engine-2db126f16344

Dockerfile 2.46% Makefile 3.00% Python 94.54%
docker fastapi github-actions google-cloud-platform google-kubernetes-engine kubernetes llama-index openai python qdrant ruff streamlit

scale-gke-qdrant-llama's Introduction

Q&A Pipeline Deployment on GKE for Scalability with LlamaIndex and Qdrant ๐Ÿš€

cover_gke_medium

This repository contains a full Q&A pipeline using the LlamaIndex framework, Qdrant as a vector database, and deployment on Google Kubernetes Engine (GKE) using a FastAPI app and Dockerfile. Python files from my repositories are loaded into the vector database, and the FastAPI app processes requests. The main goal is to provide fast access to your own code, enabling reuse of functions.

For detailed project descriptions, refer to this Medium article.

This article was featured in the GKE Newsletter (This week in GKE, ISSUE#19, 12 July 2024)

Main Steps

  • Data Ingestion: Load data from GitHub repositories
  • Indexing: Use SentenceSplitter for indexing in nodes
  • Embedding and Model: OpenAI
  • Vector Store: Use Qdrant for inserting metadata
  • Query Retrieval: Implement RetrieverQueryEngine with SentenceTransformerRerank
  • FastAPI and GKE: Handle requests via the FastAPI app deployed on GKE
  • Streamlit: UI

Feel free to โญ and clone this repo ๐Ÿ˜‰

Tech Stack

Visual Studio Code Python OpenAI Anaconda Linux Ubuntu Google Cloud Kubernetes FastAPI Git Docker GitHub Actions Streamlit

Project Structure

The project has been structured with the following files:

  • .github/workflows: CI/CD pipelines
  • tests: unittest
  • Dockerfile:Dockerfile
  • Makefile: install requirements, formating, linting, testing and clean up
  • app.py: FastAPI
  • pyproject.toml: linting and formatting using ruff
  • create_qdrant_collection.py: script to create the collection in Qdrant
  • deploy-gke.yaml: deployment function
  • kustomization.yaml: kustomize deployment function
  • requirements.txt: project requirements
  • streamlit_app.py: streamlit app

Project Set Up

The Python version used for this project is Python 3.10. You can follow along the medium article.

  1. Clone the repo (or download it as a zip file):

    git clone https://github.com/benitomartin/scale-gke-qdrant-llama.git
  2. Create the virtual environment named main-env using Conda with Python version 3.10:

    conda create -n main-env python=3.10
    conda activate main-env
  3. Execute the Makefile script and install the project dependencies included in the requirements.txt:

    pip install -r requirements.txt
    
    or
    
    make install
  4. Make sure the .env file is complete:

    OPENAI_API_KEY=
    QDRANT_API_KEY=
    QDRANT_URL=
    COLLECTION_NAME=
    ACCESS_TOKEN=
    GITHUB_USERNAME=
  5. You can test the app locally running:

    uvicorn app:app --host 0.0.0.0 --port 8000

    then go to one of these addresses

    http://localhost:8000/docs or http://127.0.0.1:8000/docs

  6. Create GCP Account, project, service account key, and activate GKE API

  7. Add the following secrets into github:

    OPENAI_API_KEY
    QDRANT_API_KEY
    QDRANT_URL
    COLLECTION_NAME
    GKE_SA_KEY
    GKE_PROJECT # PROJECT_ID
  8. Be sure to authenticate in GCP:

    gcloud auth login
    gcloud config set project PROJECT_ID
  9. Create Kubernetes Cluster

    gcloud container clusters create llama-gke-cluster \
        --zone=europe-west6-a \
        --num-nodes=5 \
        --enable-autoscaling \
        --min-nodes=2 \
        --max-nodes=10 \
        --machine-type=n1-standard-4 \
        --enable-vertical-pod-autoscaling

    after creation check the nodes

    kubectl get nodes
  10. Push the GitHub Actions workflows to start the deployment

  11. Verify Kubernetes is running after deployment

    # Get the Pods
    kubectl get po
    
    # Get the Nodes
    kubectl get nodes
    
    # Get the Services
    kubectl get svc 
    
    # Get the logs of a pod
    kubectl logs llama-gke-deploy-668b58b455-fjwvq 
    
    # Describe a pod
    kubectl describe pod llama-gke-deploy-668b58b455-fjwvq
    
    # Check CPU usage
    kubectl top pod llama-gke-deploy-668b58b455-fjwvq

Nodes, Pods, svc and, usage2

  1. Under svc the external ip is the endpoint (34.65.157.134), that can be added in the streamlit app

    # Set the FastAPI endpoint
    FASTAPI_ENDPOINT = "http://34.65.157.134:8000/query/"
  2. Check some pods and logs

    kubectl logs llama-gke-deploy-668b58b455-fjwvq 
    kubectl describe pod llama-gke-deploy-668b58b455-fjwvq
    kubectl top pod llama-gke-deploy-668b58b455-8xfhf 
  3. Clean up to avoid costs deleting the cluster and the docker image

    gcloud container clusters delete llama-gke-cluster --zone=europe-west6-a

Streamlit UI

Run the streamlit app adding the endpoint url that you get after deployment:

streamlit run streamlit_app.py

lambda-gke

scale-gke-qdrant-llama's People

Contributors

benitomartin avatar

Stargazers

Chandan kumar yadav avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.