CoolFace
Apppublic

kamkol/AB_AI_RAG_Agent

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

AB Testing RAG Agent

This application is a Streamlit-based frontend for an AB Testing QA system that uses a carefully designed retrieval-augmented generation (RAG) approach with a LangGraph architecture.

Features

  • QA system specialized in AB Testing topics
  • Intelligent query routing with LangGraph
  • Source citations for all answers
  • Streamlit interface for easy interaction

Setup for Development

Prerequisites

  • Python 3.9+
  • OpenAI API key
  • Huggingface account and token (for deployment)

Environment Setup

  1. 1.Clone this repository
  2. 2.Create a .env file in the root directory with the following content:
   OPENAI_API_KEY=your_openai_api_key_here
   HF_TOKEN=your_huggingface_token_here

Process the PDFs

Before running the app, you need to process the PDF files to create the vectorstore:

bash
python process_data.py

This will:

  1. 1.Load PDFs from notebook_version/data/
  2. 2.Process, chunk, and embed the documents
  3. 3.Create a Qdrant vectorstore in data/processed_data/

Running the App Locally

Once the data is processed, you can run the Streamlit app:

bash
streamlit run app/app.py

Deployment to Huggingface Spaces

Prerequisites for Deployment

  1. 1.Huggingface account
  2. 2.Docker installed locally

Steps to Deploy

  1. 1.Process the PDFs locally: python process_data.py
  2. 2.Build the Docker image: docker build -t ab-testing-qa .
  3. 3.Create a new Huggingface Space (Docker-based)
  4. 4.Add your Huggingface token and OpenAI API key as secrets in the space
  5. 5.Push the Docker image to Huggingface

Huggingface Spaces Configuration

The application is configured to use the following secrets:

  • OPENAI_API_KEY: Your OpenAI API key
  • HF_TOKEN: Your Huggingface token

System Architecture

The AB Testing QA system uses a sophisticated LangGraph architecture:

  1. 1.Initial RAG Node: Retrieves documents and attempts to answer the query
  2. 2.Helpfulness Judge: Determines if:
  3. 3.The query is related to AB Testing
  4. 4.The initial response is helpful enough
  5. 5.Agent Node: If needed, uses specialized tools to improve the answer:
  6. 6.Standard retrieval tool
  7. 7.Query-rephrasing retrieval tool
  8. 8.ArXiv search tool

Data Processing

The system processes PDFs using a specific approach:

  1. 1.Merges PDF pages while maintaining page metadata
  2. 2.Uses RecursiveCharacterTextSplitter with specific parameters
  3. 3.Embeds using OpenAI's text-embedding-3-small model
  4. 4.Stores in a Qdrant vectorstore