File size: 2,469 Bytes
409c17a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---

title: RAG Onboarding Backend
emoji: 🚀
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
---


# RAG Onboarding Backend - HuggingFace Space

Production-ready RAG (Retrieval-Augmented Generation) backend for corporate employee onboarding, deployed on HuggingFace Spaces.

## 🌟 Features

- **FastAPI REST API** - High-performance async API
- **HuggingFace Models** - Open-source LLMs and embeddings
- **Vector Search** - Qdrant for similarity search
- **Caching** - Redis for performance optimization
- **Monitoring** - Prometheus metrics
- **Clean Architecture** - Production-grade code structure

## 🚀 Quick Start

### API Endpoints

- `GET /` - Service info
- `GET /health` - Health check
- `POST /api/v1/query` - RAG query processing
- `GET /api/v1/metrics` - Prometheus metrics
- `GET /docs` - Interactive API documentation

### Example Query

```bash

curl -X POST "https://YOUR-SPACE-NAME.hf.space/api/v1/query" \

  -H "Content-Type: application/json" \

  -d '{

    "query_text": "What is the onboarding process?",

    "department": "HR",

    "top_k": 5

  }'

```

## 🔧 Configuration

Set the following secrets in your HuggingFace Space settings:

- `GEMINI_API_KEY` - Your Google Gemini API key
- `DATABASE_URL` - PostgreSQL connection string (use external DB like Supabase/Neon)
- `REDIS_URL` - Redis connection string (use Upstash Redis)
- `QDRANT_URL` - Qdrant vector DB URL (use Qdrant Cloud)
- `QDRANT_API_KEY` - Qdrant API key (if using cloud)

## 📊 Models Used

- **LLM**: Google Gemini 2.0 Flash (via API)
- **Embeddings**: `sentence-transformers/all-MiniLM-L6-v2`
- **Reranking**: `cross-encoder/ms-marco-MiniLM-L-12-v2` (optional)

## 🏗️ Architecture

```

┌─────────────┐

│   Client    │

└──────┬──────┘



┌─────────────┐

│  FastAPI    │

└──────┬──────┘


       ├─────► PostgreSQL (Documents)

       ├─────► Redis (Cache)

       ├─────► Qdrant (Vectors)

       └─────► Google Gemini (LLM)

```

## 📝 License

MIT License - See LICENSE file for details

## 🤝 Contributing

Contributions welcome! Please open an issue or submit a PR.

## 📧 Support

For questions or issues, please open a GitHub issue.