talexm commited on
Commit
eb579c5
1 Parent(s): e4a2031
Files changed (1) hide show
  1. rag_sec/README.md +42 -36
rag_sec/README.md CHANGED
@@ -1,51 +1,57 @@
1
- # Document Search and Response Generation System
2
 
3
- This project implements a **Document Search and Response Generation System** combining semantic search, malicious query detection, and generative response capabilities. It is designed for efficient and context-aware information retrieval and response generation.
4
 
5
- ---
6
-
7
- ## Features
8
-
9
- 1. **Semantic Search**:
10
- - Uses SentenceTransformer embeddings for document similarity.
11
- - Retrieves top-k relevant documents for a given query.
12
-
13
- 2. **Malicious Query Detection**:
14
- - Identifies and blocks malicious or harmful queries using sentiment analysis.
15
 
16
- 3. **Query Transformation**:
17
- - Rephrases or enhances ambiguous queries for better processing.
18
-
19
- 4. **Generative Response**:
20
- - Generates a context-aware response using Hugging Face models like `distilgpt2`.
21
 
22
- 5. **Expandable Architecture**:
23
- - Modular components for easy enhancement and integration.
24
- - Compatible with lightweight and resource-efficient models.
 
 
 
25
 
26
  ---
27
 
28
- ## Architecture
 
 
 
 
 
 
 
29
 
30
- 1. **Bad Query Detector**:
31
- - Detects malicious or inappropriate queries using sentiment analysis (`distilbert-base-uncased-finetuned-sst-2-english`).
32
 
33
- 2. **Query Transformer**:
34
- - Rephrases or improves queries for better retrieval results.
 
 
 
 
 
 
 
 
35
 
36
- 3. **Document Retriever**:
37
- - Encodes documents into dense vectors using `all-MiniLM-L6-v2` embeddings.
38
- - Finds similar documents using cosine similarity.
39
 
40
- 4. **Semantic Response Generator**:
41
- - Generates context-aware responses using models like `distilgpt2` or `EleutherAI/gpt-neo-1.3B`.
 
 
 
 
42
 
43
  ---
44
 
45
- ## Requirements
46
 
47
- ### Python Libraries
48
- Install the necessary libraries using `pip`:
49
- ```bash
50
- pip install transformers sentence-transformers scikit-learn numpy flask
51
- ```
 
1
+ ## Workflow
2
 
3
+ The system follows a well-structured workflow to ensure accurate, secure, and context-aware responses to user queries:
4
 
5
+ ### 1. **Input Query**
6
+ - A user provides a query that can be a general question, ambiguous statement, or potentially malicious intent.
 
 
 
 
 
 
 
 
7
 
8
+ ---
 
 
 
 
9
 
10
+ ### 2. **Detection Module**
11
+ - **Purpose**: Classify the query as "bad" or "good."
12
+ - **Steps**:
13
+ 1. Use a sentiment analysis model (`distilbert-base-uncased-finetuned-sst-2-english`) to detect malicious or inappropriate intent.
14
+ 2. If the query is classified as "bad" (e.g., SQL injection or inappropriate tone), block further processing and provide a warning message.
15
+ 3. If "good," proceed to the **Transformation Module**.
16
 
17
  ---
18
 
19
+ ### 3. **Transformation Module**
20
+ - **Purpose**: Rephrase or enhance ambiguous or poorly structured queries for better retrieval.
21
+ - **Steps**:
22
+ 1. Identify missing context or ambiguous phrasing.
23
+ 2. Transform the query using:
24
+ - Rule-based transformations for simple fixes.
25
+ - Text-to-text models (e.g., `google/flan-t5-small`) for more sophisticated rephrasing.
26
+ 3. Pass the transformed query to the **RAG Pipeline**.
27
 
28
+ ---
 
29
 
30
+ ### 4. **RAG Pipeline**
31
+ - **Purpose**: Retrieve relevant data and generate a context-aware response.
32
+ - **Steps**:
33
+ 1. **Document Retrieval**:
34
+ - Encode the transformed query and documents into embeddings using `all-MiniLM-L6-v2`.
35
+ - Compute semantic similarity between the query and stored documents.
36
+ - Retrieve the top-k documents relevant to the query.
37
+ 2. **Response Generation**:
38
+ - Use the retrieved documents as context.
39
+ - Pass the query and context to a generative model (e.g., `distilgpt2`) to synthesize a meaningful response.
40
 
41
+ ---
 
 
42
 
43
+ ### 5. **Semantic Response Generation**
44
+ - **Purpose**: Provide a concise and meaningful answer.
45
+ - **Steps**:
46
+ 1. Combine the retrieved documents into a coherent context.
47
+ 2. Generate a response tailored to the query using the generative model.
48
+ 3. Return the response to the user, ensuring clarity and relevance.
49
 
50
  ---
51
 
52
+ ### End-to-End Example
53
 
54
+ #### Input Query:
55
+ ```plaintext
56
+ "How to improve acting skills?"
57
+ ````