Skip to content

maihoangbichtram/multi_agentic_rag

Repository files navigation

🔎 Multi Agentic Research (RAG)

  • Multi-agentic researcher researches the query/topic from documents fetched from Tavily Search Engine.
  • The output is the report about the query/topic based on the retrieved documents.
  • The graph ends when the hallucination point is 1, or else the graph restarts from collecting documents from Tavily for generated queries to retrieve related info.

Demo

Website

  • To improve performance and avoid reaching limit of free tier of Google Generative AI, I limited the length of the response/report to be min 200 words.

img.png img.png img.png

Work in progress

  1. INTERNAL DOCUMENTATION
  2. Access to documents to reliable sources for academic sources (sciencedirect, elsevier, springer, ...)
  3. Construct more detail report (e.g Write report for each query)
  4. Human input (e.g research plan, sources to fetch documents for queries)

Installation

Customize LLMs, retrievers and report length in config.yaml

  1. Install Python 3.12 or later. Guide.

  2. Clone the project and navigate to the directory:

    git clone https://github.com/maihoangbichtram/multi_agentic_rag
    cd multi_agentic_rag
  3. Set up API keys by exporting them or storing them in a .env file.

    Copy .env.example to .env
  4. Create and Activate virtual environment

    4.1 In terminal: Create a virtual environment

    python3 -m venv .venv

    Activate the virtual environment

    . .venv/bin/activate

    4.2 Poetry

    poetry shell
  5. Install dependencies and start the server:

    5.1 In terminal:

    pip install -r requirements.txt

    5.2 Poetry

    poetry install
  6. Start the application

    6.1 In terminal:

    python app/main.py

    6.2 Poetry

    poetry run uvicorn app.main:app --reload --timeout-keep-alive 720

Deployment

Google Cloud

Prerequisites

  • Google Cloud Account
  • Google CLI
  • Service account under IAM (to access to Google Cloud services.)
  • (Access) Key downloaded as json (for the service account)

Terraforming GC Components

Tf files
  • main.tf
  • variables.tf
  • terraform.tfvars (not public): Declare values for variables
    #  GCP settings
    project_id = "project_id"
    
    # GCP region
    region = "europe-west3"
    
    #  Artifact registry repository
    registry_id = "registry_id"
Commands

Run commands in order

  • terraform init
  • terraform plan
  • terraform apply: create the GCP resources
Note

Enable GCP APIs manually if Terraform reports errors with permission:

gcloud services enable artifactregistry.googleapis.com
gcloud services enable run.googleapis.com

Deploying to cloud

  • Create requirements.txt for docker file
poetry export -f requirements.txt --output requirements.txt
Build and test docker image locally
docker build --pull --rm -f "Dockerfile" -t <image_name>:latest "."
docker run --rm -it -p 8080:8080/tcp <image_name>:latest
Build docker image for Cloud Run
  • Create builder
docker buildx create --name <builder_name> --bootstrap --use
  • Build the image
docker buildx build --file Dockerfile \
  --platform linux/amd64 \
  --builder <builder_name> \
  --progress plain \
  --build-arg DOCKER_REPO=<gcd_region>-docker.pkg.dev/<gcd_project_id>/<gcd_repository_name>/ \
  --pull --push \
  --tag <gcd_region>-docker.pkg.dev/<gcd_project_id>/<gcd_repository_name>/<image_name>:latest .
Deploy

Added necessary API keys for the app to run probably. If you configure OpenAI for llm, add env var OPENAI_API_KEY.

gcloud run deploy app \                             
--image <gcd_region>-docker.pkg.dev/<gcd_project_id>/<gcd_repository_name>/<image_name>:latest \
--region <gcd_region> \
--platform managed \
--allow-unauthenticated \
--set-env-vars GOOGLE_API_KEY=<GOOGLE_API_KEY>,TAVILY_API_KEY=<TAVILY_API_KEY>,CO_API_KEY=<CO_API_KEY>