vara201 commited on
Commit
d3aba6f
·
1 Parent(s): e8e1f78

Updated read me

Browse files
Files changed (1) hide show
  1. README.md +42 -28
README.md CHANGED
@@ -1,49 +1,63 @@
1
- ---
2
- title: CogniRAG - Agentic RAG Platform
3
- emoji: 🚀
4
- colorFrom: indigo
5
- colorTo: purple
6
- sdk: docker
7
- app_port: 7860
8
- pinned: false
9
- license: mit
10
- ---
11
-
12
  # CogniRAG — Enterprise Agentic RAG Backend
13
 
 
 
 
 
 
 
 
14
  An advanced, production-grade **Agentic Retrieval-Augmented Generation (RAG)** platform powered by **FastAPI**, **Local Qdrant Vector Store**, **Groq LLM (Llama-3.1)**, **Sentence-Transformers Embeddings**, and **Cross-Encoder Reranking**.
15
 
16
  Features dynamic **Query Transformation**, **Sufficiency Evaluation Grading**, an autonomous retrieval-refinement loop capped at **maximum 3 iterations**, comprehensive step-by-step telemetry, and document citations.
17
 
 
 
18
  ---
19
 
20
  ## Architecture & Agentic Flow
21
 
22
  ```mermaid
23
  flowchart TD
24
- User([User Question]) --> CacheCheck{Cache Hit?}
25
- CacheCheck -- Yes --> CachedAnswer([Instant Cached Answer])
26
- CacheCheck -- No --> LoopInit[Start Agentic Loop: Iteration 1 of 3]
27
-
28
- subgraph AgenticLoop [Agentic Retrieval & Transformation Loop (Max 3)]
29
- LoopInit --> Embed[1. Dense Embedding: BAAI/bge-small-en-v1.5]
30
- Embed --> VectorSearch[2. Vector Search: Local Qdrant Store]
31
- VectorSearch --> Rerank[3. Cross-Encoder Reranking: ms-marco-MiniLM]
32
- Rerank --> Accumulate[Merge & Deduplicate Top Passages]
33
- Accumulate --> Evaluator{4. Sufficiency Grader: Is Context Relevant?}
34
-
35
- Evaluator -- "No & Loop < 3" --> Transform[Query Transformation: Groq Llama-3.1]
36
- Transform --> |Reformulated Query| NextLoop[Increment Iteration: Loop + 1]
 
37
  NextLoop --> Embed
38
  end
39
 
40
- Evaluator -- "Yes (Sufficient)" --> Synthesis[5. LLM Synthesis & Citation Grounding]
41
  Evaluator -- "Max 3 Loops Reached" --> Synthesis
42
-
43
- Synthesis --> TraceSave[Save Telemetry Run & Steps to Trace DB]
44
- TraceSave --> Response([Response with Verified Citations & Step Telemetry])
45
  ```
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  ---
48
 
49
  ## Key Features
 
 
 
 
 
 
 
 
 
 
 
 
1
  # CogniRAG — Enterprise Agentic RAG Backend
2
 
3
+ [![Python](https://img.shields.io/badge/Python-3.11+-3776AB?style=flat&logo=python&logoColor=white)](https://www.python.org/)
4
+ [![FastAPI](https://img.shields.io/badge/FastAPI-0.111+-009688?style=flat&logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com/)
5
+ [![Groq](https://img.shields.io/badge/Groq-Llama--3.1-F55036?style=flat)](https://groq.com/)
6
+ [![Qdrant](https://img.shields.io/badge/Qdrant-Vector_DB-DC143C?style=flat)](https://qdrant.tech/)
7
+ [![HF Spaces](https://img.shields.io/badge/Hugging%20Face-Spaces-FFD21E?style=flat&logo=huggingface&logoColor=black)](https://huggingface.co/spaces)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](../LICENSE)
9
+
10
  An advanced, production-grade **Agentic Retrieval-Augmented Generation (RAG)** platform powered by **FastAPI**, **Local Qdrant Vector Store**, **Groq LLM (Llama-3.1)**, **Sentence-Transformers Embeddings**, and **Cross-Encoder Reranking**.
11
 
12
  Features dynamic **Query Transformation**, **Sufficiency Evaluation Grading**, an autonomous retrieval-refinement loop capped at **maximum 3 iterations**, comprehensive step-by-step telemetry, and document citations.
13
 
14
+ > **Hugging Face Spaces**: This backend is Docker SDK compatible. Set `GROQ_API_KEY` and `SECRET_KEY` in Space Secrets, and the app will be served on port `7860`.
15
+
16
  ---
17
 
18
  ## Architecture & Agentic Flow
19
 
20
  ```mermaid
21
  flowchart TD
22
+ User(["User Question"]) --> CacheCheck{"Cache Hit?"}
23
+ CacheCheck -- Yes --> CachedAnswer(["Instant Cached Answer"])
24
+ CacheCheck -- No --> LoopInit["Start Agentic Loop\nIteration = 1"]
25
+
26
+ subgraph AgenticLoop ["Agentic Retrieval and Refinement Loop - Max 3 Iterations"]
27
+ direction TB
28
+ LoopInit --> Embed["Step 1 - Dense Embedding\nBAAI/bge-small-en-v1.5\n384-dim L2 normalized"]
29
+ Embed --> VectorSearch["Step 2 - Vector Search\nLocal Qdrant - Top-K Candidates"]
30
+ VectorSearch --> Rerank["Step 3 - Cross-Encoder Reranking\nms-marco-MiniLM-L-6-v2\nPrecision Scoring"]
31
+ Rerank --> Accumulate["Merge and Deduplicate\nAccumulate unique passages\nacross all iterations"]
32
+ Accumulate --> Evaluator{"Step 4 - Sufficiency Grader\nIs context relevant?"}
33
+
34
+ Evaluator -- "Insufficient and Iter less than 3" --> Transform["Query Transformation\nGroq Llama-3.1 rewrites query\nfor better semantic coverage"]
35
+ Transform --> NextLoop["Increment Iteration"]
36
  NextLoop --> Embed
37
  end
38
 
39
+ Evaluator -- "Sufficient" --> Synthesis
40
  Evaluator -- "Max 3 Loops Reached" --> Synthesis
41
+
42
+ Synthesis["Step 5 - LLM Synthesis\nGroq Llama-3.1 generates answer\ngrounded in retrieved passages"] --> TraceSave["Save Telemetry\nTrace run, step durations,\nscores and metadata to SQLite"]
43
+ TraceSave --> Response(["Final Response\nAnswer - Citations - Trace ID - Step Telemetry"])
44
  ```
45
 
46
+ ### Step-by-Step Breakdown
47
+
48
+ | Step | Component | What Happens |
49
+ |------|-----------|--------------|
50
+ | **1. Query Reception** | FastAPI endpoint | User question arrives; cache is checked first |
51
+ | **2. Dense Embedding** | `BAAI/bge-small-en-v1.5` | Query embedded into 384-dim L2-normalized vector |
52
+ | **3. Vector Search** | Local Qdrant | Top-K semantically similar chunks retrieved |
53
+ | **4. Cross-Encoder Rerank** | `ms-marco-MiniLM-L-6-v2` | Chunks scored for passage-level relevance |
54
+ | **5. Context Merging** | Deduplication logic | Unique passages across all loops merged and re-ranked |
55
+ | **6. Sufficiency Grading** | Dual-mode grader | Score >= 1.5 = sufficient; Score <= -2.5 = transform; borderline = LLM JSON verdict |
56
+ | **7. Query Transformation** | `Groq Llama-3.1-8b` | Query rewritten with expanded semantics if context insufficient |
57
+ | **8. LLM Synthesis** | `Groq Llama-3.1-8b` | Top passages + question generates grounded answer with citations |
58
+ | **9. Telemetry Save** | SQLite / Trace DB | Full step trace (durations, scores, iterations, token stats) persisted |
59
+ | **10. Response** | JSON payload | Returns `answer`, `citations`, `trace_id`, and `steps` |
60
+
61
  ---
62
 
63
  ## Key Features