annyss/palestine-smart-library
0
๐ต๐ธ Palestine Smart Library โ AI for Palestine Competition
A RAG-based (Retrieval-Augmented Generation) multilingual chatbot answering questions on the Palestinian cause from 15 official documents, with zero hallucination.
Features
Architecture
User Query (Arabic or English)
โ
โผ
Language Detection (langdetect)
โ
โผ
Query Embedding: "query: {text}"
[multilingual-e5-large]
โ
โผ
FAISS IndexFlatIP (cosine similarity)
top-k=5 chunks retrieved
โ
โผ
Similarity Threshold โฅ 0.35?
NO โ "Not found in documents"
YES โ Continue
โ
โผ
LLM (Qwen3-30B-A3B-Thinking via OpenAI-compatible API)
Strict system prompt โ no external knowledge
โ
โผ
Answer + Citations [Title, Page X]
(in same language as query)Tech Stack
Quick Start
1. Clone and configure
git clone <repo>
cd coderag
cp .env.example .env
# Edit .env โ add your API key and model endpoint2. Install dependencies
pip install -r requirements.txt3. Build the FAISS index (run once)
python build_index.py
# Takes ~5-15 min first time (downloads multilingual-e5-large + embeds 15 PDFs)
# Saves index/faiss.index + index/metadata.pkl for instant reload4. Run the app
python app.py
# Open http://localhost:7860Environment Variables (.env)
LLM_PROVIDER=openai_compatible # "groq" or "openai_compatible"
OPENAI_COMPATIBLE_KEY=sk-... # API key
OPENAI_COMPATIBLE_BASE_URL=https://api.together.xyz/v1
OPENAI_COMPATIBLE_MODEL=Qwen/Qwen3-30B-A3B-Thinking
GROQ_API_KEY=gsk_... # Only needed if LLM_PROVIDER=groq
EMBEDDING_MODEL=intfloat/multilingual-e5-largeDocument Corpus (15 PDFs)
English (8)
- UN General Assembly Resolution 194 (1948)
- UNRWA Technical Report 2024
- Humanitarian Situation Update 176 โ Gaza Strip (OCHA)
- Gaza Update Report โ November 2024 (OPT)
- Israel-Palestine History Timeline 2024โ25
- Palestinian Historical Calendar
- Palestinian Identity โ Rashid Khalidi
- The Hundred Years' War on Palestine
Arabic (7)
- ุชูุฑูุฑ ุบุฒุฉ ุงูุฅูุณุงูู 2024
- ุฐุงูุฑุฉ ุงูู ูุงู
- ุดุฎุตูุงุช ููุณุทูููุฉ
- ููุณุทูู ุงูุนุฑุจูุฉ
- ููุณุทูู
- ูุชุงุจ ุงููุฎุจุฉ โ ุงูุฌุฒุก ุงูุฃูู
- ูุชุงุจ ุงููุฎุจุฉ โ ุงูุฌุฒุก ุงูุซุงูู
Anti-Hallucination Design
- Vector similarity threshold: Best retrieved chunk cosine similarity < 0.35 โ system returns the exact string "This information was not found in the available documents." โ LLM is never called.
- Strict system prompt: LLM instructed to answer only from provided excerpts, cite sources, and not use external knowledge.
- Temperature = 0.1: Minimal creativity, maximum factuality.
- No web search: Completely offline retrieval (no external APIs during inference).
Project Structure
coderag/
โโโ app.py # Main Gradio app
โโโ build_index.py # One-time index builder
โโโ requirements.txt
โโโ .env # API keys (never commit)
โโโ .env.example
โโโ official_docs/ # 15 PDFs
โโโ index/ # FAISS index (built by build_index.py)
โโโ rag/
โ โโโ document_loader.py # PDF loading + chunking + metadata
โ โโโ embeddings.py # multilingual-e5-large wrapper
โ โโโ vector_store.py # FAISS wrapper with dynamic add
โ โโโ generator.py # LLM generation + anti-hallucination
โโโ tabs/
โ โโโ chat_tab.py
โ โโโ discourse_tab.py
โ โโโ compare_tab.py
โ โโโ summary_tab.py
โ โโโ map_tab.py
โ โโโ timeline_tab.py
โ โโโ wordcloud_tab.py
โ โโโ statistics_tab.py
โ โโโ upload_tab.py
โ โโโ about_tab.py
โโโ utils/
โโโ language.py # Language detectionCompetition
AI for Palestine โ Smart Library Submission deadline: April 24, 2026 Team email: anisbensab@gmail.com
