Skip to content

Commit 98f9dce

Browse files
committed
Create SystemArchitecture.md
1 parent 1d0cb3e commit 98f9dce

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

backend/SystemArchitecture.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
# System Architecture
3+
4+
## Overview
5+
6+
This document describes the system architecture of the backend course recommendation system, focusing on the Retrieval-Augmented Generation (RAG) pipeline. The system's primary goal is to understand user queries and provide relevant course recommendations.
7+
8+
## Components
9+
10+
The system is composed of the following key components:
11+
12+
1. **Flask Application (`app.py`)**:
13+
* Serves as the entry point of the backend.
14+
* Handles API requests, specifically the `/chat` endpoint.
15+
* Initializes and orchestrates the RAG pipeline.
16+
* Manages data loading and response formatting.
17+
18+
2. **Query Generator (`src/service/query_generator.py`)**:
19+
* Converts the conversation history into a structured query suitable for course retrieval.
20+
* Utilizes the Groq API with function calling to extract query parameters (teacher, keywords, department, program, grade).
21+
* Reads a system prompt to guide the language model.
22+
23+
3. **Course Reranker (`src/service/relative_search.py` or `src/service/relative_search_bi_encoder.py`)**:
24+
* Scores courses based on the generated query.
25+
* There are two options based on the `USE_CROSS_ENCODER` flag:
26+
* **`CourseReranker`**: Uses a cross-encoder model (`BAAI/bge-reranker-base`) to compute relevance scores.
27+
* **`CourseRerankerWithFieldMapping`**: Uses a bi-encoder model (`paraphrase-multilingual-MiniLM-L12-v2`) and precomputed embeddings to calculate the relevance score and supports field-specific filtering and weighting.
28+
29+
4. **Final Response Generator (`src/service/final_response_generator.py`)**:
30+
* Formats the retrieved courses and query into a detailed prompt.
31+
* Connects to the Groq API and generates a natural language response based on the structured data and prompt.
32+
33+
## RAG Pipeline Workflow
34+
35+
1. **User Input**: The user sends a query through the chat interface.
36+
2. **Query Generation**: The `query_generator.py` uses the Groq API to convert the conversation history into a structured query.
37+
3. **Course Retrieval**: The `relative_search.py` or `relative_search_bi_encoder.py` component scores and ranks courses based on the generated query, and the appropriate reranker is chosen based on `USE_CROSS_ENCODER` flag.
38+
4. **Final Response Generation**: The `final_response_generator.py` component formats a detailed prompt and uses the Groq API to create a final, human-readable response.
39+
5. **Output**: The final response is sent back to the user.
40+
41+
## Data Flow
42+
43+
- The `app.py` loads course data from `src/data/courses.csv`.
44+
- The `relative_search_bi_encoder.py` loads precomputed embeddings from `src/data/precomputed_field_embeddings.pt`.
45+
- The `query_generator.py` reads a system prompt from `prompt.txt`.
46+
- The `final_response_generator.py` uses a system prompt in its internal logic.
47+
48+
## Key Technologies
49+
50+
- **Flask**: Web framework for the backend.
51+
- **Groq API**: For language model based query generation and response generation.
52+
- **Sentence Transformers**: For sentence embedding and cross-encoder models.
53+
- **Pandas**: For data manipulation.
54+
55+
This system architecture provides a clear structure for understanding how the course recommendation system functions and how the RAG pipeline facilitates efficient and relevant responses to user queries.

0 commit comments

Comments
 (0)