Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
fa7e1c2
Initial commit
0xunion23 Jun 1, 2026
f3fa19e
initial commit
0xkhush Jun 1, 2026
19a3c3c
Added like, dislike, copy to clipboard, auto scroll, refresh page, me…
Arka-Kanji Jun 1, 2026
08cbcc0
Fix embed_flag.py crash on transformers 5.x, add DESIGN.md, fix port …
Jun 1, 2026
1d5dd0f
Merge pull request #1 from 0xunion23/chat-ui-enhancements
0xunion23 Jun 2, 2026
c99a9c9
Merge pull request #2 from 0xunion23/fix/embed-transformers-compat-an…
0xunion23 Jun 2, 2026
37babbf
initial commit
0xkhush Jun 2, 2026
f1125cb
update requirnment + design.md(changed ollama model name)
0xkhush Jun 2, 2026
9d7ee7b
changed ollama model info
0xkhush Jun 2, 2026
71184ae
added transformers
0xkhush Jun 2, 2026
622ce7d
fix: handle short query embeddings safely
0xkhush Jun 2, 2026
5ddecc1
Feature: Added Auto/Light/Dark theme toggle, Copy & Edit Prompt, and …
Arka-Kanji Jun 2, 2026
6e23f87
perf: speed up RAG retrieval with warm embedding worker
0xkhush Jun 2, 2026
787daa5
Merge pull request #3 from 0xunion23/edit-theme-feature
0xkhush Jun 2, 2026
14e686d
Speed up retrieval with a warm embedding worker
0xkhush Jun 2, 2026
0ed6d03
Merge pull request #4 from 0xunion23/0xcook
0xkhush Jun 2, 2026
a688028
fix : error causing crash
0xkhush Jun 2, 2026
3c13486
noise vs valid query detection 1.0
0xkhush Jun 2, 2026
c36ac46
Merge pull request #5 from 0xunion23/0xcook
0xkhush Jun 2, 2026
13a1218
Create MostAskedQuestion.js
srivatsan1467 Jun 2, 2026
d2f0918
Create normalizeQuestion.js
srivatsan1467 Jun 2, 2026
67bab97
Create mostAskedRoutes.js
srivatsan1467 Jun 2, 2026
eb59fcc
Update index.js
srivatsan1467 Jun 2, 2026
d8a19fb
Update index.js
srivatsan1467 Jun 2, 2026
4d99778
Update mostAskedRoutes.js
srivatsan1467 Jun 2, 2026
5414459
Update index.js
srivatsan1467 Jun 2, 2026
94563e7
Create mostAskedService.js
srivatsan1467 Jun 2, 2026
52167af
Update ragService.js
srivatsan1467 Jun 2, 2026
03576fe
Update main.jsx
srivatsan1467 Jun 2, 2026
6fb1ba0
Update main.jsx
srivatsan1467 Jun 2, 2026
d5488ce
Update main.jsx
srivatsan1467 Jun 2, 2026
45dab5a
Update styles.css
srivatsan1467 Jun 2, 2026
a42b5ed
Added daily search analytics dashboard
jsumanigoud-svg Jun 2, 2026
c48ecb9
some typos
0xkhush Jun 3, 2026
e6926c2
Update main.jsx
srivatsan1467 Jun 3, 2026
9923541
Update main.jsx
srivatsan1467 Jun 3, 2026
5e93511
Update styles.css
srivatsan1467 Jun 3, 2026
5174162
feat: add org FAQ bot creator and shareable link
Ritwij07 Jun 3, 2026
0dcef6a
Merge pull request #11 from Ritwij07/feature/org-faq-bot-v2
0xkhush Jun 3, 2026
5ca1c7d
improved ollama generation
0xkhush Jun 3, 2026
f97d781
fix style issue in create bot
0xkhush Jun 3, 2026
9fbcecd
Merge pull request #15 from 0xunion23/0xcook
Ritwij07 Jun 3, 2026
422b0a6
Merge pull request #14 from 0xunion23/fix-error-create-bot
Ritwij07 Jun 3, 2026
2e449b4
Add duplicate question detection feature
HarshithaKollipara Jun 4, 2026
106eec7
Merge branch 'main' into feature/duplicate-question-detection
0xkhush Jun 4, 2026
17565e3
Merge pull request #18 from 0xunion23/feature/duplicate-question-dete…
0xkhush Jun 4, 2026
e70eb5b
Implemented semantic similarity
srivatsan1467 Jun 4, 2026
db629d5
Added embedding field to MostAskedQuestion model
srivatsan1467 Jun 4, 2026
eeeaa22
feat: upgrade chat UI with read aloud, export, character limits, and …
Arka-Kanji Jun 4, 2026
ed63399
Merge pull request #21 from 0xunion23/chat-tools-and-voice
0xkhush Jun 4, 2026
34b2eda
Merge pull request #19 from 0xunion23/srivatsan1467-patch-1
0xkhush Jun 4, 2026
a4a9dd2
Merge pull request #20 from 0xunion23/srivatsan1467-patch-2
0xkhush Jun 4, 2026
8787577
Fix chat layout and add analytics overlay
0xkhush Jun 5, 2026
d2dfb50
Reduce RAG response latency
0xkhush Jun 5, 2026
b7c1f77
Added auto focus input, dynamic bot greeting and chat memory
Arka-Kanji Jun 5, 2026
992c8f9
Merge pull request #25 from 0xunion23/fixing-error
0xunion23 Jun 5, 2026
c6c427a
Merge pull request #27 from 0xunion23/chat-logic-upgrades
0xkhush Jun 5, 2026
72ba1bd
Update project README
0xkhush Jun 5, 2026
633dc63
Add FAQ search suggestions controller
srivatsan1467 Jun 5, 2026
2436920
Add suggestion routes for FAQ search feature
srivatsan1467 Jun 5, 2026
a964f11
Integrate FAQ search suggestions into chatbot UI
srivatsan1467 Jun 5, 2026
7ab0099
Register FAQ search suggestions API route
srivatsan1467 Jun 5, 2026
e1deb7d
Add prompt injection protection and security dashboard
Sainikhil-hub Jun 5, 2026
e0e2fd7
Merge pull request #28 from 0xunion23/codex/update-readme
Ritwij07 Jun 8, 2026
8d88519
Merge pull request #26 from 0xunion23/codex/rag-latency-preload
Ritwij07 Jun 8, 2026
fd62e3f
Merge pull request #29 from 0xunion23/srivatsan1467-patch-3
0xkhush Jun 8, 2026
fe93e31
Merge pull request #30 from 0xunion23/srivatsan1467-patch-4
0xkhush Jun 8, 2026
e05e6c2
Merge pull request #31 from 0xunion23/srivatsan1467-patch-5
0xkhush Jun 8, 2026
0843a56
Merge branch 'main' into srivatsan1467-patch-6
0xkhush Jun 8, 2026
a457b3c
Merge pull request #32 from 0xunion23/srivatsan1467-patch-6
0xkhush Jun 8, 2026
e6f972f
Merge branch 'main' into security-dashboard-feature
Sainikhil-hub Jun 9, 2026
8e9119a
Show escalation badge for unanswered queries
0xkhush Jun 9, 2026
065b0ad
Merge pull request #33 from 0xunion23/security-dashboard-feature
0xkhush Jun 9, 2026
ad4bedd
fixed some latency issues
0xkhush Jun 9, 2026
b887f8f
here hallucination function in ragservice is slowing down the entire …
0xkhush Jun 9, 2026
ac49192
Merge pull request #38 from 0xunion23/escalation
Ritwij07 Jun 9, 2026
cda6c54
Merge branch 'main' into removing-hallucination
0xkhush Jun 9, 2026
08a3b23
Merge pull request #39 from 0xunion23/removing-hallucination
Ritwij07 Jun 9, 2026
964b50d
login-register-done
0xkhush Jun 9, 2026
97191e1
Polish chatbot header and answer UI
0xkhush Jun 9, 2026
36fff12
Merge pull request #41 from 0xunion23/login-reg-limit
0xunion23 Jun 9, 2026
6e59a2d
improve chatbot reponse
0xkhush Jun 10, 2026
e26d43b
added context memory v1
0xkhush Jun 10, 2026
f5eca43
improved response
0xkhush Jun 10, 2026
000838b
correct:registering issue+
0xkhush Jun 10, 2026
944d831
passes last 3 queries to prompt for more accuracy
0xkhush Jun 10, 2026
49e3dee
chore: increase retrieval top k
0xkhush Jun 10, 2026
3a9632e
Merge pull request #43 from 0xunion23/learning-context
0xunion23 Jun 11, 2026
31ffae0
feat: transfer vled-project codebase
Jun 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
.env
.DS_Store
284 changes: 284 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
# FAQ OxEngine — System Design

## Overview

FAQ OxEngine is a fully local Retrieval-Augmented Generation (RAG) chatbot built for the Vicharanashala internship program at IIT Ropar. It allows users to ask natural language questions and receive accurate, grounded answers sourced from the official FAQ knowledge base — without any external API dependencies.

---

## Architecture

```
┌─────────────────────────────────────────────────────────────┐
│ User Browser │
│ React Frontend (Vite) │
│ localhost:5173 │
└─────────────────────────┬───────────────────────────────────┘
│ POST /api/chat { message }
┌─────────────────────────────────────────────────────────────┐
│ Express API Server │
│ localhost:5001 │
│ │
│ 1. Receives user query │
│ 2. Calls Python subprocess to embed the query │
│ 3. Retrieves top-K similar FAQs from MongoDB │
│ 4. Checks confidence threshold │
│ 5. Sends context + query to Ollama │
│ 6. Returns structured response │
└────────┬──────────────────────┬──────────────────┬──────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Python Process │ │ MongoDB │ │ Ollama │
│ (FlagEmbedding)│ │ faq_vled_rag │ │ gemma3:1b │
│ │ │ │ │ │
│ Embeds query │ │ Stores FAQs │ │ Generates │
│ into 384-dim │ │ + 384-dim │ │ final answer │
│ vector │ │ embedding │ │ from context │
│ │ │ vectors │ │ only │
└─────────────────┘ └──────────────────┘ └─────────────────┘
```

---

## Request Flow

```
User: "Is there a stipend?"
[1] Express receives message
[2] Python embeds query
"Is there a stipend?" → [0.023, -0.041, 0.187, ...] (384 numbers)
[3] Load all FAQ vectors from MongoDB (cached in memory)
Compute dot product similarity against all 148 FAQ vectors
Rank by score, pick top 4
[4] Check confidence
best_score >= MIN_CONFIDENCE (0.45)?
┌──┴──┐
YES NO
│ │
│ ▼
│ Return fallback:
│ "I don't have enough information..."
[5] Build prompt for Ollama:
"Answer using ONLY the retrieved context.
Context 1: [FAQ text]
Context 2: [FAQ text]
...
User question: Is there a stipend?"
[6] Ollama generates grounded answer
[7] Return to client:
{
answer: "Yes, interns receive...",
answerFound: true,
confidence: 0.81,
sources: [{ question, category, score }, ...]
}
```

---

## Components

### Frontend — `client/`

| File | Purpose |
|------|---------|
| `src/main.jsx` | Single-file React app — chat UI, message history, confidence badges, source chips, quick prompts |
| `src/styles.css` | Custom CSS — responsive layout, mobile support |
| `index.html` | HTML entry point |
| `.env` | `VITE_API_URL` — points to Express server |

### Backend — `server/src/`

| File | Purpose |
|------|---------|
| `index.js` | Express app entry — CORS, routes, error handler, MongoDB connect |
| `config/env.js` | All config from environment variables with defaults |
| `models/Faq.js` | Mongoose schema — question, answer, category, tags, embedding, isActive |
| `routes/chatRoutes.js` | `POST /api/chat` — accepts message, returns answer |
| `routes/faqRoutes.js` | `GET/POST /api/faqs` — list and add FAQs |
| `services/ragService.js` | Core RAG logic — retrieval, confidence check, answer generation |
| `services/embeddingService.js` | Spawns Python subprocess, sends texts, receives vectors |
| `services/ollamaService.js` | Calls Ollama `/api/generate` with grounded prompt |
| `python/embed_flag.py` | Loads BGE model, encodes texts, returns JSON embeddings |

### Scripts — `server/src/scripts/`

| Script | Command | Purpose |
|--------|---------|---------|
| `seedFaqs.js` | `npm run seed` | Wipes DB, inserts 6 built-in FAQs with embeddings |
| `reindexFaqs.js` | `npm run reindex` | Re-embeds all existing FAQs (run after manual edits) |
| `importSamagamaFaqs.js` | `npm run import:samagama` | Scrapes samagama.in/internship/faq, embeds and upserts all FAQs |

---

## Knowledge Base

The knowledge base lives in MongoDB (`faq_vled_rag.faqs`). It is populated once and queried at runtime — Samagama is never called during a user query.

| Source | FAQs | Topics |
|--------|------|--------|
| Samagama import | 142 | NOC, stipend, ViBe platform, team formation, Rosetta journal, Spurti points, certificates, code of conduct, interviews |
| Built-in seed | 6 | System architecture, confidence, storage, models |
| **Total** | **148** | |

Each FAQ document stores:
- `question` — the FAQ question text
- `answer` — the full answer text
- `category` — section heading from the source page
- `tags` — searchable labels
- `sourceId` / `sourceUrl` — link back to original source
- `embedding` — 384-dimensional BGE vector for semantic search
- `isActive` — soft delete flag

---

## Embedding & Retrieval

**Model:** `BAAI/bge-small-en-v1.5` (384 dimensions, ~130MB, runs locally)

**How similarity works:**
- All FAQ embeddings are L2-normalized at index time
- Query embedding is also normalized at query time
- Dot product of two normalized vectors = cosine similarity
- Score range: 0.0 (unrelated) → 1.0 (identical)

**Retrieval config (via `.env`):**

| Variable | Default | Meaning |
|----------|---------|---------|
| `MIN_CONFIDENCE` | `0.45` | Minimum score to attempt an answer |
| `TOP_K` | `4` | Number of FAQ contexts passed to Ollama |

**In-memory cache:** FAQ vectors are loaded from MongoDB once and cached. Cache is invalidated whenever a new FAQ is added or reindexed.

---

## LLM — Ollama

The LLM only sees the retrieved FAQ context — it has no access to the internet or its own training knowledge for answering. The prompt explicitly instructs it:

```
You are a FAQ support chatbot.
Answer using only the retrieved context.
If the context does not contain the answer, say:
"I do not have enough information in the FAQ knowledge base to answer that."
```

**Config:**

| Variable | Default |
|----------|---------|
| `OLLAMA_MODEL` | `gemma3:4b` |
| `OLLAMA_BASE_URL` | `http://127.0.0.1:11434` |
| Temperature | `0.1` (deterministic) |
| Context window | `4096` tokens |

---

## Environment Variables

### `server/.env`

```env
PORT=5001
MONGODB_URI=mongodb://127.0.0.1:27017/faq_vled_rag
CLIENT_ORIGIN=http://localhost:5173
MIN_CONFIDENCE=0.45
TOP_K=4
OLLAMA_BASE_URL=http://127.0.0.1:11434
OLLAMA_MODEL=gemma3:4b
FLAG_EMBEDDING_MODEL=BAAI/bge-small-en-v1.5
PYTHON_BIN=python
```

### `client/.env`

```env
VITE_API_URL=http://localhost:5001
```

---

## API

### `POST /api/chat`

**Request:**
```json
{ "message": "Is there a stipend?" }
```

**Response:**
```json
{
"answer": "Yes, interns receive a monthly honorarium...",
"answerFound": true,
"confidence": 0.81,
"sources": [
{
"id": "...",
"question": "What is the stipend amount?",
"category": "4. Selection, offer letter, and certificate",
"score": 0.8123
}
]
}
```

**Low confidence response:**
```json
{
"answer": "I don't have enough information in the FAQ knowledge base to answer that.",
"answerFound": false,
"confidence": 0.31,
"sources": [...]
}
```

### `GET /api/faqs`
Returns all active FAQs.

### `POST /api/faqs`
Adds a new FAQ and auto-embeds it.

---

## Current Limitations

| Limitation | Detail |
|------------|--------|
| Local only | MongoDB, Ollama, and the embedding model all run on the developer's machine. Not accessible to external users. |
| No escalation | Low-confidence queries return a fallback message. No handoff to a human agent is implemented. |
| Static knowledge base | FAQs are not auto-updated. If Samagama content changes, `npm run import:samagama` must be re-run manually. |
| Memory constraint | `gemma3:4b` requires ~4GB RAM. Larger models need more memory. |
| No auth | The API has no authentication. Anyone with network access to port 5001 can query it. |

---

## Path to Production

To make this accessible to real users, the following changes are needed:

1. **Host the server** on a cloud VM (AWS, GCP, DigitalOcean) or containerize with Docker
2. **Use MongoDB Atlas** (free tier) instead of local MongoDB — accessible from anywhere
3. **Replace Ollama** with an API-based LLM (OpenAI, Groq, Gemini) to avoid hosting a local model
4. **Deploy the frontend** to Vercel or Netlify — free, instant
5. **Add authentication** if the chatbot should be restricted to registered interns
6. **Automate FAQ sync** — schedule `import:samagama` to run periodically so the knowledge base stays current
Loading