Building a Multi-Tenant RAG API with rag-api

The Problem

Dealing with document Q&A at scale is a nightmare. PDFs, images, Word files—every format demands its own parsing, and don’t get me started on OCR. Add multi-tenancy into the mix, with isolated data and custom logic per tenant, and you're drowning in complexity. Most open-source tools give you one piece of the puzzle: vector search, OCR, or maybe a knowledge graph. But what if you need all of it, and it has to just work?

What This Does

rag-api is a multi-tenant Retrieval-Augmented Generation (RAG) service that combines LightRAG and RAG-Anything for intelligent document Q&A. It auto-selects the best parser—DeepSeek-OCR, MinerU, or Docling—based on document complexity (src/smartparserselector.py). No need to guess which tool to use; it figures it out.

The project is cleanly organized. The api/ folder handles endpoints like documents.py (file ingestion), query.py (retrieval), and tenant.py (tenant management). The brains of the operation live in src/, where modules like documentcomplexity.py and rag.py handle parsing and retrieval. Oh, and deployment? Dead simple. There's a Dockerfile, docker-compose.yml, and even a deploy.sh script to get you started in minutes.

Real-World Use

Say you're building a SaaS platform where businesses upload contracts, invoices, and scanned forms for Q&A. Here's what your workflow might look like: Deploy the service (docker-compose up). Upload a batch of files via the /documents endpoint (check out api/documents.py). Behind the scenes, smartparserselector.py picks the best parser (OCR for images, direct insertion for text). Query the data using /query (hello, hybrid retrieval with LightRAG).

Example cURL request to upload files:

curl -X POST -F "file=@contract.pdf" http://localhost:8000/documents

And retrieving info:

curl -X GET "http://localhost:8000/query?question=What%20is%20the%20contract%20value?"

Multi-tenancy? Each tenant has isolated storage and config (api/tenantconfig.py), so no cross-contamination.

The Bottom Line

rag-api is overkill for small projects but perfect for enterprise-level document Q&A with multi-tenancy. It’s opinionated but flexible: great parser selection, hybrid retrieval, and Redis-based task persistence. Just don’t expect hand-holding—the docs are there, but you’ll need to dig in. If you're wrangling complex document processing at scale, this is your new best friend.