Skip to content

Repository files navigation

title GitRAG API
emoji πŸ”
colorFrom indigo
colorTo purple
sdk docker
pinned false
license mit
app_port 7860

GitRAG

Ask natural-language questions about any public GitHub repository β€” and get answers grounded in actual source code, with exact file paths and line numbers.

CI/CD Python 3.13 License: MIT

Live demo: gitrag.vercel.app Β Β·Β  API: yanou16-gitgub-rag.hf.space


Architecture

System overview

System architecture

RAG pipeline

RAG pipeline

How it works

GitHub repo
    β”‚
    β–Ό
AST-aware chunking          β€” splits files into semantic units (functions, classes)
    β”‚
    β–Ό
Embeddings (text-embedding-3-small) + BM25 index
    β”‚
    β–Ό
Hybrid retrieval (semantic + BM25 β†’ Reciprocal Rank Fusion)
    β”‚
    β–Ό
Cohere reranking            β€” cross-encoder rescores top 20 β†’ keeps best 5
    β”‚
    β–Ό
Groq llama-3.3-70b          β€” generates a grounded answer with file citations

Supported languages: Python, JavaScript/TypeScript, C#, Java, C/C++, Go, Rust, Ruby, PHP, Swift, Kotlin, Dart, Vue, Svelte, Shell, SQL, HTML, CSS, JSON, YAML, TOML, XML


Project structure

gitrag/
β”œβ”€β”€ app/                        # FastAPI backend
β”‚   β”œβ”€β”€ main.py                 # App entry point, middleware, CORS
β”‚   β”œβ”€β”€ config.py               # Settings via environment variables
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ ingest.py           # POST /ingest β€” clone, chunk, embed, store
β”‚   β”‚   β”œβ”€β”€ query.py            # POST /query  β€” hybrid search + rerank + LLM
β”‚   β”‚   └── health.py           # GET  /health β€” liveness check
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ github.py           # GitHub API client (file listing + content fetch)
β”‚   β”‚   β”œβ”€β”€ chunker.py          # AST-aware code chunking
β”‚   β”‚   β”œβ”€β”€ embedder.py         # OpenAI-compatible embedding service
β”‚   β”‚   β”œβ”€β”€ vector_store.py     # ChromaDB wrapper (upsert, similarity search)
β”‚   β”‚   β”œβ”€β”€ hybrid_search.py    # BM25 + semantic β†’ RRF fusion
β”‚   β”‚   β”œβ”€β”€ reranker.py         # Cohere reranking
β”‚   β”‚   └── llm.py              # Groq LLM answer generation
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── schemas.py          # Pydantic request/response models
β”‚   └── utils/
β”‚       β”œβ”€β”€ hashing.py          # URL β†’ stable repo_id
β”‚       └── retry.py            # Async retry decorator
β”œβ”€β”€ frontend/                   # React + Vite frontend (deployed on Vercel)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/         # Navbar, Hero, HowItWorks, Tool, Footer
β”‚   β”‚   β”œβ”€β”€ api.js              # API client (ingestRepo, queryRepo)
β”‚   β”‚   └── App.jsx
β”‚   β”œβ”€β”€ tailwind.config.cjs
β”‚   └── vite.config.js
β”œβ”€β”€ tests/                      # pytest integration tests (40 tests)
β”œβ”€β”€ Dockerfile                  # Production image for HuggingFace Spaces
β”œβ”€β”€ docker-compose.yml          # Local dev with Docker
└── requirements.txt

Quick start

Prerequisites

  • Python 3.13+
  • API keys: OpenAI-compatible embeddings, Groq, Cohere (optional)

Run locally

git clone https://github.com/yanou16/Git_RAG.git
cd Git_RAG

# Backend
cp .env.example .env        # fill in your API keys
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000

# Frontend (separate terminal)
cd frontend
npm install
npm run dev                  # http://localhost:3000

Run with Docker

docker compose up --build

API reference

POST /ingest

Index a public GitHub repository.

{
  "repo_url": "https://github.com/tiangolo/fastapi",
  "branch": "master",
  "force_reindex": false
}

Response:

{
  "repo_id": "abc123",
  "files_indexed": 87,
  "chunks_stored": 1243,
  "duration_ms": 18420,
  "was_cached": false
}

POST /query

Ask a question about an indexed repository.

{
  "repo_url": "https://github.com/tiangolo/fastapi",
  "question": "How does dependency injection work?",
  "use_hybrid": true,
  "use_reranking": true
}

Response:

{
  "answer": "Dependency injection in FastAPI works via...",
  "sources": [
    {
      "file_path": "fastapi/dependencies/utils.py",
      "start_line": 145,
      "excerpt": "...",
      "rerank_score": 0.92
    }
  ],
  "pipeline": "hybrid+rerank",
  "tokens_used": 1247,
  "latency_ms": 1834
}

GET /health

{ "status": "ok", "version": "1.0.0" }

Deployment

Backend β€” HuggingFace Spaces (Docker)

  1. Fork this repo
  2. Create a Space at huggingface.co/spaces with Docker SDK
  3. Add your HF Space as a git remote: git remote add hf https://huggingface.co/spaces/<user>/<space>
  4. Set secrets in Space Settings:
Secret Description
ANIMUSAI_API_KEY OpenAI-compatible key for text-embedding-3-small
ANIMUSAI_BASE_URL e.g. https://api.openai.com/v1
GROQ_API_KEY console.groq.com
COHERE_API_KEY Optional β€” enables reranking
GITHUB_TOKEN Optional β€” raises rate limit from 60 to 5000 req/h
  1. Push: git push hf main

Frontend β€” Vercel

  1. Import the repo on vercel.com
  2. Set Root Directory to frontend
  3. Add env var: VITE_API_URL=https://<your-space>.hf.space
  4. Deploy

Tests

pip install -r requirements-dev.txt
pytest tests/ -v

40 integration tests covering ingest, query, chunking, hybrid search, and health endpoints.


Tech stack

Layer Technology
API FastAPI + Uvicorn
Embeddings OpenAI text-embedding-3-small
Vector store ChromaDB (persistent)
Keyword search BM25 (rank-bm25)
Fusion Reciprocal Rank Fusion
Reranking Cohere rerank-v3.5
LLM Groq llama-3.3-70b-versatile
Frontend React + Vite + Tailwind CSS
Hosting HuggingFace Spaces (backend) + Vercel (frontend)

Author

Rayane Louzazna β€” LinkedIn Β· GitHub

MIT License

About

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages