{"id":32687348,"url":"https://github.com/bensbehchaimae/rag-qa-system","last_synced_at":"2025-11-01T11:01:51.834Z","repository":{"id":321664629,"uuid":"1011904134","full_name":"bensbehChaimae/rag-qa-system","owner":"bensbehChaimae","description":"A RAG question/answering application","archived":false,"fork":false,"pushed_at":"2025-10-30T20:09:18.000Z","size":720,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-30T22:09:14.040Z","etag":null,"topics":["celery","cohere","fastapi","llm","monitoring","openai","python3","rag"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bensbehChaimae.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-01T14:04:08.000Z","updated_at":"2025-10-06T11:18:46.000Z","dependencies_parsed_at":"2025-10-30T22:09:24.288Z","dependency_job_id":"f2667fc0-f646-4781-8655-fd4db6ed1207","html_url":"https://github.com/bensbehChaimae/rag-qa-system","commit_stats":null,"previous_names":["bensbehchaimae/rag-qa-system"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bensbehChaimae/rag-qa-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensbehChaimae%2Frag-qa-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensbehChaimae%2Frag-qa-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensbehChaimae%2Frag-qa-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensbehChaimae%2Frag-qa-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bensbehChaimae","download_url":"https://codeload.github.com/bensbehChaimae/rag-qa-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensbehChaimae%2Frag-qa-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282131907,"owners_count":26619252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-01T02:00:06.759Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["celery","cohere","fastapi","llm","monitoring","openai","python3","rag"],"created_at":"2025-11-01T11:00:24.077Z","updated_at":"2025-11-01T11:01:51.825Z","avatar_url":"https://github.com/bensbehChaimae.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rag application\n\nAn implementation of a Retrieval-Augmented Generation (RAG) model for question answering application.\nThis app allows users to upload documents and ask questions, returning context-aware answers based on the uploaded content.\n\n## Table of Contents\n\n- [Technologies](#technologies)\n  - [Languages and Frameworks](#languages-and-frameworks)\n  - [Databases](#databases)\n  - [ORM \u0026 Migrations](#orm--migrations)\n  - [LLM Providers](#llm-providers)\n  - [Utilities](#utilities)\n- [RAG Application Workflow](#rag-retrieval-augmented-generation-application-workflow)\n  - [1. Upload a Document](#1-upload-a-document)\n  - [2. Process the Document](#2-process-the-document)\n  - [3. Search for Similar Documents](#3-search-for-similar-documents-semantic-search)\n  - [4. Generate the Answer](#4-generate-the-answer)\n- [Project Architecture](#project-architecture)\n  - [API Architecture Overview](#api-architecture-overview)\n  - [Project Architecture Overview](#project-architecture-overview-1)\n- [Requirements](#requirements)\n- [Installation](#installation)\n  - [Install Dependencies](#install-dependencies)\n  - [Install Python using MiniConda](#install-python-using-miniconda)\n  - [Install the Required Packages](#install-the-required-packages)\n  - [Setup Environment Variables](#setup-the-environment-variables)\n- [Running the Application](#running-the-application)\n  - [Run the FastAPI Server](#run-the-fastapi-server)\n  - [Run Docker Compose Service](#run-docker-compose-service)\n- [Optional Setup](#optional-setup)\n\n---\n\n## Technologies\n\n### Languages and Frameworks\n![Python](https://img.shields.io/badge/Python-3.10+-blue.svg)\n![FastAPI](https://img.shields.io/badge/FastAPI-Asynchronous-green.svg)\n![Uvicorn](https://img.shields.io/badge/Uvicorn-ASGI-red.svg)\n![Pydantic](https://img.shields.io/badge/Pydantic-v2+-green.svg)\n\n### Databases\n![PostgreSQL](https://img.shields.io/badge/PostgreSQL-14+-blue.svg?logo=postgresql)\n![MongoDB](https://img.shields.io/badge/MongoDB-6.x-green.svg?logo=mongodb)\n![pgvector](https://img.shields.io/badge/pgvector-0.5+-orange.svg)\n![Qdrant](https://img.shields.io/badge/Qdrant-VectorDB-blueviolet.svg)\n\n### ORM \u0026 Migrations\n![SQLAlchemy](https://img.shields.io/badge/SQLAlchemy-ORM-red.svg)\n![Alembic](https://img.shields.io/badge/Alembic-Migrations-lightgrey.svg)\n\n### LLM Providers\n![OpenAI](https://img.shields.io/badge/OpenAI-API-black.svg)\n![Cohere](https://img.shields.io/badge/Cohere-LLM-purple.svg)\n![Ollama](https://img.shields.io/badge/Ollama-Local-orange.svg)\n\n### Utilities\n![ngrok](https://img.shields.io/badge/ngrok-SecureTunnel-orange.svg)\n\n## RAG (Retrieval-Augmented Generation) Application Workflow\n\nTraditional language models (LLMs) generate answers based only on the knowledge they were trained on. This can lead to outdated or hallucinated responses, especially when dealing with domain-specific or dynamic information.\n\n`Retrieval-Augmented Generation (RAG)` Architecture solves this by combining the power of information retrieval and language generation. Instead of relying solely on the model's internal knowledge, RAG pipelines retrieve relevant documents from an external knowledge base and use them to ground the model's answers.\n\nIn a typical RAG pipeline: \n\n### 1. Upload a Document\n\n- The user uploads one or more documents (PDF, TXT, etc.) to be used as the knowledge base.\n\n### 2. Process the Document\n\nThis step involves:\n\n- Extracting text from the uploaded files.\n- Chunking the extracted text into smaller pieces (documents/passages).\n- Parsing and cleaning the data as needed.\n\n![Data parsing](src/assets/images/Data_parsing.png)\n\n**Indexing**\n\n![indexing](src/assets/images/Indexing.png)\n\n- The chunks are converted into embeddings using an embedding model.\n- The embeddings are stored in a vector store for efficient similarity search.\n\n### 3. Search for Similar Documents (Semantic Search)\n\nWhen a query is submitted:\n\n- The query is converted into an embedding.\n- A similarity search is performed against the vector store to retrieve the most relevant chunks.\n\n![search](src/assets/images/Semantic_search.png)\n\n### 4. Generate the Answer\n\n- A prompt is constructed using the user query and retrieved documents.\n- The prompt is passed to an LLM (Large Language Model).\n- The LLM returns a response grounded in the relevant information.\n\n![answer](src/assets/images/Get_answer.png)\n\n## Project Architecture\n\n### API Architecture Overview\n\n![api](src/assets/architecture/API_architecture.png)\n\nThis API architecture is built with FastAPI and provides routes for monitoring, document ingestion, semantic indexing, and health checks. Documents can be uploaded, processed into chunks, stored in a VectorDB, and then queried for search or Q\u0026A with an LLM. Metrics endpoints support observability, while base endpoints handle system and health information.\n\n### Project Architecture Overview\n\n![app](src/assets/architecture/architecture.png)\n\nThis architecture enables users to upload documents and query them through a FastAPI backend. Document processing runs in the background via Celery, where text is extracted (using PyMuPDF and Tesseract), converted into vector embeddings with Cohere, and stored in Qdrant. When a question is asked, the system retrieves the most relevant document chunks and leverages LangChain to generate a context-aware response. The entire solution is containerized with Docker, deployed on DigitalOcean, and monitored using Prometheus and Grafana.\n\n## Requirements\n\n- Python 3.12\n\n## Installation\n\n### Install Dependencies\n\nTo run this project on Windows, follow these steps:\n- Install WSL and Ubuntu for Windows ([Tutorial](https://www.youtube.com/watch?v=IL7Jd9rjgrM))\n- Open your Ubuntu terminal and update the package lists:\n\n```bash\nsudo apt update\n```\n\n### Install Python using MiniConda\n\n- Download and install MiniConda in ubuntu from [here](https://www.anaconda.com/docs/getting-started/miniconda/install)\n- Create a new environment using the following command:\n\n```bash\n$ conda create -n \u003cenv_name\u003e python=3.12\n```\n\n- Activate the environment:\n\n```bash\n$ conda activate \u003cenv_name\u003e\n```\n\n### Install the Required Packages\n\n#### Prerequisites for Linux/WSL\n\nBefore installing the Python dependencies, ensure that the required system packages are installed to avoid compilation or runtime errors:\n\n```bash\n$ sudo apt update \n$ sudo apt install libpq-dev gcc python3-dev\n```\n\nOnce the system packages are in place, install the Python dependencies from the requirements file:\n\n```bash\n$ pip install -r requirements.txt\n```\n\n### Setup the Environment Variables\n\nSet your environment variables in the `.env` file. \n\n```bash\n$ cp .env.example .env\n```\n\n## Running the Application\n\n### Run the FastAPI Server\n\nYou can run the FastAPI server using Uvicorn.\n\n- Run the server locally: \n\n```bash\n$ uvicorn main:app --reload \n```\n\n- Run the server with custom host and port:\n\n```bash\n$ uvicorn main:app --reload --host 0.0.0.0 --port 5000\n```\n\n### Run Docker Compose Service\n\nCopy `.env.example` in your `.env` and update it with your credentials.\n\n```bash\n$ cd docker\n$ cp .env.example .env\n```\n\n## Optional Setup\n\nSetup your command line interface for better readability:\n\n```bash\nexport PS1=\"\\[\\033[01;32m\\]\\u@\\h:\\w\\n\\[\\033[00m\\]\\$ \"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbensbehchaimae%2Frag-qa-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbensbehchaimae%2Frag-qa-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbensbehchaimae%2Frag-qa-system/lists"}