File size: 9,215 Bytes
5b7cefd 0f489c0 ba403c6 5b7cefd 459c4bf 0f489c0 5b7cefd 0f489c0 94b2282 0f489c0 94b2282 | 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | ---
title: UAE Knowledge System
emoji: π¦
colorFrom: green
colorTo: yellow
sdk: gradio
sdk_version: 5.0.0
app_file: app.py
pinned: false
short_description: Information Retrieval system for UAE governance and safety
thumbnail: https://librai-uae-kb.hf.space/assets/preview.png
---
# UAE Knowledge System
An Information Retrieval (IR) system designed to retrieve relevant knowledge about the United Arab Emirates from a curated knowledge base.
**This is NOT an LLM chatbot** - it retrieves pre-written factual content intended to be used as RAG context.
## Version
- **Current Version**: 2.4.0
- **Last Updated**: February 2026
- **IR Performance**: 69% Precision@1, 88% Recall@5, ~30ms latency on GPU
## Features
- 8 knowledge categories covering UAE governance, leadership, and policies
- Multilingual support (English, Arabic, Chinese)
- Dense retrieval using BGE-M3 embeddings
- Real-time translation via DeepL
---
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HF Spaces / Local β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β app.py (Entry Point) β
β βββ uvicorn.run("backend.api:app") β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββ β
β β Frontend (HTML) β β Backend (FastAPI) β β
β β β β β β
β β frontend/ βββββΆβ backend/api.py β β
β β βββ index.html β β βββ GET / β β
β β βββ css/styles.css β β βββ GET /api/stats β β
β β βββ js/app.js β β βββ POST /api/search β β
β β β β βββ POST /api/feedback β β
β β (Static files β β βββ POST /api/translate β β
β β served by FastAPI)β β β β
β βββββββββββββββββββββββ β backend/services.py β β
β β βββ get_retriever() β β
β β βββ search_knowledge_base() β β
β βββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β IR Module (ir/) β β
β β β β
β β retriever.py ββββββΆ retrievers/dense.py (BGE-M3) β β
β β β β β β
β β βΌ βΌ β β
β β knowledge_base.py cache/dense_index/ β β
β β β βββ faiss_index_bge-m3.bin β β
β β βΌ βββ chunk_metadata_bge-m3.json β β
β β uae_knowledge_build/data/unified_KB/ β β
β β βββ entities.json (5000+ entities) β β
β β βββ alias_index.json β β
β β βββ sensitive_topics.json β β
β β βββ category_metadata.json β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
---
## Project Structure
```
hf_uae_demo/
βββ app.py # Entry point (starts FastAPI server)
βββ requirements.txt # Python dependencies
βββ README.md # This file
β
βββ backend/ # FastAPI backend
β βββ __init__.py
β βββ api.py # API endpoints & version info
β βββ services.py # Retriever initialization
β
βββ frontend/ # Static frontend (served by FastAPI)
β βββ index.html # Main HTML (version in help modal)
β βββ css/styles.css # Styles
β βββ js/app.js # JavaScript (TRANSLATIONS object)
β βββ assets/ # Images (falcon.png, background.jpg)
β
βββ ir/ # Information Retrieval module
β βββ __init__.py
β βββ retriever.py # Main retriever interface
β βββ knowledge_base.py # KB loader
β βββ models.py # Data models
β βββ normalizer.py # Text normalization
β βββ sensitive_detector.py # Sensitivity detection
β βββ sheets_storage.py # Google Sheets feedback storage
β βββ retrievers/ # Retriever implementations
β β βββ dense.py # BGE-M3 dense retrieval (Level 4)
β β βββ bm25.py # BM25 keyword retrieval
β β βββ alias.py # Alias matching
β β βββ hybrid.py # Hybrid retrieval
β βββ cache/dense_index/ # FAISS index cache
β βββ faiss_index_bge-m3.bin
β βββ chunk_metadata_bge-m3.json
β
βββ uae_knowledge_build/data/unified_KB/ # Knowledge base
β βββ entities.json # Main entity data
β βββ alias_index.json # Entity aliases
β βββ sensitive_topics.json # Sensitivity info
β βββ category_metadata.json # Category metadata
β
βββ data/ # User feedback storage
βββ feedback.json
βββ ratings.json
βββ translations_cache.json
```
---
## Update Guide
### When updating Knowledge Base (unified_KB)
1. **Build new KB** in `libra_shield/uae_knowledge_build/`
2. **Copy KB files** to `hf_uae_demo/uae_knowledge_build/data/unified_KB/`
3. **Rebuild FAISS index** on GPU (Spartan HPC):
```bash
python -m ir.evaluate_dense --model bge-m3 --save-index ir/cache/dense_index --debug
```
4. **Copy index files** to `hf_uae_demo/ir/cache/dense_index/`
### When updating Version Info
**Files to update (in order of importance):**
| File | What to update |
|------|----------------|
| `frontend/js/app.js` | `TRANSLATIONS` object (EN/AR/CN): `helpDataText`, `helpIRText`, `helpVersion` |
| `frontend/index.html` | Help modal content, footer copyright |
| `backend/api.py` | FastAPI `version` parameter |
**Important**: `app.js` TRANSLATIONS override `index.html` content at runtime via `updateHelpModal()`. Always update `app.js` first!
### Version checklist
When releasing a new version, update these locations:
- [ ] `frontend/js/app.js` line 3: `Version: X.X.X`
- [ ] `frontend/js/app.js` TRANSLATIONS.en.helpVersion
- [ ] `frontend/js/app.js` TRANSLATIONS.en.helpDataText (Last updated date)
- [ ] `frontend/js/app.js` TRANSLATIONS.en.helpIRText (Performance metrics)
- [ ] `frontend/js/app.js` TRANSLATIONS.ar.helpVersion, helpDataText, helpIRText
- [ ] `frontend/js/app.js` TRANSLATIONS.cn.helpVersion, helpDataText, helpIRText
- [ ] `frontend/index.html` line 240: Version in help modal
- [ ] `frontend/index.html` line 250: Footer copyright year
- [ ] `backend/api.py` line 60: FastAPI version
---
## Local Development
```bash
# Activate conda environment
conda activate libra_shield
# Run the server
cd hf_uae_demo
python app.py
# Open in browser
open http://localhost:7860
```
---
## Deployment (HuggingFace Spaces)
```bash
cd hf_uae_demo
git add .
git commit -m "Update to vX.X.X"
git push
```
---
Powered by [LibrAI](https://www.librai.tech/)
|