Rabbitt-AI commited on
Commit
53d333e
·
verified ·
1 Parent(s): cbcc6fd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +172 -13
README.md CHANGED
@@ -1,13 +1,172 @@
1
- ---
2
- title: RabbittLlama
3
- emoji: 💬
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 4.36.1
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Chance RAG: Advanced Retrieval-Augmented Generation System
2
+
3
+ ## Table of Contents
4
+ 1. [System Architecture](#1-system-architecture)
5
+ 2. [Data Flow](#2-data-flow)
6
+ 3. [Detailed Component Descriptions](#3-detailed-component-descriptions)
7
+ - [3.1 Document Processor](#31-document-processor)
8
+ - [3.2 MistralRAGChatbot](#32-mistralragchatbot)
9
+ - [3.3 Retrieval Engine](#33-retrieval-engine)
10
+ - [3.4 Reranking Engine](#34-reranking-engine)
11
+ - [3.5 Response Generator](#35-response-generator)
12
+ 4. [User Interface](#4-user-interface)
13
+ 5. [Performance Optimization](#5-performance-optimization)
14
+ 6. [Error Handling and Logging](#6-error-handling-and-logging)
15
+ 7. [Future Enhancements](#7-future-enhancements)
16
+ 8. [Conclusion](#8-conclusion)
17
+
18
+ ## 1. System Architecture
19
+
20
+ [Diagram 1: System Architecture]
21
+ +-------------------+ +-------------------+ +-------------------+
22
+ | PDF Document | | User Interface | | Mistral AI API |
23
+ | | | (Gradio UI) | | |
24
+ +--------+----------+ +--------+----------+ +--------+----------+
25
+ | | |
26
+ v v v
27
+ +-------------------+ +-------------------+ +-------------------+
28
+ | Document Processor| | MistralRAGChatbot | | Response Generator|
29
+ | | | | | |
30
+ +--------+----------+ +--------+----------+ +--------+----------+
31
+ | ^ ^
32
+ v | |
33
+ +-------------------+ +-------------------+ +-------------------+
34
+ | Vector Database | | Retrieval Engine | | Reranking Engine |
35
+ | (Annoy Index) | | | | |
36
+ +-------------------+ +-------------------+ +-------------------+
37
+
38
+ ## 2. Data Flow
39
+
40
+ [Diagram 2: Data Flow]
41
+ +-------------+ +-----------------+ +------------------+
42
+ | PDF Upload | --> | Text Extraction | --> | Chunk Generation |
43
+ +-------------+ +-----------------+ +------------------+
44
+ |
45
+ v
46
+ +-------------+ +-----------------+ +------------------+
47
+ | User Query | --> | Query Embedding | --> | Document Retrieval|
48
+ +-------------+ +-----------------+ +------------------+
49
+ |
50
+ v
51
+ +-------------+ +-----------------+ +------------------+
52
+ | Reranking | --> | Context Creation| --> | Response Generation|
53
+ +-------------+ +-----------------+ +------------------+
54
+ |
55
+ v
56
+ +------------------+
57
+ | Display Response |
58
+ +------------------+
59
+
60
+ ## 3. Detailed Component Descriptions
61
+
62
+ ### 3.1 Document Processor
63
+
64
+ The Document Processor handles PDF files and prepares them for use in the RAG system.
65
+
66
+ Key functions:
67
+ - `store_embeddings_in_vector_db`: Processes PDFs and stores embeddings.
68
+ - `split_text_into_chunks`: Divides text into manageable chunks.
69
+
70
+ ### 3.2 MistralRAGChatbot
71
+
72
+ This core class orchestrates the entire RAG process.
73
+
74
+ Key methods:
75
+ - `generate_response_with_rag`: Coordinates retrieval, reranking, and response generation.
76
+ - `retrieve_documents`: Fetches relevant documents using various methods.
77
+ - `rerank_documents`: Applies reranking algorithms to improve relevance.
78
+
79
+ ### 3.3 Retrieval Engine
80
+
81
+ The Retrieval Engine uses multiple methods to find relevant documents.
82
+
83
+ Methods:
84
+ 1. Annoy (Approximate Nearest Neighbors)
85
+ 2. TF-IDF (Term Frequency-Inverse Document Frequency)
86
+ 3. BM25 (Best Matching 25)
87
+ 4. Word2Vec
88
+ 5. Euclidean Distance
89
+ 6. Jaccard Similarity
90
+
91
+ [Diagram 3: Retrieval Methods Comparison]
92
+ Method | Speed | Accuracy | Memory Usage
93
+ ---------|-------|----------|--------------
94
+ Annoy | Fast | Good | Low
95
+ TF-IDF | Fast | Moderate | Moderate
96
+ BM25 | Fast | Good | Low
97
+ Word2Vec | Slow | Good | High
98
+ Euclidean| Fast | Moderate | Low
99
+ Jaccard | Slow | Moderate | Low
100
+
101
+ ### 3.4 Reranking Engine
102
+
103
+ The Reranking Engine applies advanced algorithms to improve the relevance of retrieved documents.
104
+
105
+ Methods:
106
+ 1. Advanced Fusion
107
+ 2. Reciprocal Rank Fusion
108
+ 3. Weighted Score Fusion
109
+ 4. Semantic Similarity Reranking
110
+
111
+ [Diagram 4: Reranking Process]
112
+ +-------------------+ +-------------------+ +-------------------+
113
+ | Retrieved Docs | --> | Reranking Methods | --> | Reranked Docs |
114
+ +-------------------+ +-------------------+ +-------------------+
115
+ |
116
+ +--------+--------+
117
+ | |
118
+ +-------v------+ +-------v------+
119
+ | Score Fusion | | Semantic Sim |
120
+ +--------------+ +--------------+
121
+
122
+ ### 3.5 Response Generator
123
+
124
+ Utilizes the Mistral AI API to generate human-like responses based on the retrieved and reranked context.
125
+
126
+ Key function:
127
+ - `build_prompt`: Constructs the prompt for the Mistral AI model.
128
+
129
+ ## 4. User Interface
130
+
131
+ The Gradio-based user interface provides an intuitive way to interact with the Chance RAG system.
132
+
133
+ Components:
134
+ 1. PDF Upload
135
+ 2. User Query Input
136
+ 3. Response Style Selection
137
+ 4. Retrieval Methods Selection
138
+ 5. Reranking Methods Selection
139
+ 6. Chunk Size and Overlap Adjustment
140
+ 7. Response Display
141
+
142
+ ## 5. Performance Optimization
143
+
144
+ To improve the system's performance, consider the following:
145
+
146
+ 1. Implement caching for embeddings and frequently retrieved documents.
147
+ 2. Use parallel processing for document retrieval and reranking.
148
+ 3. Optimize chunk size and overlap based on document characteristics.
149
+ 4. Implement adaptive retrieval method selection based on query type.
150
+
151
+ ## 6. Error Handling and Logging
152
+
153
+ The system includes error handling and logging mechanisms to ensure robustness and facilitate debugging.
154
+
155
+ Key aspects:
156
+ - Exception handling in critical functions
157
+ - Logging of important events and errors
158
+ - User-friendly error messages in the interface
159
+
160
+ ## 7. Future Enhancements
161
+
162
+ 1. Multi-document support: Allow processing of multiple PDFs simultaneously.
163
+ 2. Dynamic model selection: Choose the most appropriate Mistral AI model based on the query complexity.
164
+ 3. User feedback integration: Incorporate user feedback to improve retrieval and reranking over time.
165
+ 4. Multilingual support: Extend the system to handle multiple languages.
166
+ 5. Advanced analytics: Implement usage analytics and performance metrics tracking.
167
+
168
+ ## 8. Conclusion
169
+
170
+ The Chance RAG system provides a powerful and flexible solution for context-aware question answering based on PDF documents. By leveraging multiple retrieval and reranking methods, along with the advanced language capabilities of the Mistral AI API, it offers highly relevant and coherent responses to user queries.
171
+
172
+ This documentation provides a comprehensive overview of the system architecture, components, and processes. For specific implementation details, refer to the inline comments and docstrings in the code.