Skip to main content

Overview

Deploy a production ready Retrieval Augmented Generation (RAG) system in minutes.
Full step-by-step video tutorial is here: https://youtu.be/CkcVGtiSGDQ?si=Y1X1LP-Aw09g_zIp GitHub repo: https://github.com/bultcloud/RAG-BultAI Upload documents. Ask questions. Get answers with inline citations and source scoring. This template includes: • Hybrid search combining keyword and vector retrieval
• Cross encoder reranking for higher precision
• Multi model LLM support
• Background document processing
• Authentication and analytics
It supports multiple LLM providers (OpenAI, Anthropic, Google, Ollama), hybrid search with reranking, OCR for scanned PDFs, multi-user authentication, and conversation export. It is designed to demonstrate how to run serious AI workloads on Bult.ai without managing infrastructure.

Architecture

#1
Rag 2
#2
Rag 3

Components


App Service
FastAPI backend handling authentication, API endpoints, streaming responses.
PostgreSQL
Stores users, projects, documents, analytics.
pgvector
Stores embeddings and enables vector similarity search.
Background Worker
Processes documents asynchronously:
• Chunking
• Embedding generation
• OCR if needed
LLM Provider
OpenAI, Anthropic, Google, or Ollama.

Features

  • Multi-model LLM support — switch between OpenAI, Anthropic, Google AI, or local Ollama models via environment variable
  • Advanced RAG pipeline — hybrid search (BM25 + vector), cross-encoder reranking, HyDE query transformation, multi-query retrieval, query decomposition
  • Document processing — PDF, DOCX, PPTX, TXT, MD, CSV, JSON, HTML; automatic OCR for scanned PDFs via Tesseract
  • Inline citations — every response cites source documents with relevance scores
  • Authentication — JWT login/register + optional Google OAuth
  • Analytics dashboard — usage metrics, cost tracking, query latency, top projects
  • Conversation export — Markdown, JSON, and PDF export with full Unicode support
  • Background processing — async job queue with progress tracking and retry logic
  • Single-page frontend — clean UI with streaming responses, markdown rendering, dark mode

Deploy RAG on bult.ai

Bult.ai is a PaaS that deploys from GitHub with built-in database templates and Docker support. You need three services: the app (GitHub), a PostgreSQL database, and a pgvector instance.

Prerequisites

  • GitHub account
  • OpenAI API key (get one here)
  • Bult.ai account

Step 1: Fork or clone this repository

Fork this repo on GitHub (or clone it and push to your own repo). GitHub repo: https://github.com/bultcloud/RAG-BultAI

Step 2: Create the app service (GitHub)

  1. On bult.ai, click Create > GitHub
  2. Select your forked repository
  3. Go to the Git tab and change build settings from Nixpacks to Dockerfile. Set Dockerfile Path to Dockerfile and Dockerfile Context to ”.”
  4. Inside the service settings, set the port to 8002
  5. Go to Environment Variables and add the variables from .env.example.
The required ones: Add any other settings from .env.example as needed (LLM_MODEL, EMBEDDING_MODEL, etc.). Note: The PG_CONN hostname must match the name of your pgvector Docker service (step 4). Set the user, password, and database name to match your Postgres service (step 3).

Step 3: Create the PostgreSQL database

  1. Click Create > in the list of services, go to Databases > Postgres
  2. This creates a Postgres instance from a built-in template — it’s automated
  3. The only thing you need to configure is the environment variables:
These values must match what you put in PG_CONN in step 2.

Step 4: Create the pgvector service (Docker)

The app needs the pgvector extension for vector search. Create a Docker service for it:
  1. Click Create > Docker
  2. Docker image: ankane/pgvector:latest
  3. Name this service to match the hostname in your PG_CONN (e.g., pgvector)
  4. Deploy the service
  5. After it’s running, add a volume mounted at /var/lib/postgresql/data for persistent storage
  6. Add internal port 5432

Step 5: Deploy and verify

  1. All three services should show as running
1
  1. Check the app service logs — you should see database migrations and the worker starting
  2. Open the public URL for your app service. Register a user and start chatting.

Troubleshooting

Optional: Google Sign-In

To enable Google OAuth login:
  1. Go to Google Cloud Console and create a project (or use an existing one)
  2. Navigate to APIs & Services > OAuth Consent Screen and configure it
  3. Go to Credentials > Create OAuth Client ID > Web Application
  4. Under Authorized redirect URIs, add your bult.ai callback URL. The format is:
For example: https://rag-bultai-raga-season.fin1.bult.app/api/auth/google/callback Important: The redirect URI in Google Cloud Console must exactly match your app’s public URL on bult.ai. You can find this URL in your app service settings on the bult.ai dashboard.
  1. Copy the Client ID and Client Secret, then add these environment variables to your app service:
  1. Redeploy. The login page will show a “Sign in with Google” button.

Local Development

Prerequisites

  • Python 3.10+
  • PostgreSQL 14+ with pgvector extension
  • OpenAI API key

Setup

A background worker starts automatically with the app. To run additional workers for faster document processing, open a separate terminal:
Open http://localhost:8002. Register a user and start uploading documents.

How It Works

Document processing pipeline

  1. User uploads a file through the web UI
  2. A background job is created (status: queued)
  3. The worker picks up the job and processes the document:
  • Loads the file with PyMuPDF (PDFs) or LlamaIndex readers (other formats)
  • Detects if the PDF has a text layer — if not, runs OCR (Tesseract)
  • Optionally extracts tables with pdfplumber
  • Splits text into chunks (semantic or fixed-size, configurable)
  • Generates embeddings via OpenAI API
  • Stores chunks + embeddings in PostgreSQL with pgvector
  1. Document status updates in real time: queued > processing > ready

Query pipeline

  1. User asks a question in a conversation
  2. The query goes through optional transformations: HyDE, multi-query expansion, decomposition
  3. Hybrid search combines BM25 keyword matching + vector similarity (configurable alpha balance)
  4. Cross-encoder reranks the top candidates for precision
  5. Top chunks are sent to the LLM with a system prompt that enforces inline citations
  6. Response streams back to the UI character by character
Uploading files:
3
Document stats:
4

Configuration

All settings are controlled through environment variables. Copy .env.example to .env and adjust as needed.

Required

LLM provider

RAG tuning

These have sensible defaults and don’t need to be set unless you want to experiment:

Project Structure


API Reference

All endpoints except /api/health and /api/auth/ require a JWT token in the Authorization: Bearer <token> header.

Authentication

Projects & Documents

Chat

Analytics

2

System


Example: Send Chat Message

Request: POST /api/chat {\ "project_id": 1,\ "conversation_id": 12,\ "message": "Summarize section 3 of the contract"\ } Headers: Authorization: Bearer <your_jwt_token> Response:
Server Sent Events stream with incremental tokens.

Customization

Change LLM provider

Set LLM_PROVIDER and the corresponding API key in .env:

Customize the system prompt

Edit SYSTEM_PROMPT in core/config.py to change how the LLM responds — citation style, tone, response structure, etc.

Change the UI theme

Edit CSS variables in static/index.html. The UI supports light and dark mode.

Default Retrieval Configuration

  • Embedding model: text-embedding-3-large
  • Embedding dimension: 3072
  • Chunk size: 1024 tokens
  • Chunk overlap: 200 tokens
  • Top K before reranking: 50
  • Top K after reranking: 8
  • Hybrid search alpha: 0.5