File size: 14,537 Bytes
365de9c 796983b 365de9c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
---
title: The Ultimate RAG
emoji: 🌍
colorFrom: pink
colorTo: indigo
sdk: docker
pinned: false
short_description: the ultimate rag
---
# The-Ultimate-RAG
## Overview

[S25] The Ultimate RAG is an Innopolis University software project that generates cited responses from a local database.
## Prerequisites
Before you begin, ensure the following is installed on your machine:
- [Python](https://www.python.org/)
- [Docker](https://www.docker.com/get-started/)
## Installation
1. **Clone the repository**
```bash
git clone https://github.com/PopovDanil/The-Ultimate-RAG
cd The-Ultimate-RAG
```
2. **Set up a virtual environment (recommended)**
To isolate project dependencies and avoid conflicts, create a virtual environment:
- **On Unix/Linux/macOS:**
```bash
python3 -m venv env
source env/bin/activate
```
- **On Windows:**
```bash
python -m venv env
env\Scripts\activate
```
3. **Install required libraries**
Within the activated virtual environment, install the dependencies:
```bash
pip install -r ./app/requirements.txt
```
*Note:* ensure you are in the virtual environment before running the command
4. **Set up Docker**
- Ensure Docker is running on your machine
- Open a terminal, navigate to project directory, and run:
```bash
docker-compose up --build
```
*Note:* The initial build may take 10–20 minutes, as it needs to download large language models and other
dependencies.
Later launches will be much faster.
5. **Server access**
Once the containers are running, visit `http://localhost:5050`. You should see the application’s welcome page
To stop the application and shut down all containers, press `Ctrl+C` in the terminal where `docker-compose` is running,
and then run:
```bash
docker-compose down
```
## Usage
You can try currently deployed version of the system [here](https://huggingface.co/spaces/The-Ultimate-RAG-HF/The-Ultimate-RAG). **Note**: you should use the following instructions:
- Access the cite, you should see the *main* page with the name of the system
- Press the button "+ Add new chat", wait until the *login* page is loaded
- Find button "Register" (for now it is highly recommended to follow the instructions *strictly*) and press it
- You should be redirected to *sing up* page, here you should enter your credentials (you can use Test1@test1.com in all field for testing)
- Click **ONLY ONCE** on the button "Sign Up", and wait (for now it takes around 10 seconds to load *chat* page)
- Now you will be able to communicate with the system
- You can try to ask any thing and attach files. Enter a query and press the *enter* button (near the input area)
## Architecture
### Static view
The following **diagram** depicts the current state of our codebase organization.

We have decided to adapt this architecture to enhance the *maintainability* of the product for the following reasons:
- [x] A **modular** system, which is reflected by the use of subsystems in our code increases the **reusability** of the components.
- [x] Individual subsystems can be easily **analyzed** in conjunction with monolith products.
- [x] This approach ensures the ease and speed of **testing**.
- [x] Additionally, each part can be **easily modified** without affecting the rest of the codebase.
### Dynamic view
The following **diagram** depicts the one non-trivial case of the system use: user queries the system and attach file. This diagram can halp in understating the pipeline of file processing and response generation:

### Deployment view
The deployment architecture of The Ultimate RAG is designed to ensure reliable, scalable, and isolated environments for testing and production.
```mermaid
graph TD
subgraph Test Environment
TEST_SPACE[Hugging Face Space <br> Test Server] -->|Connects to| TEST_DB[Test PostgreSQL Database]
TEST_SPACE -->|Runs| APP_TEST[Docker Container: Application]
end
subgraph Production Environment
PROD_SPACE[Hugging Face Space <br> Production Server] -->|Connects to| PROD_DB[Production PostgreSQL Database]
PROD_SPACE -->|Runs| APP_PROD[Docker Container: Application]
end
subgraph CI/CD Pipeline
GITHUB[GitHub Repository] -->|Push to| TEST_SPACE
TEST_SPACE -->|Integration Tests Pass| PROD_SPACE
end
subgraph External Services
TEST_DB -->|Hosted on| DB_SERVICE[Supabase]
PROD_DB -->|Hosted on| DB_SERVICE
end
classDef server fill:#f9f,stroke:#333,stroke-width:2px,color:#000000;
classDef db fill:#bbf,stroke:#333,stroke-width:2px,color:#000000;
classDef pipeline fill:#bfb,stroke:#333,stroke-width:2px,color:#000000;
class TEST_SPACE,PROD_SPACE,APP_TEST,APP_PROD server;
class TEST_DB,PROD_DB db;
class GITHUB pipeline;
```
- **Diagram Location:** The deployment diagram is stored at [`docs/architecture/deployment-view/deployment.mmd`](/docs/architecture/deployment-view/deployment.md).
**Deployment Choices:**
- **Hugging Face Spaces:** We use Hugging Face Spaces for both test and production environments due to their ease of use, free tier, and seamless integration with Git-based deployment. This allows rapid deployment and automatic scaling for our Python application.
- **Docker:** The application is containerized using Docker (defined in `docker-compose.yml`) to ensure consistency across test and production environments, simplifying dependency management and deployment.
- **Separate PostgreSQL Service:** The test and production PostgreSQL databases are hosted on an external service (not Hugging Face) to provide scalability, isolation, and robust database management. This ensures that test data does not interfere with production data.
- **Isolation of Environments:** Separate Hugging Face Spaces and databases for test and production prevent test activities from affecting the live application, ensuring stability for end users.
**Customer Deployment:**
Customers can access the application directly via the production Hugging Face Space at [URL to be provided]. No local deployment is required, as the application is hosted and managed on Hugging Face. To interact with the application, customers need:
- A web browser to access the production URL.
- Optional: API keys or credentials (contact the [DevOps lead](https://github.com/Andrchest) for access details, if applicable).
If customers prefer to deploy the application locally, they can follow the [Installation](#installation) instructions in this README, which include cloning the repository, setting up Docker, and configuring a `.env` file with a PostgreSQL connection string (contact the [DevOps lead](https://github.com/Andrchest) for details).
## Development
### Kanban board
**Link to the board**: [Kanban board](https://github.com/orgs/The-Ultimate-RAG/projects/3/views/2)
#### Column Entry Criteria
##### 1. **To Do**
- [x] Issue is created using the project’s issue templates.
- [x] Issue is **estimated** (story points) by the Team.
- [x] Issue is **prioritized** by the Team.
- [x] Issue is **assigned**.
##### 2. **In Progress**
- [x] **Merge Request (MR)** is created and linked to the issue.
- [x] **Reviewer(s)** are assigned.
- [x] Code passes **automated checks** (unit&integration testing, linting).
##### 4. **Ready to Deploy**
- [x] MR is **approved** by at least one reviewer.
- [x] All **review comments** are resolved.
- [x] Code is **merged** into target branch (`main`).
##### 5. **User Testing** *(Optional)*
- [x] Feature is deployed to **testing** server.
- [x] Testers/stakeholders are **notified**
#### 6. **Done**
- [x] Feature is deployed to **production** server.
- [x] User testing (if needed) is **approved**.
- [x] Issue is **closed**.
### Git Workflow
#### Base Workflow
We have developed our **custom** workflow due to CI/CD integration issues and features of the development process. Key principles:
- `main` is always deployable.
- Feature branches are created from `main` and merged back via Pull Requests (PRs).
- No long-lived branches except `for_testing`, which serves for deploy to the testing server.
---
#### Rules
##### **1. Issues**
- Use the one of the Issue Templates.
- Include: **Description**, **Labels**, and **Milestone**.
- Assign the most logically suitable *label* from the list of [labels](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/issues/labels) (read their description first).
- Assign the issue to yourself, and contact [PM](https://github.com/PopovDanil) to re-assign if needed.
##### **2. Branching**
- For developing new feature create a new branch.
- There are now strict rules for naming, but each name should logically depict the changes on code (e.g. add response streaming → response_stream).
- For each merge mention the reason why branches were merged.
##### **3. Commit Messages**
- Template: `<type>(<scope>): <description>`.
- Examples:
```
feat(auth): add login button
fix(api): resolve null pointer in user endpoint
```
##### **4. Pull Requests (PRs) and Reviews**
- Use the [PR Template](/.github/PULL_REQUEST_TEMPLATE/standart.md).
- Target branch - `main`, but for testing `for_testing` can be used.
- Contact [PM](https://github.com/PopovDanil) to assign Reviewers.
- Merge pull request if the code passes **review**, **tests** and **linter** (in other case you will be unable to do it).
- Delete branch after merge.
##### **5. Resolving Issues**
- Close manually only after:
- [x] PR is merged.
- [x] Feature is verified in production (if applicable).
#### **Basic workflow example**
```mermaid
flowchart LR
A[Create Issue] --> B[Create Branch]
B --> C[Commit & Push]
C --> D[Open PR]
D --> E{Code Review}
E -->|Approved| F[Squash Merge]
E -->|Rejected| C
F --> G[Verify in Prod]
G --> H[Close Issue]
%% Detailed Annotations
subgraph "Issue Creation"
A
end
subgraph "Development"
B
C
end
subgraph "Collaboration"
D
E
end
subgraph "Release"
F
G
H
end
```
---
### Secrets management
Contact [DevOps lead](https://github.com/Andrchest) for more information.
All the secrets are stored in `.env` file. Its content will be provided after request to DevOps lead.
## Quality assurance
### Quality attribute scenarios
You can find scenarios in the [docs/quality-assurance/quality-attribute-scenarios.md](./docs/quality-assurance/quality-attribute-scenarios.md)
### Automated tests
We've implemented a comprehensive automated testing suite using the following tools:
- 🐍 [pytest](https://docs.pytest.org/) - Primary test runner and framework
- ⚡ [httpx](https://www.python-httpx.org/) - Async HTTP client for API testing
| Test Type | Location | Description | Tools Used |
|--------------------|-------------------------------|-----------------------------------------------------------------------------|---------------------|
| Unit Tests | `app/tests/unit/` | Tests for individual components and utility functions | pytest |
| Integration Tests | `app/tests/integration/` | Tests for component interactions and, API and RAG systems integrations | pytest + httpx |
| Performance Tests | `app/tests/performance/` | *Will be added soon.* Will collect the statistical information of time, speed, and correctness evaluations | pytest + httpx |
### User acceptance tests
See [acceptance test](./docs/quality-assurance/user-acceptance-tests.md) for the formal definition of system readiness.
## Build and deployment
### Continuous Integration
Our Continuous Integration (CI) pipeline ensures code quality by running automated checks on every pull request to the `main` branch. The pipeline is managed using GitHub Actions and is defined in:
- [`.github/workflows/unit-tests.yml`](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/blob/main/.github/workflows/unit-tests.yml)
In the CI pipeline, we use the following tools:
- **Static Analysis Tools:**
- **flake8**: A linter for Python that enforces coding style and detects programming errors.
- **bandit**: A security vulnerability scanner for Python, identifying potential security issues in the codebase.
- **Testing Tools:**
- **pytest**: A testing framework for Python, used to run unit tests located in [`app/tests/unit`](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/tree/main/app/tests/unit).
If any checks fail, the pull request cannot be merged into `main`. All CI workflow runs can be viewed at:
- [GitHub Actions - CI Workflow Runs](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/actions/workflows/unit-tests.yml)
### Continuous Deployment
Our Continuous Deployment (CD) pipeline automatically deploys the application after a successful merge into `main`. The pipeline is defined in:
- [`.github/workflows/sync-to-hf.yml`](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/blob/main/.github/workflows/sync-to-hf.yml)
The CD pipeline performs the following steps:
1. Pushes the updated code to a **Hugging Face Space** (test environment) using `git`, where it is automatically deployed.
2. Runs **integration tests** on the test server with a test PostgreSQL database (hosted on a separate service), using tests located in [`app/tests/integration`](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/tree/main/app/tests/integration).
3. If integration tests pass, deploys to a separate **Hugging Face Space** (production environment) with a production PostgreSQL database (also hosted on a separate service). Deployment takes approximately 2–3 minutes.
4. If any tests fail, the production server remains unaffected.
In the CD pipeline, we use the following tools:
- **Deployment Tools:**
- **Docker**: Builds and packages the application as a container.
- **git**: Pushes the application to Hugging Face Spaces for deployment.
- **Testing Tools:**
- **pytest**: Runs integration tests on the test server.
All CD workflow runs can be viewed at:
- [GitHub Actions - CD Workflow Runs](https://github.com/The-Ultimate-RAG/The-Ultimate-RAG/actions/workflows/sync-to-hf.yml)
## License
This project is licensed under the [MIT License](LICENSE).
|