Grounding Engine is the backend service for Grounded, a Retrieval-Augmented Generation platform for answering questions over user-owned documents with citations, evidence traces, and tiered verification.
This repository contains the API, ingestion pipeline, retrieval system, verification logic, background workers, database migrations, benchmark tooling, and backend tests. The frontend/client application is maintained separately.
Grounding Engine turns uploaded documents into queryable, traceable knowledge bases.
- Manages tenants, workspaces, datasets, agents, conversations, API keys, and team members
- Uploads, extracts, chunks, stores, and indexes documents
- Runs sparse + dense hybrid retrieval over indexed content
- Packages evidence for grounded answer generation
- Produces cited answers with response shaping and degraded behavior when evidence is weak
- Records query traces, run history, feedback, audit logs, and dashboard summaries
- Supports async processing for longer-running high-assurance workflows
- Provides benchmark fixtures, reports, raw outputs, and evaluation tooling
The backend supports three execution tiers:
| Tier | Backend Behavior |
|---|---|
| Standard | Fast baseline RAG with hybrid retrieval, citations, evidence packaging, and traces |
| Enterprise | Stronger retrieval precision with reranking, freshness scoring, and richer evidence selection |
| Critical | High-assurance verification with contradiction handling, corrective retry, and async runs |
Client / API consumer
|
v
FastAPI routes
|
v
Services: auth, datasets, documents, agents, conversations, query, runs
|
v
Pipeline: extraction -> chunking -> sparse/dense indexing -> retrieval -> generation -> verification
|
v
PostgreSQL + Qdrant + Redis + S3-compatible storage
| Area | Tools |
|---|---|
| API | FastAPI, Pydantic |
| Database | PostgreSQL, SQLAlchemy, Alembic |
| Retrieval | Qdrant, sparse indexing, dense embeddings, reranking hooks |
| Workers | Redis, ARQ |
| Storage | MinIO / S3-compatible object storage |
| Testing | pytest |
| Evaluation | Custom benchmark runner, benchmark fixtures, BEIR/NFCorpus support |
backend/
app/
api/ FastAPI routes and dependencies
core/ Shared infrastructure, security, retrieval clients
models/ SQLAlchemy models
pipeline/ Ingestion and query pipeline orchestration
schemas/ Request and response schemas
services/ Business logic
workers/ Background worker entrypoints
alembic/ Database migrations
reports/ Benchmark reports, summaries, and raw outputs
scripts/ Utility scripts
tests/ Unit, integration, contract, load, and evaluation tests
docs/ System design, API flow, product flow, benchmarks
.env.example Public environment template
docker-compose.yml Local infrastructure
docker-compose.dev.yml Backend development stack
Makefile Common backend commands
requirements.txt Python dependencies
- Python 3.11+
- Docker Desktop
- Git
Clone the repository:
git clone https://github.com/Grounded-RAG/grounding-engine.git
cd grounding-engineCreate a local environment file:
cp .env.example .envStart local infrastructure:
docker compose up -d postgres redis qdrant minioCreate and activate a virtual environment:
python -m venv backend/.venv
source backend/.venv/bin/activateOn Windows PowerShell:
backend\.venv\Scripts\Activate.ps1Install dependencies and apply migrations:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
cd backend
python -m alembic upgrade headRun the API:
python -m uvicorn app.main:app --reloadLocal endpoints:
- API:
http://localhost:8000 - Swagger docs:
http://localhost:8000/docs - Health check:
http://localhost:8000/health/ready - MinIO console:
http://localhost:9001
make infra-up # Start PostgreSQL, Redis, Qdrant, and MinIO
make migrate # Apply database migrations
make test # Run backend tests
make ci # Run compile, migration, and foundation test checks
make infra-down # Stop local infrastructureRun tests directly:
cd backend
pytestRun a compile check:
python -m compileall backend/app backend/tests backend/alembicBenchmark assets are intentionally included for evaluation transparency.
Key locations:
backend/tests/evaluation/: benchmark runner, schema, variants, fixtures, and testsbackend/reports/benchmark-current/: current benchmark report, summary, and raw resultsbackend/reports/benchmark-beir-nfcorpus/: BEIR/NFCorpus report, summary, queries, and raw resultsdocs/BENCHMARKING_README.md: benchmark usage notesdocs/BENCHMARK_AND_PERFORMANCE_OPTIMIZATION_PLAN.md: evaluation and optimization plan
Run the BEIR/NFCorpus benchmark when the dataset is available locally:
make benchmark-beirRun a smaller smoke benchmark:
make benchmark-beir-smokedocs/SYSTEM_DESIGN.md: backend architecture, runtime flow, and tier behaviordocs/PRODUCT_FLOW.md: product objects and backend-supported workflowsdocs/SWAGGER_TEST_FLOW.md: manual API testing flowdocs/BENCHMARKING_README.md: benchmark setup and interpretationdocs/BENCHMARK_ISSUE_BACKLOG.md: known benchmark gaps and follow-up work
Use .env.example as the public template. Do not commit local .env files, real API keys, provider secrets, database credentials, or private tokens.
FRONTEND_URL is still a backend setting because OAuth, email, and invitation flows need the URL of the separately hosted client application.