VijayShinde1996/local-rag-engine

CSS

0

6 commits

updated Jul 26, 2025

See the code

README

πŸ” Offline RAG (Retrieval-Augmented Generation)

An open-source, fully offline Retrieval-Augmented Generation (RAG) system ## πŸ“‹ To-Do List

  • Add more example physics documents
  • Implement batch processing for large files
  • Add support for more document formats
  • Enhance error handling and user feedback
  • Add unit tests and documentation
  • Optimize embedding process for better performance
  • Add configuration file for easy model switching
  • Implement user session management

✨ Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Designed & Developed by VRS Foundation (Vijay R. Shinde)

For questions or support, please open an issue on GitHub.hout internet**, without APIs, and supports any subject β€” driven by uploaded documents or a master knowledge base.

Built with:

  • 🧠 SentenceTransformers for semantic embeddings
  • πŸ“¦ FAISS for vector indexing
  • πŸ€– Local LLMs like LLaMA 2 / Mistral via llama-cpp-python
  • πŸ–₯️ Flask + HTML/JS frontend with animations and admin control

πŸš€ Features

  • πŸ’Ύ 100% Offline: Works in disconnected or air-gapped environments
  • πŸ“š Custom + Default Knowledge: Upload your own PDFs or rely on preloaded knowledge
  • ⚑ Fast Embedding & Retrieval: Uses MiniLM or BGE with FAISS
  • πŸ”’ No API Keys or External Calls: All models run locally
  • πŸŽ›οΈ Admin Panel: Upload/delete master KB files
  • πŸ§‘β€πŸ’» User Panel: Upload files, ask questions, view answers
  • 🎨 Dark-Themed, Animated UI: Modern frontend with clear feedback

🧱 Architecture Overview

File Upload -> Text Chunking -> Sentence Embedding -> FAISS Vector Store -> Top-k Retrieval -> Prompt Builder -> llama.cpp (LLaMA / Mistral GGUF) -> Final Answer

                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚         User / Admin       β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
                                           β–Ό
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚    🌐 Frontend (Flask UI)  β”‚
                              β”‚  HTML/CSS/JS + AJAX + Jinjaβ”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚            Flask Web Server             β”‚
                      β”‚           (routes.py + API)             β”‚
                      β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                           β”‚                              β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚  πŸ“„ embedder.py   β”‚            β”‚     rag.py (Query Engine)   β”‚
          β”‚ - Chunking logic  β”‚            β”‚ - Embeds question           β”‚
          β”‚ - Embeddings      β”‚            β”‚ - FAISS top-k retrieval     β”‚
          β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                                          β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  πŸ” FAISS Vector Store   β”‚              β”‚  🧠 llm.py (LLM Prompting)β”‚
 β”‚  - User Index (session)   β”‚              β”‚  - prompt construction    β”‚
 β”‚  - Master KB (fallback)   β”‚              β”‚  - llama-cpp-python call  β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β–²
                                           β”‚
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β”‚   πŸ¦™ Local LLM Runtime Engine  β”‚
                          β”‚     (llama-cpp-python / GGUF)   β”‚
                          β”‚   Quantized Mistral / LLaMA     β”‚
                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Project Structure

offline-rag/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ routes.py        # Flask route handling
β”‚   β”œβ”€β”€ embedder.py      # Chunking + Embedding logic
β”‚   β”œβ”€β”€ vector_store.py  # FAISS vector store manager
β”‚   β”œβ”€β”€ rag.py          # Retrieval + LLM answering
β”‚   β”œβ”€β”€ llm.py          # llama-cpp wrapper
β”‚   └── file_utils.py    # Helper functions
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ templates/       # HTML templates (index, admin, intro)
β”‚   └── static/
β”‚       β”œβ”€β”€ css/        # Dark UI styling
β”‚       β”œβ”€β”€ js/         # AJAX & animation logic
β”‚       └── images/     # UI assets
β”‚
β”œβ”€β”€ data/               # Stored embeddings + user/master files
β”œβ”€β”€ models/            # GGUF LLM model (LLaMA/Mistral)
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
└── run.py            # Entry point

πŸ“₯ Installation

⚠️ Works best on Linux or Windows with Python 3.10+

  1. Clone the repo
git clone https://github.com/vijay-shinde/offline-rag.git
cd offline-rag
Create virtual env + install dependencies

```bash
# Create virtual environment
python -m venv envGenAI
source envGenAI/bin/activate  # Linux/Mac
# or
envGenAI\Scripts\activate     # Windows

# Install dependencies
pip install -r requirements.txt
  1. Download LLM Model

    • Download a GGUF quantized model (e.g., Mistral 7B Q4)
    • Place it in the models/ directory
  2. Run the Application

python run.py

Visit http://localhost:5000 in your browser

πŸ§ͺ Example Usage

Upload newton_laws_summary.pdf via Admin panel. Ask: β€œWhat does Newton’s Second Law explain?”

➑️ The system retrieves from master KB and responds using the local LLM.

πŸ“˜ Research Summary Inspired by: β€œAttention is All You Need”, Vaswani et al. (2017)

Embedding: Sentence-BERT (MiniLM-L6-v2 or BGE-Small)

Vector Search: FAISS (Facebook AI)

LLM: LLaMA 2 / Mistral via llama-cpp-python (GGUF format)

πŸ“„ Full whitepaper: Offline_RAG_IEEE_Paper.pdf

πŸ›‘οΈ Use Cases Education (offline Q&A)

Secure Enterprises

Remote research labs

Edge AI / Dev sandboxes

🀝 Contribution PRs welcome! Feel free to fork, suggest improvements, or extend it for other domains.

πŸ“œ License MIT License

Designed & Developed by [VRS Foundation (Vijay R. Shinde)]

markdown Copy Edit


VijayShinde1996/local-rag-engine

CSS

0

6 commits

updated Jul 26, 2025

See the code

README

πŸ” Offline RAG (Retrieval-Augmented Generation)

An open-source, fully offline Retrieval-Augmented Generation (RAG) system ## πŸ“‹ To-Do List

  • Add more example physics documents
  • Implement batch processing for large files
  • Add support for more document formats
  • Enhance error handling and user feedback
  • Add unit tests and documentation
  • Optimize embedding process for better performance
  • Add configuration file for easy model switching
  • Implement user session management

✨ Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Designed & Developed by VRS Foundation (Vijay R. Shinde)

For questions or support, please open an issue on GitHub.hout internet**, without APIs, and supports any subject β€” driven by uploaded documents or a master knowledge base.

Built with:

  • 🧠 SentenceTransformers for semantic embeddings
  • πŸ“¦ FAISS for vector indexing
  • πŸ€– Local LLMs like LLaMA 2 / Mistral via llama-cpp-python
  • πŸ–₯️ Flask + HTML/JS frontend with animations and admin control

πŸš€ Features

  • πŸ’Ύ 100% Offline: Works in disconnected or air-gapped environments
  • πŸ“š Custom + Default Knowledge: Upload your own PDFs or rely on preloaded knowledge
  • ⚑ Fast Embedding & Retrieval: Uses MiniLM or BGE with FAISS
  • πŸ”’ No API Keys or External Calls: All models run locally
  • πŸŽ›οΈ Admin Panel: Upload/delete master KB files
  • πŸ§‘β€πŸ’» User Panel: Upload files, ask questions, view answers
  • 🎨 Dark-Themed, Animated UI: Modern frontend with clear feedback

🧱 Architecture Overview

File Upload -> Text Chunking -> Sentence Embedding -> FAISS Vector Store -> Top-k Retrieval -> Prompt Builder -> llama.cpp (LLaMA / Mistral GGUF) -> Final Answer

                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚         User / Admin       β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
                                           β–Ό
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚    🌐 Frontend (Flask UI)  β”‚
                              β”‚  HTML/CSS/JS + AJAX + Jinjaβ”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚            Flask Web Server             β”‚
                      β”‚           (routes.py + API)             β”‚
                      β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                           β”‚                              β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚  πŸ“„ embedder.py   β”‚            β”‚     rag.py (Query Engine)   β”‚
          β”‚ - Chunking logic  β”‚            β”‚ - Embeds question           β”‚
          β”‚ - Embeddings      β”‚            β”‚ - FAISS top-k retrieval     β”‚
          β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                                          β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  πŸ” FAISS Vector Store   β”‚              β”‚  🧠 llm.py (LLM Prompting)β”‚
 β”‚  - User Index (session)   β”‚              β”‚  - prompt construction    β”‚
 β”‚  - Master KB (fallback)   β”‚              β”‚  - llama-cpp-python call  β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β–²
                                           β”‚
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β”‚   πŸ¦™ Local LLM Runtime Engine  β”‚
                          β”‚     (llama-cpp-python / GGUF)   β”‚
                          β”‚   Quantized Mistral / LLaMA     β”‚
                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Project Structure

offline-rag/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ routes.py        # Flask route handling
β”‚   β”œβ”€β”€ embedder.py      # Chunking + Embedding logic
β”‚   β”œβ”€β”€ vector_store.py  # FAISS vector store manager
β”‚   β”œβ”€β”€ rag.py          # Retrieval + LLM answering
β”‚   β”œβ”€β”€ llm.py          # llama-cpp wrapper
β”‚   └── file_utils.py    # Helper functions
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ templates/       # HTML templates (index, admin, intro)
β”‚   └── static/
β”‚       β”œβ”€β”€ css/        # Dark UI styling
β”‚       β”œβ”€β”€ js/         # AJAX & animation logic
β”‚       └── images/     # UI assets
β”‚
β”œβ”€β”€ data/               # Stored embeddings + user/master files
β”œβ”€β”€ models/            # GGUF LLM model (LLaMA/Mistral)
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
└── run.py            # Entry point

πŸ“₯ Installation

⚠️ Works best on Linux or Windows with Python 3.10+

  1. Clone the repo
git clone https://github.com/vijay-shinde/offline-rag.git
cd offline-rag
Create virtual env + install dependencies

```bash
# Create virtual environment
python -m venv envGenAI
source envGenAI/bin/activate  # Linux/Mac
# or
envGenAI\Scripts\activate     # Windows

# Install dependencies
pip install -r requirements.txt
  1. Download LLM Model

    • Download a GGUF quantized model (e.g., Mistral 7B Q4)
    • Place it in the models/ directory
  2. Run the Application

python run.py

Visit http://localhost:5000 in your browser

πŸ§ͺ Example Usage

Upload newton_laws_summary.pdf via Admin panel. Ask: β€œWhat does Newton’s Second Law explain?”

➑️ The system retrieves from master KB and responds using the local LLM.

πŸ“˜ Research Summary Inspired by: β€œAttention is All You Need”, Vaswani et al. (2017)

Embedding: Sentence-BERT (MiniLM-L6-v2 or BGE-Small)

Vector Search: FAISS (Facebook AI)

LLM: LLaMA 2 / Mistral via llama-cpp-python (GGUF format)

πŸ“„ Full whitepaper: Offline_RAG_IEEE_Paper.pdf

πŸ›‘οΈ Use Cases Education (offline Q&A)

Secure Enterprises

Remote research labs

Edge AI / Dev sandboxes

🀝 Contribution PRs welcome! Feel free to fork, suggest improvements, or extend it for other domains.

πŸ“œ License MIT License

Designed & Developed by [VRS Foundation (Vijay R. Shinde)]

markdown Copy Edit