Skip to content
ms00000ms0000Public

About

HyperRAG — Enterprise-grade Multi-Document RAG Assistant using Hybrid Search, Cross-Encoder Reranking, Gemini 2.5 Flash, and Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

27 Commits

Folders and files

Repository files navigation

🚀 Enterprise Multi-Document RAG Assistant

Python Streamlit FAISS Gemini Sentence Transformers BM25 Cross Encoder License

Enterprise-Grade Multi-Document Retrieval-Augmented Generation (RAG) Assistant

Upload multiple documents, perform Hybrid Search using FAISS + BM25, rerank results with Cross-Encoder, and generate context-aware answers using Google's Gemini 2.5 Flash—all through an elegant Streamlit interface.

🌐 Live Demo:
https://hyperrag.streamlit.app/

💻 GitHub Repository:
https://github.com/ms00000ms0000/HyperRAG


📌 Overview

Enterprise Multi-Document RAG Assistant is a production-oriented Retrieval-Augmented Generation (RAG) system designed to answer user queries from multiple uploaded documents using modern information retrieval and Large Language Models.

Unlike traditional document chatbots that rely solely on semantic similarity, this project combines Hybrid Retrieval, Cross-Encoder Reranking, Conversation Memory, and Citation Generation to provide highly relevant, explainable, and context-aware responses.

The system is built with a modular architecture that separates indexing, retrieval, reranking, prompting, inference, memory management, and user interface into independent components, making it scalable and easy to maintain.

Whether you're querying company policies, employee handbooks, research papers, legal documents, or technical manuals, the assistant efficiently retrieves the most relevant information before generating an accurate response backed by citations.


🎯 Objectives

The primary goals of this project are:

  • Build a production-ready Retrieval-Augmented Generation (RAG) system.
  • Support multiple document formats.
  • Enable semantic and lexical search simultaneously.
  • Improve retrieval quality using reranking.
  • Generate trustworthy answers with citations.
  • Maintain conversation history.
  • Provide an intuitive enterprise-grade Streamlit interface.
  • Follow modular software engineering principles.
  • Create a deployment-ready AI application.

✨ Key Features

📄 Multi-Document Support

Upload multiple files simultaneously and query them together.

Supported formats:

  • PDF
  • DOCX
  • TXT

🔍 Hybrid Search

Instead of relying on only vector similarity, the system performs:

  • Semantic Search (FAISS)
  • Lexical Search (BM25)

Both retrieval methods are fused using Reciprocal Rank Fusion (RRF) to maximize retrieval accuracy.


🧠 Context-Aware AI Responses

The assistant uses Google's Gemini 2.5 Flash to generate natural, human-like answers based strictly on retrieved document context.

Benefits include:

  • Reduced hallucinations
  • Context-aware responses
  • Better factual grounding

🎯 Cross-Encoder Reranking

Retrieved chunks are reranked using a Cross-Encoder model before being sent to the LLM.

Advantages:

  • Higher answer quality
  • Better relevance
  • Reduced noisy retrieval

📚 Automatic Citations

Every generated answer includes source references containing:

  • Document Name
  • Page Number

This allows users to verify where information originated.


💬 Conversation Memory

The assistant remembers previous interactions during the current session, enabling:

  • Follow-up questions
  • Context-aware conversations
  • Better user experience

📊 Retrieval Metrics

Every query includes detailed execution statistics:

  • Retrieval Time
  • Reranking Time
  • Prompt Building Time
  • LLM Response Time
  • Total Execution Time
  • Retrieved Chunks
  • Indexed Vectors
  • Embedding Dimension

⚡ Smart Index Management

The system avoids unnecessary re-indexing using document hashing.

Features include:

  • Automatic change detection
  • Incremental rebuild logic
  • Faster startup
  • Efficient indexing

🎨 Enterprise Streamlit Interface

The project includes a modern Streamlit frontend featuring:

  • Drag-and-drop document upload
  • ChatGPT-style conversation interface
  • Source citations
  • Metrics dashboard
  • Download options
  • Session management
  • Clean responsive layout

🏗️ System Architecture

The application follows a modular enterprise architecture consisting of two major pipelines.

1️⃣ Indexing Pipeline

Responsible for preparing documents for retrieval.

Workflow:

Documents
      │
      ▼
Document Loader
      │
      ▼
Chunking Service
      │
      ▼
Embedding Generator
      │
      ▼
FAISS Vector Index
      │
      ├──────────────► BM25 Index
      │
      ▼
Persistent Storage

2️⃣ Query Pipeline

Responsible for answering user queries.

User Query
      │
      ▼
Conversation Memory
      │
      ▼
Hybrid Search
      │
      ├──── FAISS
      │
      └──── BM25
             │
             ▼
     Reciprocal Rank Fusion
             │
             ▼
      Cross Encoder Reranker
             │
             ▼
       Prompt Builder
             │
             ▼
      Gemini 2.5 Flash
             │
             ▼
 Answer + Citations + Metrics

🧩 Core Components

Component Responsibility
Document Manager Finds and validates uploaded files
Loader Factory Selects appropriate loader (PDF/DOCX/TXT)
Chunking Service Splits documents into overlapping chunks
Embedding Service Generates sentence embeddings
FAISS Vector Store Semantic similarity search
BM25 Engine Keyword-based retrieval
Hybrid Search Combines FAISS and BM25
RRF Service Fuses search rankings
Cross Encoder Reranks retrieved chunks
Prompt Builder Builds optimized prompts
Gemini Service Generates AI responses
Citation Service Creates document citations
Conversation Memory Maintains chat history
Session Manager Tracks session statistics
Streamlit UI User interaction layer

🖼️ Project Architecture

Multi-doc-rag-architecture


🌟 Why This Project?

Most basic RAG systems only perform vector search, which often misses exact keyword matches or retrieves less relevant context.

This project enhances traditional RAG by combining:

  • Hybrid Retrieval (FAISS + BM25)
  • Reciprocal Rank Fusion (RRF)
  • Cross-Encoder Reranking
  • Conversation Memory
  • Source Citations
  • Performance Metrics
  • Enterprise-grade Streamlit UI
  • Smart Index Rebuilding
  • Modular Software Architecture

The result is a scalable, production-oriented AI assistant suitable for enterprise knowledge bases, HR policy assistants, legal document search, research paper analysis, and internal documentation systems.


🛠️ Technology Stack

Category Technology
Programming Language Python 3.11+
Frontend Streamlit
LLM Google Gemini 2.5 Flash
Embedding Model Sentence Transformers (all-MiniLM-L6-v2)
Vector Database FAISS
Lexical Search BM25
Retrieval Fusion Reciprocal Rank Fusion (RRF)
Reranker Cross-Encoder (MS MARCO)
Document Processing PyMuPDF, python-docx
Numerical Computing NumPy
Environment Management python-dotenv
Logging Python Logging
Deployment Streamlit Community Cloud
Version Control Git & GitHub

📂 Project Structure

enterprise-multi-document-rag/
│
├── app/
│   ├── chunking/
│   ├── config/
│   ├── document_loader/
│   ├── fusion/
│   ├── llm/
│   ├── logging/
│   ├── pipelines/
│   ├── prompts/
│   ├── reranker/
│   ├── retrieval/
│   ├── search/
│   ├── services/
│   ├── session/
│   ├── storage/
│   ├── ui/
│   ├── utils/
│   └── vectorstore/
│
├── docs/
│
├── uploaded_documents/
│
├── faiss_index/
│
├── run.py
├── requirements.txt
├── packages.txt
├── .env.example
├── .gitignore
└── README.md

⚙️ How It Works

The project follows a Retrieval-Augmented Generation (RAG) workflow consisting of two major stages.

Stage 1 — Document Indexing

Documents
      │
      ▼
Load Documents
      │
      ▼
Chunk Documents
      │
      ▼
Generate Embeddings
      │
      ▼
Create FAISS Index
      │
      ▼
Create BM25 Index
      │
      ▼
Save Index

Stage 2 — Question Answering

User Query
      │
      ▼
Conversation Memory
      │
      ▼
Hybrid Search
      │
      ▼
Reciprocal Rank Fusion
      │
      ▼
Cross Encoder
      │
      ▼
Prompt Builder
      │
      ▼
Gemini 2.5 Flash
      │
      ▼
Answer
      │
      ├── Citations
      └── Performance Metrics

🚀 Getting Started

Clone Repository

git clone https://github.com/ms00000ms0000/enterprise-multi-document-rag.git

cd enterprise-multi-document-rag

Create Virtual Environment

Windows

python -m venv .venv

.venv\Scripts\activate

Linux / macOS

python3 -m venv .venv

source .venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Streamlit Deployment Dependencies

For Streamlit Cloud, install system packages using:

packages.txt
libgl1
libglib2.0-0

🔑 Environment Variables

Create a file named:

.env

Add the following:

GEMINI_API_KEY=YOUR_GEMINI_API_KEY

Obtain Gemini API Key

  1. Visit
https://aistudio.google.com/app/apikey
  1. Create a new API Key

  2. Copy it into the .env file


▶️ Run Command-Line Version

python run.py

Example

python run.py --docs docs

🌐 Run Streamlit Web Application

streamlit run app/ui/streamlit_app.py

After launching, open

http://localhost:8501

☁️ Streamlit Deployment

The application is deployed on Streamlit Community Cloud.

Live Demo

https://hyperrag.streamlit.app/


📦 Supported File Formats

The assistant currently supports:

  • PDF
  • DOCX
  • TXT

Multiple files can be uploaded simultaneously.


🧠 Retrieval Pipeline

Every user query goes through the following pipeline:

User Question

        │

        ▼

Conversation Memory

        │

        ▼

Vector Retrieval (FAISS)

        │

        ▼

Keyword Retrieval (BM25)

        │

        ▼

Reciprocal Rank Fusion

        │

        ▼

Cross Encoder Reranking

        │

        ▼

Prompt Construction

        │

        ▼

Gemini 2.5 Flash

        │

        ▼

Answer + Citations + Metrics

⚡ Performance Optimizations

This project includes several optimizations for faster retrieval and lower latency.

Smart Index Reuse

Previously generated FAISS indexes are reused whenever possible to avoid unnecessary embedding generation.


Batch Embedding Generation

Embeddings are generated in configurable batches for better memory utilization and faster indexing.


Hybrid Retrieval

Combining semantic and lexical retrieval significantly improves recall compared to standalone vector search.


Cross-Encoder Reranking

Only the most relevant chunks are forwarded to the language model, improving both response quality and inference speed.


Conversation Memory

Recent interactions are maintained within the session, enabling contextual follow-up questions.


🔒 Security Notes

  • API keys are never hardcoded.
  • Environment variables are used for sensitive credentials.
  • Uploaded documents remain isolated within the active session.
  • The application does not permanently store user conversations.
  • Document citations improve transparency and answer traceability.

💼 Enterprise Use Cases

This system can be adapted for:

  • 📚 Enterprise Knowledge Base
  • 🏢 HR Policy Assistant
  • ⚖️ Legal Document Search
  • 🏥 Healthcare Documentation
  • 🎓 Educational Content Assistant
  • 📄 Research Paper Exploration
  • 🏦 Banking & Financial Compliance
  • 🛡️ Internal SOP Search
  • 📑 Technical Documentation Assistant
  • 🧾 Company Handbook Assistant

📈 Scalability

The modular architecture allows future integration with:

  • Pinecone
  • ChromaDB
  • Weaviate
  • Milvus
  • Azure AI Search
  • Elasticsearch
  • OpenSearch
  • PostgreSQL + pgvector

without major architectural changes.


📸 Application Screenshots

🏠 Home Page

Rag_Home_page_ss


📂 Document Upload

Rag_Upload_Page_ss


💬 Chat Interface

Rag_Chat_ss


📚 Source Citations

Rag_source_ss


📥 Download and Clear Chat History

Rag_download_clear_chat_option_ss


📊 Performance Metrics

Rag_Metrics_ss


📈 Performance Metrics

For every user query, the system reports detailed execution statistics.

Metric Description
Retrieval Time Time spent performing Hybrid Search
Reranking Time Cross-Encoder reranking latency
Prompt Build Time Prompt construction time
LLM Time Gemini inference time
Total Time Overall pipeline execution
Indexed Vectors Number of vectors stored in FAISS
Embedding Dimension Embedding vector dimension
Final Chunks Chunks provided to Gemini

📚 Libraries Used

AI & LLM

  • Google Gemini SDK
  • Sentence Transformers
  • Cross Encoder

Retrieval

  • FAISS
  • rank-bm25
  • NumPy

Document Processing

  • PyMuPDF
  • python-docx

Web Interface

  • Streamlit

Utilities

  • python-dotenv
  • pathlib
  • hashlib
  • logging
  • pickle
  • json
  • tempfile
  • shutil

📖 Example Workflow

Upload Documents

        │

        ▼

Documents Indexed

        │

        ▼

Ask Question

        │

        ▼

Hybrid Retrieval

        │

        ▼

Cross Encoder

        │

        ▼

Gemini Generates Answer

        │

        ▼

Answer + Citations + Metrics

🎯 Future Improvements

The architecture has been intentionally designed to support enterprise-scale enhancements.

Planned improvements include:

  • 🔐 User Authentication
  • 👥 Multi-user Session Management
  • 🖼️ Image Retrieval (Multimodal RAG)
  • 📊 Admin Dashboard
  • ☁️ Cloud Vector Databases (Pinecone, Weaviate, Milvus)
  • 📂 Shareable Knowledge Bases
  • 📑 OCR Support for Scanned PDFs
  • 🎤 Voice-based Question Answering
  • 🌍 Multi-language Document Support
  • 🔎 Metadata-based Filtering
  • 📅 Incremental Document Indexing
  • 📡 API Version using FastAPI
  • 🤖 Agentic RAG Workflow
  • 🧩 MCP (Model Context Protocol) Integration
  • 📈 Analytics Dashboard
  • 🛡️ Role-Based Access Control (RBAC)
  • 📝 Feedback-based Answer Improvement

🏆 Learning Outcomes

This project demonstrates practical implementation of:

  • Retrieval-Augmented Generation (RAG)
  • Large Language Model Integration
  • Hybrid Information Retrieval
  • Vector Search using FAISS
  • Lexical Search using BM25
  • Cross-Encoder Reranking
  • Prompt Engineering
  • Modular Software Architecture
  • Production-ready Python Development
  • Streamlit Web Application Development
  • Performance Monitoring
  • Citation-based Explainability
  • Enterprise Software Design

🤝 Contributing

Contributions are always welcome.

If you would like to improve this project:

  1. Fork the repository
  2. Create a new feature branch
git checkout -b feature/your-feature
  1. Commit your changes
git commit -m "Add new feature"
  1. Push the branch
git push origin feature/your-feature
  1. Open a Pull Request

🐞 Issues

If you encounter any bugs or have suggestions for improvements, please open an issue on GitHub.

Every contribution helps make the project better.


📬 Connect with me


⭐ Support the Project

If you found this project helpful or learned something from it:

⭐ Star the repository

🍴 Fork the project

🛠️ Contribute new features

📢 Share it with others

Your support motivates continued development and future open-source AI projects.


📄 License

This project is licensed under the MIT License.

You are free to:

  • Use
  • Modify
  • Distribute
  • Build upon this project

with proper attribution.

See the LICENSE file for complete details.


🚀 Built with ❤️ using Python, Streamlit, FAISS, BM25, Cross-Encoder & Google Gemini

Thank you for visiting this repository!

⭐ Don't forget to star the repository if you like the project! ⭐

About

HyperRAG — Enterprise-grade Multi-Document RAG Assistant using Hybrid Search, Cross-Encoder Reranking, Gemini 2.5 Flash, and Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages