Martechsol commited on
Commit
cb79a0a
·
1 Parent(s): 3944045

Update from backup state - 2026-05-06

Browse files
ANTIGRAVITY_INSTRUCTIONS.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Antigravity Setup & Instructions
2
+
3
+ This backup was created on **2026-05-05**.
4
+ It contains the full state of the Martechsol RAG Chatbot project.
5
+
6
+ ## Current Setup Info
7
+ - **Main Workspace Path:** `D:\RAG_Backup_2026_05_05`
8
+ - **Primary LLM:** Qwen 3 32B (via Groq)
9
+ - **Deployment Target:** Hugging Face Spaces (`space` remote)
10
+ - **Git Remote:** `https://huggingface.co/spaces/joedown11/chatRAG`
11
+
12
+ ## Instructions for Antigravity (Coding Assistant)
13
+
14
+ If the user says **"push"**, you should perform the following actions to update the project and its deployment:
15
+
16
+ 1. **Sync Local Changes**: Ensure all local files are saved.
17
+ 2. **Commit Changes**:
18
+ - Run `git add .`
19
+ - Run `git commit -m "Update from backup state - [Current Date]"` (or a specific message if provided).
20
+ 3. **Deploy to Space**:
21
+ - Run `git push space main` (or `master` if appropriate).
22
+ 4. **Verify Configuration**:
23
+ - Ensure `.env` or `app/core/config.py` has the correct API keys if they were changed.
24
+ - If the user changed the API provider (e.g., from Groq to something else), verify that `app/core/config.py` reflects the new provider and model.
25
+
26
+ ## Note for next session:
27
+ The user intends to change the API provider and other settings *after* this backup.
28
+ If you are opening this folder, check `app/core/config.py` first to see the current provider.
29
+ If the user says "push", they want the *latest* version of the code and setup to be updated everywhere as it is right now.
CONFIG_NOTES.md CHANGED
@@ -1,29 +1,32 @@
1
  # Configuration Backup - Martechsol RAG Chatbot
2
- **Date:** 2026-04-28
3
  **Source:** C:\Users\DELL\Desktop\RAG_backup2
4
- **Destination:** D:\RAG_Backup_2026_04_28
5
 
6
- ## Core Settings (from app/core/config.py)
7
  - **App Name:** Fast RAG Chatbot
8
- - **LLM Provider:** groq (default)
9
- - **Groq Model:** llama-3.1-8b-instant
 
10
  - **HF Model:** meta-llama/Llama-3.1-8B-Instruct
11
  - **Embedding Model:** BAAI/bge-small-en-v1.5
 
12
  - **Docs Directory:** docs/
13
  - **Index Directory:** data/index/
14
  - **Sessions Directory:** data/sessions/
15
- - **Chunk Size:** 420 tokens
16
  - **Overlap:** 80 tokens
17
- - **Top K:** 4
 
18
 
19
  ## Admin Credentials
20
  - **Username:** martech_admin
21
  - **Password:** martech_admin_303
22
  - **OTP Expiry:** 300 seconds (5 minutes)
23
 
24
- ## Security
25
  - **Auth Method:** HTTP Basic Auth + OTP (email-based)
26
- - **Email for OTP:** randomjoedown@gmail.com
27
  - **SMTP Server:** smtp.gmail.com (Port 465)
28
 
29
  ## API / Integration
@@ -32,7 +35,7 @@
32
  - **Admin Endpoint:** /admin
33
  - **CORS:** Allowed for all (*) for testing
34
 
35
- ## Infrastructure
36
- - **Hugging Face Path:** /data (for persistent storage)
37
- - **Local Path:** data/ (for local storage)
38
- - **Dockerfile:** Based on python:3.10-slim, serves on port 7860
 
1
  # Configuration Backup - Martechsol RAG Chatbot
2
+ **Date:** 2026-05-05
3
  **Source:** C:\Users\DELL\Desktop\RAG_backup2
4
+ **Destination:** D:\RAG_Backup_2026_05_05
5
 
6
+ ## Core Settings (latest state)
7
  - **App Name:** Fast RAG Chatbot
8
+ - **LLM Provider:** groq
9
+ - **Main LLM Model:** qwen/qwen3-32b (Groq)
10
+ - **Query Rewriter:** llama-3.1-8b-instant (Groq)
11
  - **HF Model:** meta-llama/Llama-3.1-8B-Instruct
12
  - **Embedding Model:** BAAI/bge-small-en-v1.5
13
+ - **Reranker Model:** cross-encoder/ms-marco-MiniLM-L-6-v2
14
  - **Docs Directory:** docs/
15
  - **Index Directory:** data/index/
16
  - **Sessions Directory:** data/sessions/
17
+ - **Chunk Size:** 350 tokens (Optimized for context window)
18
  - **Overlap:** 80 tokens
19
+ - **Top K:** 8
20
+ - **Max Context Chunks:** 4
21
 
22
  ## Admin Credentials
23
  - **Username:** martech_admin
24
  - **Password:** martech_admin_303
25
  - **OTP Expiry:** 300 seconds (5 minutes)
26
 
27
+ ## Security & Notifications
28
  - **Auth Method:** HTTP Basic Auth + OTP (email-based)
29
+ - **Admin Email:** randomjoedown@gmail.com
30
  - **SMTP Server:** smtp.gmail.com (Port 465)
31
 
32
  ## API / Integration
 
35
  - **Admin Endpoint:** /admin
36
  - **CORS:** Allowed for all (*) for testing
37
 
38
+ ## Optimization Notes
39
+ - **Latency Optimization**: Skip thinking process for Qwen3 using deterministic intent detection.
40
+ - **Conciseness Protocol**: Strict 25-30 word response limit enforced via System Prompt.
41
+ - **Hybrid Search**: FAISS + BM25 with Reranker for high precision.
PROJECT_TECHNICAL_SPEC.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Martechsol HR Assistant: Project Technical Specification & Workflow
2
+
3
+ This document provides a comprehensive overview of the **Martechsol HR Assistant**, covering its architecture, the models used, API integrations, and the end-to-end data workflow.
4
+
5
+ ---
6
+
7
+ ## 1. Project Architecture Overview
8
+
9
+ The system is a high-performance **Retrieval-Augmented Generation (RAG)** application designed to provide precise, grounded answers based on employee handbooks and HR documents.
10
+
11
+ ### High-Level Stack:
12
+ - **Language**: Python 3.10+
13
+ - **API Framework**: FastAPI
14
+ - **Server**: Uvicorn
15
+ - **UI**: Gradio (for direct testing/Hugging Face Spaces)
16
+ - **Web Integration**: Custom HTML/CSS/JS "Floating Icon" for WordPress/External sites.
17
+ - **Persistence**: FAISS (Vector DB) & Local Session Storage.
18
+
19
+ ---
20
+
21
+ ## 2. Models & API Infrastructure
22
+
23
+ The project utilizes 4 distinct models to ensure a balance between speed, reasoning capability, and accuracy.
24
+
25
+ | Model Component | Model Name / ID | Provider / Engine | Purpose |
26
+ | :--- | :--- | :--- | :--- |
27
+ | **Main LLM (Brain)** | `qwen/qwen3-32b` | **Groq** | Reasoning, formatting, and generating the final response. |
28
+ | **Query Rewriter** | `llama-3.1-8b-instant` | **Groq** | Expanding user queries into multiple search terms (used as fallback). |
29
+ | **Embedding Model** | `BAAI/bge-small-en-v1.5` | Sentence Transformers | Converting text chunks into mathematical vectors for search. |
30
+ | **Reranker** | `ms-marco-MiniLM-L-6-v2` | Cross-Encoder | Deeply evaluating the relevance of retrieved document chunks. |
31
+
32
+ ### APIs Connected:
33
+ 1. **Groq API**: Powers the LLM inference (Qwen3 and Llama 3.1). Groq is chosen for its extreme speed (LPUs).
34
+ 2. **SMTP (Gmail/Custom)**: Used for sending OTPs or notifications (if configured).
35
+ 3. **Hugging Face**: Used for hosting the Gradio interface and downloading model weights for Embeddings/Reranking.
36
+
37
+ ---
38
+
39
+ ## 3. The RAG Pipeline Workflow
40
+
41
+ When a user sends a message, the system follows this exact sequence:
42
+
43
+ ### Phase 1: Query Processing
44
+ 1. **Normalization**: The message is cleaned and converted to a cache key (MD5 hash).
45
+ 2. **Cache Lookup**: If the exact question was asked recently, the answer is returned instantly from an in-memory LRU cache.
46
+ 3. **Local Expansion**: The query is expanded into up to 3 targeted search queries using a deterministic keyword map (e.g., "timing" → "office hours", "workday schedule"). This saves 3-5 seconds of LLM latency.
47
+
48
+ ### Phase 2: Retrieval (Search)
49
+ 1. **Vector Search**: The system uses **FAISS** to find the most mathematically similar text chunks in the `docs/` folder.
50
+ 2. **Keyword Search (BM25)**: Complements vector search by finding exact word matches.
51
+ 3. **Hybrid Filtering**: Chunks are initially filtered by a relevance threshold (RRF).
52
+
53
+ ### Phase 3: Intelligence & Reranking
54
+ 1. **Cross-Encoding**: The top retrieved chunks are sent to the **Reranker model**. Unlike standard search, the reranker looks at the *actual meaning* of the chunk relative to the question.
55
+ 2. **Context Construction**: The most relevant chunks (capped at 1500 words to avoid token limits) are assembled into a context block.
56
+
57
+ ### Phase 4: Generation (The Final Answer)
58
+ 1. **Prompt Injection**: The question, context, and a pruned chat history (last 2 turns) are wrapped in a strict **Master System Prompt**.
59
+ 2. **LLM Execution**: The request is sent to `qwen/qwen3-32b`.
60
+ - *Optimization*: The instruction `/no_think` is added to skip internal chain-of-thought, reducing response time by 40-60%.
61
+ 3. **Post-Processing**:
62
+ - Strips `<think>` tags.
63
+ - Removes conversational filler (e.g., "Based on the documents provided...").
64
+ - Enforces HTML formatting (bolding key terms, `<br>` for lists).
65
+
66
+ ---
67
+
68
+ ## 4. Backend Components & Directory Structure
69
+
70
+ ### Core Files:
71
+ - `app/main.py`: Entry point for the FastAPI application.
72
+ - `app/core/config.py`: Centralized configuration (API keys, model names, chunk sizes).
73
+ - `app/services/rag_pipeline.py`: Orchestrates the flow from query to final answer.
74
+ - `app/services/llm.py`: Handles communication with Groq and prompt engineering.
75
+ - `app/services/vector_store.py`: Manages FAISS indexing and retrieval.
76
+ - `app/services/session_store.py`: Manages user history and OTP sessions.
77
+
78
+ ### Data Flow:
79
+ 1. **Input**: User Query (HTTP POST to `/chat` or Gradio WebSocket).
80
+ 2. **Processing**: FastAPI → RAG Pipeline Service → LLM Service.
81
+ 3. **Output**: JSON Response with `reply` and `retrieved_chunks` (metadata).
82
+
83
+ ---
84
+
85
+ ## 5. Summary of Key Features
86
+ - **Deterministic Intent Detection**: Instantly recognizes topics like "leaves" or "salary" to pull the right data without LLM delay.
87
+ - **Thinking Model Suppression**: Uses the power of Qwen3/DeepSeek while disabling their slow "thinking" phase for the final user response.
88
+ - **Hybrid Search**: Combines the precision of keywords with the "vibe" search of vectors.
89
+ - **Strict Formatting**: Enforces list styles and word counts to ensure a professional HR tone.
robocopy_backup.log DELETED
@@ -1,81 +0,0 @@
1
-
2
- -------------------------------------------------------------------------------
3
- ROBOCOPY :: Robust File Copy for Windows
4
- -------------------------------------------------------------------------------
5
-
6
- Started : Wednesday, April 29, 2026 9:00:28 PM
7
- Source : c:\Users\DELL\Desktop\RAG_backup2\
8
- Dest : C:\Users\DELL\Desktop\RAG_backup_final\
9
-
10
- Files : *.*
11
-
12
- Exc Files : .DS_Store
13
-
14
- Exc Dirs : .git
15
- .gemini
16
- __pycache__
17
- venv
18
-
19
- Options : *.* /TEE /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:2 /W:5
20
-
21
- ------------------------------------------------------------------------------
22
-
23
- 13 c:\Users\DELL\Desktop\RAG_backup2\
24
- *EXTRA File 60 exclude_list.txt
25
- Newer 378 .env.example
26
- New File 46 .gitattributes
27
- Newer 194 app.py
28
- New File 1198 CONFIG_NOTES.md
29
- Newer 295 docker-compose.yml
30
- Newer 782 Dockerfile
31
- New File 6675 martech_sol_logo.jpg
32
  99%
33
- Newer 161 requirements.txt
34
- New File 0 robocopy_backup.log
35
- 3 c:\Users\DELL\Desktop\RAG_backup2\app\
36
- Newer 8109 main.py
37
- Newer 10861 ui_gradio.py
38
- 2 c:\Users\DELL\Desktop\RAG_backup2\app\admin\
39
- Newer 14492 router.py
40
- 1 c:\Users\DELL\Desktop\RAG_backup2\app\admin\templates\
41
- Newer 35075 admin.html
42
- 2 c:\Users\DELL\Desktop\RAG_backup2\app\api\
43
- Newer 693 schemas.py
44
- 2 c:\Users\DELL\Desktop\RAG_backup2\app\core\
45
- Newer 2594 config.py
46
- 10 c:\Users\DELL\Desktop\RAG_backup2\app\services\
47
- Newer 3568 chunker.py
48
- Newer 8361 llm.py
49
- Newer 4989 rag_pipeline.py
50
- New File 1661 reranker.py
51
- Newer 10783 session_store.py
52
- Newer 4823 vector_store.py
53
- 0 c:\Users\DELL\Desktop\RAG_backup2\data\
54
- 1 c:\Users\DELL\Desktop\RAG_backup2\data\index\
55
- 1 c:\Users\DELL\Desktop\RAG_backup2\data\sessions\
56
- 2 c:\Users\DELL\Desktop\RAG_backup2\docs\
57
- 1 c:\Users\DELL\Desktop\RAG_backup2\floaitng-icon\
58
- *EXTRA File 24856 Artificial Intelligence Chatbot.lottie
59
- New File 462684 KhloeSAC.lottie
60
  99%
61
- New Dir 3 c:\Users\DELL\Desktop\RAG_backup2\PHPMailer\
62
- New File 1256 Exception.php
63
  93%
64
- New File 183229 PHPMailer.php
65
  99%
66
- New File 49148 SMTP.php
67
  99%
68
- 3 c:\Users\DELL\Desktop\RAG_backup2\static\
69
- Newer 19723 addon.html
70
- New File 462684 bot-icon.lottie
71
  99%
72
- Newer 2010 chat-loader.js
73
- 3 c:\Users\DELL\Desktop\RAG_backup2\wordpress code\
74
-
75
- ------------------------------------------------------------------------------
76
-
77
- Total Copied Skipped Mismatch FAILED Extras
78
- Dirs : 21 1 20 0 0 0
79
- Files : 47 28 19 0 0 2
80
- Bytes : 5.00 m 1.23 m 3.76 m 0 0 24.3 k
81
- Times : 0:00:00 0:00:00 0:00:00 0:00:00
82
-
83
-
84
- Speed : 20,257,375 Bytes/sec.
85
- Speed : 1,159.136 MegaBytes/min.
86
- Ended : Wednesday, April 29, 2026 9:00:29 PM
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
  99%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  99%
 
 
2
  93%
 
3
  99%
 
4
  99%
 
 
 
5
  99%