CoolFace
Apppublic

aarushi63/scholarship-rag

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

๐ŸŽ“ ScholarMatch AI

An AI-powered scholarship discovery and recommendation platform for Indian students.

ScholarMatch AI uses Retrieval-Augmented Generation (RAG) to match students with relevant government scholarship schemes based on their profile โ€” caste category, state, income, and education level. An integrated AI chat advisor powered by Google Gemini answers student queries with cited, grounded responses.

Dataset: 45 government scholarship schemes ยท 180 text chunks ยท Hybrid retrieval latency ~200 ms ยท Recall@5 43% on a 6-example golden set

โœจ Features

  • โ€”Hybrid Search โ€” Combines dense semantic embeddings (BAAI/bge-small-en-v1.5) with sparse TF-IDF vectors in Qdrant for accurate retrieval.
  • โ€”AI Chat Advisor โ€” Gemini 2.5 Flash generates grounded answers, linking to specific scheme pages.
  • โ€”Personalised Recommendations โ€” Schemes are ranked by an eligibility scorer that weighs the user's category, state, income, and education level.
  • โ€”User Accounts โ€” JWT-based auth with profile management (category, state, income, education level).
  • โ€”Saved Schemes โ€” Users can bookmark and manage their favourite scholarships.
  • โ€”Dashboard โ€” At-a-glance stats and personalised scheme highlights.
  • โ€”PDF Ingestion โ€” Parse government scholarship notification PDFs to automatically extract structured scheme data.
  • โ€”RAGAS Evaluation โ€” Built-in RAG evaluation pipeline (eval/) to measure retrieval quality.

๐Ÿ—‚๏ธ Project Structure

scholarship_Rag/
โ”œโ”€โ”€ backend/                # FastAPI REST API
โ”‚   โ”œโ”€โ”€ auth/               # JWT authentication
โ”‚   โ”œโ”€โ”€ db/                 # SQLAlchemy models, Postgres & Qdrant clients
โ”‚   โ”œโ”€โ”€ recommendation/     # Eligibility scoring & ranking logic
โ”‚   โ”œโ”€โ”€ routes/             # API route handlers (chat, schemes, profile, saved, dashboard)
โ”‚   โ”œโ”€โ”€ config.py           # Pydantic settings (reads from .env)
โ”‚   โ”œโ”€โ”€ schemas.py          # Pydantic request/response schemas
โ”‚   โ””โ”€โ”€ main.py             # FastAPI app entry point
โ”œโ”€โ”€ frontend/               # Next.js 16 + TypeScript frontend
โ”‚   โ”œโ”€โ”€ app/                # App Router pages
โ”‚   โ””โ”€โ”€ lib/                # Shared utilities & API client
โ”œโ”€โ”€ ingestion/              # Data pipeline: chunk โ†’ embed โ†’ index into Qdrant
โ”‚   โ”œโ”€โ”€ chunker.py          # Splits scheme text into overlapping chunks
โ”‚   โ”œโ”€โ”€ embedder.py         # Dense + sparse embedding generation
โ”‚   โ”œโ”€โ”€ index_data.py       # CLI to index data/sample_schemes.json into Qdrant
โ”‚   โ””โ”€โ”€ schema.py           # SchemeMetadata Pydantic model
โ”œโ”€โ”€ scraper/                # PDF & web scrapers
โ”‚   โ”œโ”€โ”€ pdf_parser.py       # Parse scholarship notification PDFs
โ”‚   โ””โ”€โ”€ sources/            # Source-specific scrapers
โ”œโ”€โ”€ data/                   # Scholarship dataset (JSON) & TF-IDF vectorizer
โ”œโ”€โ”€ eval/                   # RAGAS-based RAG evaluation scripts
โ”œโ”€โ”€ scripts/                # Helper scripts
โ”œโ”€โ”€ docker-compose.yml      # Local Qdrant + Redis + Postgres stack
โ”œโ”€โ”€ render.yaml             # Render.com deployment config (backend)
โ””โ”€โ”€ requirements.txt        # Python dependencies

๐Ÿš€ Getting Started

Prerequisites

ToolVersion
Pythonโ‰ฅ 3.11
Node.jsโ‰ฅ 20
Docker + Docker ComposeLatest

1. Clone the Repository

bash
git clone https://github.com/aarushi2810/scholarship_Rag.git
cd scholarship_Rag

2. Configure Environment Variables

bash
cp .env.example .env

Edit .env and fill in your keys:

VariableWhere to get it
QDRANT_URLQdrant Cloud
QDRANT_API_KEYQdrant Cloud dashboard
QDRANT_COLLECTIONSet to scholarships (default)
REDIS_URLUpstash (optional)
DATABASE_URLNeon PostgreSQL connection string
GEMINI_API_KEYGoogle AI Studio
JWT_SECRETGenerate with openssl rand -hex 32
EMBEDDING_MODELBAAI/bge-small-en-v1.5 (default)
EMBEDDING_DIM384 (default)
Note: For local development you can run the full database stack with Docker (see step 3) and set DATABASE_URL to postgresql+asyncpg://postgres:postgres@localhost:5432/scholarshiprag.

3. Start Local Services (Docker)

bash
docker compose up -d

This starts Qdrant (port 6333), Redis (port 6379), and PostgreSQL (port 5432).

4. Set Up Python Backend

bash
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt

5. Index the Scholarship Data

bash
python -m ingestion.index_data

This reads data/sample_schemes.json, generates dense + sparse embeddings, and uploads them to your Qdrant collection.

6. Run the Backend

bash
uvicorn backend.main:app --reload --port 8000

API docs available at http://localhost:8000/docs.

7. Run the Frontend

bash
cd frontend
npm install
npm run dev

Frontend available at http://localhost:3000.


๐Ÿ”Œ API Overview

MethodEndpointDescription
POST/auth/registerRegister a new user
POST/auth/loginLogin and receive JWT
GET/profileGet current user profile
PUT/profileUpdate user profile
GET/schemesBrowse scholarship schemes
GET/schemes/{scheme_id}Get a single scheme
POST/recommendationsGet personalised scheme recommendations
POST/chatAsk the AI advisor a question (RAG)
GET/savedList saved/bookmarked schemes
POST/saved/{scheme_id}Save a scheme
DELETE/saved/{scheme_id}Remove a saved scheme
GET/dashboardDashboard stats for the current user
GET/healthHealth check

๐Ÿง  How the RAG Pipeline Works

mermaid
flowchart TD
    A["User message"] --> B["Intent detection"]
    B --> C["Entity extraction\n(state, category, income, education)"] 
    C --> D["Query rewriting\n(vague queries only)"] 
    D --> E["Hybrid search โ€” Qdrant\nDense: BGE-small cosine + Sparse: TF-IDF BM25\ntop-20 candidates"]
    E --> F["FlashRank cross-encoder reranking\ntop-7 passages"]
    F --> G["Eligibility scoring\nweighted match: category ยท state ยท education ยท deadline"]
    G --> H["Gemini 2.5 Flash\nsystem prompt tailored to intent\nretry + exponential backoff"]
    H --> I["Response formatting\nemoji strip ยท citation injection ยท 600-word cap"]
    I --> J["Chat response + source citations"]

    subgraph Caches
        K["Embedding cache\nTTL 30 min"]
        L["Result cache\nTTL 5 min"]
    end
    E --> K
    E --> L
StageLatency (p50)
Hybrid retrieval (Qdrant)~150 ms
FlashRank reranking~30 ms
Eligibility ranking~5 ms
Gemini generation~2โ€“8 s
End-to-end (retrieval only)~200 ms

๐Ÿ“„ Ingesting New PDFs

Use the built-in PDF parser to extract scholarship data from government notification PDFs:

bash
# Parse a single PDF
python -m scraper.pdf_parser data/raw/pdfs/nsp_notification.pdf

# Parse all PDFs in a directory
python -m scraper.pdf_parser data/raw/pdfs/

The parser extracts: scheme name, eligibility text, income ceiling, deadline, benefits, documents required, caste categories, and education levels โ€” all via regex heuristics tuned for government document formats.


๐Ÿ“Š Running RAG Evaluation

The eval/ directory contains retrieval evaluation scripts measuring recall and latency.

bash
# Run the hybrid retrieval benchmark (dense vs hybrid comparison)
python -m eval.run_retrieval_eval

# Inspect raw passage payloads from Qdrant
python eval/scratch/inspect_payloads.py

Results on the 6-example golden set: | Metric | Dense only | Hybrid | |--------|-----------|--------| | Recall@5 | 40.5% | 43.0% | | Latency (p50) | ~337 ms | ~203 ms |


๐Ÿณ Docker Deployment

The backend ships with a Dockerfile and the project includes a render.yaml for one-click deployment to Render.com:

bash
# Build and run backend container locally
docker build -f backend/Dockerfile -t scholarmatch-backend .
docker run -p 8000:8000 --env-file .env scholarmatch-backend

๐Ÿ› ๏ธ Tech Stack

LayerTechnology
BackendFastAPI, SQLAlchemy (async), asyncpg
FrontendNext.js 16, React 19, TypeScript
Vector DBQdrant (dense + sparse hybrid)
Relational DBPostgreSQL (Neon / Docker)
CacheRedis (Upstash / Docker)
Embeddingssentence-transformers โ€” BAAI/bge-small-en-v1.5
Sparse IndexTF-IDF (scikit-learn)
Re-rankerFlashRank
LLMGoogle Gemini 2.5 Flash
AuthJWT (python-jose, passlib)
PDF Parsingpdfplumber
Web ScrapingPlaywright, BeautifulSoup4
EvaluationRAGAS

โš ๏ธ Known Limitations

  • โ€”Dataset coverage: 45 government schemes covering 9 Indian states + All-India schemes. Private scholarships and institution-specific awards are not included.
  • โ€”Tamil Nadu and some other states have no state-specific schemes in the dataset; queries default correctly to All-India scholarships.
  • โ€”Gemini dependency: Chat requires a valid GEMINI_API_KEY. If unavailable, the advisor falls back to structured plain-text answers from retrieved passages.
  • โ€”English only: Queries must be in English; regional language support is not implemented.
  • โ€”Income data: Some older schemes have no income ceiling in the dataset; eligibility scoring treats them as income-unrestricted.

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch: git checkout -b feature/my-feature
  3. 3.Commit your changes: git commit -m "Add my feature"
  4. 4.Push the branch: git push origin feature/my-feature
  5. 5.Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License.