# RAGFlow — Advanced Retrieval-Augmented Generation System
A comprehensive RAG system that transforms PDF documents into searchable knowledge bases using hybrid retrieval (semantic + keyword search), query enhancement, and intelligent reranking. Features modular architecture with multiple LLM and embedding providers.
# Clone repository
git clone https://github.com/Flowerf19/RAG.git
cd RAG
# Create virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1 # Windows
source .venv/bin/activate #linux
# Install dependencies
pip install -r requirements.txt
# Install language models
python -c "import spacy; spacy.cli.download('en_core_web_sm')"
ollama pull embeddinggemma:latest
ollama pull bge-m3:latest
# Process all PDFs in data/pdf/
python -c "from pipeline.rag_pipeline import RAGPipeline; RAGPipeline().process_directory('data/pdf')"
streamlit run ui/app.py
.venv\Scripts\Activate.ps1; streamlit run ui/dashboard/app.py
graph TD
A[PDF Documents] --> B[Document Processing]
B --> C[Text Extraction & OCR]
C --> D[Semantic Chunking]
D --> E[Vector Embeddings]
D --> F[Keyword Indexing]
G[User Query] --> H[Query Enhancement]
H --> I[Hybrid Search]
I --> J[Result Reranking]
J --> K[LLM Generation]
E --> L[(Vector DB)]
I --> L
L --> I
F --> M[(Keyword DB)]
I --> M
M --> I
K --> N[Final Answer]
style A fill:#e1f5fe
style N fill:#c8e6c9
style L fill:#fff3e0
style M fill:#fff3e0
graph TD
A[PDF Documents] --> B[PDF Processing]
B --> C[Page Content]
C --> D[Semantic Chunking]
D --> E[spaCy Segmentation]
E --> F[Coherence Analysis]
F --> G[ChunkSet]
G --> H[Embedder]
H --> I[FAISS Index]
G --> J[BM25 Index]
style A fill:#e1f5fe
style I fill:#c8e6c9
style J fill:#c8e6c9
graph TD
A[User Query] --> B[QueryProcessor]
B --> C{Enhancement?}
C -->|Yes| D[QEM Module]
C -->|No| E[Original Query]
D --> F[LLM Expansion]
F --> G[Multi-language]
G --> H[Enhanced Query]
H --> I[Embedder]
E --> I
I --> N[Query Embeddings]
H --> O[Keyword Extraction]
O --> P[BM25 Terms]
style A fill:#e1f5fe
style N fill:#fff3e0
style P fill:#fff3e0
graph TD
A[Query Embeddings] --> B[Vector Search]
B --> C[FAISS Index]
C --> D[Top-K Candidates]
E[BM25 Terms] --> F[Keyword Search]
F --> G[Whoosh Index]
G --> H[Top-K Candidates]
D --> I[Score Fusion]
H --> I
I --> J[Z-Score Normalization]
J --> K[Hybrid Results]
K --> L{Reranking?}
L -->|Yes| M[Reranker]
L -->|No| N[Final Results]
M --> S[Re-ranked Results]
S --> N
style A fill:#e1f5fe
style N fill:#c8e6c9
graph TD
A[Final Results] --> B[Context Builder]
B --> C[Chunk Aggregation]
C --> D[Metadata Enrichment]
D --> E[Context Window]
F[Enhanced Query] --> G[Prompt Builder]
G --> H[System Prompt]
H --> I[User Query]
I --> J[Final Prompt]
E --> K[LLM Client]
J --> K
K --> Q[Generated Response]
Q --> R[Source Citations]
R --> S[Confidence Scores]
S --> T[Final Answer]
style A fill:#e1f5fe
style T fill:#c8e6c9
`
RAG-2/
├── PDFLoaders/ # Advanced PDF processing with OCR
├── chunkers/ # Semantic text segmentation
├── embedders/ # Multi-provider embeddings
├── pipeline/ # Core RAG orchestration
├── query_enhancement/ # Query expansion module
├── reranking/ # Result reranking
├── BM25/ # Keyword-based search
├── llm/ # LLM provider integration
├── ui/ # Streamlit web interface
│ └── dashboard/ # Evaluation dashboard
├── evaluation/ # Model evaluation system
│ ├── metrics/ # Database and logging
│ ├── evaluators/ # Auto-evaluation functions
│ └── backend_dashboard/# Dashboard API
├── data/ # Indexes and processed data
├── config/ # Configuration files
├── prompts/ # System prompts
├── .github/ # GitHub workflows and templates
└── .streamlit/ # Streamlit configuration
The table below lists common embedding providers and models that the project supports or can be configured to use. Dimensions are approximate where noted. Cost / Performance / Security columns are qualitative and depend on deployment (local vs cloud) and model variant.
| Provider | Model (example) | Dimensions (approx.) | Multilingual | Cost | Performance | Security |
|---|---|---|---|---|---|---|
| HuggingFace (local) | BAAI/bge-m3 | 1024 | ✅ | Low | High | Local (best) |
| HuggingFace (API) | multilingual-e5-large | 1024 | ✅ | Medium | High | Cloud (depends on HF) |
| Ollama (local) | embeddinggemma | 768 | ✅ | Low | Medium | Local (best) |
| Ollama (local) | bge-m3 | 1024 | ✅ | Low | High | Local (best) |
| OpenAI (cloud) | text-embedding-3-* | 1536 | ✅ | High | High | Cloud (managed) |
| Cohere (cloud) | multilingual models | 1536 | ✅ | Medium | High | Cloud (managed) |
| Jina AI (cloud/local) | jina-v2-multilingual | 1024 | ✅ | Medium | High | Cloud / Self-host |
| Google / GTE (cloud) | gte-multilingual | 1024 | ✅ | High | High | Cloud (managed) |
| Sentence-Transformers | all-MiniLM-L6-v2 | 384 | ✅ | Free | Medium | Local/Cloud |
| Lightweight (edge) | bge-base / small | ~256-512 | ✅ | Low | Low-Med | Local (edge) |
Notes:
Local (best) means data stays on-prem; Cloud (managed) means data sent to third-party API — consider privacy/compliance impacts.The following table summarizes common reranking options used after initial retrieval. Columns are qualitative; actual cost and latency depend on model size and whether you run locally or via cloud APIs.
| Provider | Model (example) | Cost | Performance | Latency | Security | Notes |
|---|---|---|---|---|---|---|
| HuggingFace (local) | BAAI/bge-reranker-v2-m3 | Low | High | Medium | Local (best) | Strong accuracy for semantic re-ranking when run locally on GPU/CPU. |
| Jina | jina-reranker-v2-base-multilingual | Medium | High | Low-Med | Cloud/Self-host | Good multilingual reranking; can be self-hosted for privacy. |
| Cohere (cloud) | cohere-rerank | Medium | High | Low | Cloud (managed) | Low latency cloud API; consider data policies. |
| OpenAI (cloud) | text-davinci / specialized | High | High | Low | Cloud (managed) | High quality but cost and privacy concerns for sensitive data. |
| Google (GTE) | gte-reranker | High | High | Low | Cloud (managed) | Strong performance for multilingual reranking via cloud. |
| Sentence-Transformers (local) | cross-encoder/ms-marco-MiniLM-L-6-v2 | Low | Medium-High | Medium | Local/Cloud | Lightweight cross-encoders good for small-scale reranking. |
| Lightweight heuristic | TF-IDF / lexical scoring | Free | Low-Med | Very Low | Local (best) | Fast baseline reranker; useful when compute is limited. |
Notes:
Key libraries used by this project (grouped by purpose).
| Package | Purpose |
|---|---|
streamlit | Web UI / dashboard |
pandas | Data manipulation |
numpy | Numeric operations |
requests | HTTP requests |
openpyxl | Excel reading/writing |
rich | Console formatting/logging |
ftfy | Text fixing (encoding cleanup) |
faiss-cpu | Vector index / similarity search (FAISS) |
whoosh | BM25 / lexical indexing |
spacy | NLP tokenization / segmentation |
transformers | Model loading / HuggingFace models |
torch | Model runtime (PyTorch) |
sentence-transformers | Off-the-shelf embedding models |
PyMuPDF / pymupdf | PDF parsing / page extraction |
pdfplumber | PDF table extraction |
pymupdf4llm | PDF helper utilities (project-specific) |
paddlepaddle | OCR backend (PaddleOCR) |
doclayout_yolo | Layout detection for document regions |
langchain | Orchestration, LLM adapters |
langchain-community | Extra community connectors |
langchain-google-genai | Gemini / Google GenAI wrapper |
langchain-ollama | Ollama integration |
langchain-openai | OpenAI integration |
langchain-text-splitters | Text chunking helpers |
openai | OpenAI API client |
google.generativeai | Google Gemini client |
pip-system-certs | Use system certs for HTTPS |
ragas | RAG evaluation framework (used in evaluation/) |
datasets | HuggingFace datasets (evaluation) |
matplotlib, seaborn, plotly | Visualizations / charts |
scikit-learn | ML utilities and metrics |
If you want, I can (a) add a short note about which packages are optional (e.g., Ollama/Gemini/OpenAI wrappers), or (b) create a minimal requirements-core.txt for a lightweight install.
# HuggingFace API (optional)
export HF_TOKEN="your_token_here"
# Google Gemini (optional)
export GOOGLE_API_KEY="your_key_here"
# OpenAI (optional)
export OPENAI_API_KEY="your_key_here"
For full functionality, you'll need to set up API keys for various services:
Copy the secrets template:
cp .streamlit/secrets.example .streamlit/secret.toml
Edit the secrets file with your actual API keys:
# HuggingFace API Token (required for E5-Large Multilingual embeddings via HF API)
HF_TOKEN = "hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Google Gemini API Key (required for Gemini LLM inference)
gemini_api_key = "AIzaSyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Environment Variables (alternative to secrets.toml):
export GOOGLE_API_KEY="your_gemini_key"
export HF_TOKEN="your_huggingface_token"
⚠️ Security Note: Never commit actual API keys to version control. The .streamlit/secret.toml file is already in .gitignore.
git clone https://github.com/Flowerf19/RAG.git
cd RAG
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
MIT License - see LICENSE file for details.
Built with FAISS, Ollama, spaCy, Whoosh, Streamlit, PaddleOCR, and HuggingFace Transformers.
RAGFlow Transforming documents into conversational knowledge bases.
156 commits
29 commits
Python
99.4%
# RAGFlow — Advanced Retrieval-Augmented Generation System
A comprehensive RAG system that transforms PDF documents into searchable knowledge bases using hybrid retrieval (semantic + keyword search), query enhancement, and intelligent reranking. Features modular architecture with multiple LLM and embedding providers.
# Clone repository
git clone https://github.com/Flowerf19/RAG.git
cd RAG
# Create virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1 # Windows
source .venv/bin/activate #linux
# Install dependencies
pip install -r requirements.txt
# Install language models
python -c "import spacy; spacy.cli.download('en_core_web_sm')"
ollama pull embeddinggemma:latest
ollama pull bge-m3:latest
# Process all PDFs in data/pdf/
python -c "from pipeline.rag_pipeline import RAGPipeline; RAGPipeline().process_directory('data/pdf')"
streamlit run ui/app.py
.venv\Scripts\Activate.ps1; streamlit run ui/dashboard/app.py
graph TD
A[PDF Documents] --> B[Document Processing]
B --> C[Text Extraction & OCR]
C --> D[Semantic Chunking]
D --> E[Vector Embeddings]
D --> F[Keyword Indexing]
G[User Query] --> H[Query Enhancement]
H --> I[Hybrid Search]
I --> J[Result Reranking]
J --> K[LLM Generation]
E --> L[(Vector DB)]
I --> L
L --> I
F --> M[(Keyword DB)]
I --> M
M --> I
K --> N[Final Answer]
style A fill:#e1f5fe
style N fill:#c8e6c9
style L fill:#fff3e0
style M fill:#fff3e0
graph TD
A[PDF Documents] --> B[PDF Processing]
B --> C[Page Content]
C --> D[Semantic Chunking]
D --> E[spaCy Segmentation]
E --> F[Coherence Analysis]
F --> G[ChunkSet]
G --> H[Embedder]
H --> I[FAISS Index]
G --> J[BM25 Index]
style A fill:#e1f5fe
style I fill:#c8e6c9
style J fill:#c8e6c9
graph TD
A[User Query] --> B[QueryProcessor]
B --> C{Enhancement?}
C -->|Yes| D[QEM Module]
C -->|No| E[Original Query]
D --> F[LLM Expansion]
F --> G[Multi-language]
G --> H[Enhanced Query]
H --> I[Embedder]
E --> I
I --> N[Query Embeddings]
H --> O[Keyword Extraction]
O --> P[BM25 Terms]
style A fill:#e1f5fe
style N fill:#fff3e0
style P fill:#fff3e0
graph TD
A[Query Embeddings] --> B[Vector Search]
B --> C[FAISS Index]
C --> D[Top-K Candidates]
E[BM25 Terms] --> F[Keyword Search]
F --> G[Whoosh Index]
G --> H[Top-K Candidates]
D --> I[Score Fusion]
H --> I
I --> J[Z-Score Normalization]
J --> K[Hybrid Results]
K --> L{Reranking?}
L -->|Yes| M[Reranker]
L -->|No| N[Final Results]
M --> S[Re-ranked Results]
S --> N
style A fill:#e1f5fe
style N fill:#c8e6c9
graph TD
A[Final Results] --> B[Context Builder]
B --> C[Chunk Aggregation]
C --> D[Metadata Enrichment]
D --> E[Context Window]
F[Enhanced Query] --> G[Prompt Builder]
G --> H[System Prompt]
H --> I[User Query]
I --> J[Final Prompt]
E --> K[LLM Client]
J --> K
K --> Q[Generated Response]
Q --> R[Source Citations]
R --> S[Confidence Scores]
S --> T[Final Answer]
style A fill:#e1f5fe
style T fill:#c8e6c9
`
RAG-2/
├── PDFLoaders/ # Advanced PDF processing with OCR
├── chunkers/ # Semantic text segmentation
├── embedders/ # Multi-provider embeddings
├── pipeline/ # Core RAG orchestration
├── query_enhancement/ # Query expansion module
├── reranking/ # Result reranking
├── BM25/ # Keyword-based search
├── llm/ # LLM provider integration
├── ui/ # Streamlit web interface
│ └── dashboard/ # Evaluation dashboard
├── evaluation/ # Model evaluation system
│ ├── metrics/ # Database and logging
│ ├── evaluators/ # Auto-evaluation functions
│ └── backend_dashboard/# Dashboard API
├── data/ # Indexes and processed data
├── config/ # Configuration files
├── prompts/ # System prompts
├── .github/ # GitHub workflows and templates
└── .streamlit/ # Streamlit configuration
The table below lists common embedding providers and models that the project supports or can be configured to use. Dimensions are approximate where noted. Cost / Performance / Security columns are qualitative and depend on deployment (local vs cloud) and model variant.
| Provider | Model (example) | Dimensions (approx.) | Multilingual | Cost | Performance | Security |
|---|---|---|---|---|---|---|
| HuggingFace (local) | BAAI/bge-m3 | 1024 | ✅ | Low | High | Local (best) |
| HuggingFace (API) | multilingual-e5-large | 1024 | ✅ | Medium | High | Cloud (depends on HF) |
| Ollama (local) | embeddinggemma | 768 | ✅ | Low | Medium | Local (best) |
| Ollama (local) | bge-m3 | 1024 | ✅ | Low | High | Local (best) |
| OpenAI (cloud) | text-embedding-3-* | 1536 | ✅ | High | High | Cloud (managed) |
| Cohere (cloud) | multilingual models | 1536 | ✅ | Medium | High | Cloud (managed) |
| Jina AI (cloud/local) | jina-v2-multilingual | 1024 | ✅ | Medium | High | Cloud / Self-host |
| Google / GTE (cloud) | gte-multilingual | 1024 | ✅ | High | High | Cloud (managed) |
| Sentence-Transformers | all-MiniLM-L6-v2 | 384 | ✅ | Free | Medium | Local/Cloud |
| Lightweight (edge) | bge-base / small | ~256-512 | ✅ | Low | Low-Med | Local (edge) |
Notes:
Local (best) means data stays on-prem; Cloud (managed) means data sent to third-party API — consider privacy/compliance impacts.The following table summarizes common reranking options used after initial retrieval. Columns are qualitative; actual cost and latency depend on model size and whether you run locally or via cloud APIs.
| Provider | Model (example) | Cost | Performance | Latency | Security | Notes |
|---|---|---|---|---|---|---|
| HuggingFace (local) | BAAI/bge-reranker-v2-m3 | Low | High | Medium | Local (best) | Strong accuracy for semantic re-ranking when run locally on GPU/CPU. |
| Jina | jina-reranker-v2-base-multilingual | Medium | High | Low-Med | Cloud/Self-host | Good multilingual reranking; can be self-hosted for privacy. |
| Cohere (cloud) | cohere-rerank | Medium | High | Low | Cloud (managed) | Low latency cloud API; consider data policies. |
| OpenAI (cloud) | text-davinci / specialized | High | High | Low | Cloud (managed) | High quality but cost and privacy concerns for sensitive data. |
| Google (GTE) | gte-reranker | High | High | Low | Cloud (managed) | Strong performance for multilingual reranking via cloud. |
| Sentence-Transformers (local) | cross-encoder/ms-marco-MiniLM-L-6-v2 | Low | Medium-High | Medium | Local/Cloud | Lightweight cross-encoders good for small-scale reranking. |
| Lightweight heuristic | TF-IDF / lexical scoring | Free | Low-Med | Very Low | Local (best) | Fast baseline reranker; useful when compute is limited. |
Notes:
Key libraries used by this project (grouped by purpose).
| Package | Purpose |
|---|---|
streamlit | Web UI / dashboard |
pandas | Data manipulation |
numpy | Numeric operations |
requests | HTTP requests |
openpyxl | Excel reading/writing |
rich | Console formatting/logging |
ftfy | Text fixing (encoding cleanup) |
faiss-cpu | Vector index / similarity search (FAISS) |
whoosh | BM25 / lexical indexing |
spacy | NLP tokenization / segmentation |
transformers | Model loading / HuggingFace models |
torch | Model runtime (PyTorch) |
sentence-transformers | Off-the-shelf embedding models |
PyMuPDF / pymupdf | PDF parsing / page extraction |
pdfplumber | PDF table extraction |
pymupdf4llm | PDF helper utilities (project-specific) |
paddlepaddle | OCR backend (PaddleOCR) |
doclayout_yolo | Layout detection for document regions |
langchain | Orchestration, LLM adapters |
langchain-community | Extra community connectors |
langchain-google-genai | Gemini / Google GenAI wrapper |
langchain-ollama | Ollama integration |
langchain-openai | OpenAI integration |
langchain-text-splitters | Text chunking helpers |
openai | OpenAI API client |
google.generativeai | Google Gemini client |
pip-system-certs | Use system certs for HTTPS |
ragas | RAG evaluation framework (used in evaluation/) |
datasets | HuggingFace datasets (evaluation) |
matplotlib, seaborn, plotly | Visualizations / charts |
scikit-learn | ML utilities and metrics |
If you want, I can (a) add a short note about which packages are optional (e.g., Ollama/Gemini/OpenAI wrappers), or (b) create a minimal requirements-core.txt for a lightweight install.
# HuggingFace API (optional)
export HF_TOKEN="your_token_here"
# Google Gemini (optional)
export GOOGLE_API_KEY="your_key_here"
# OpenAI (optional)
export OPENAI_API_KEY="your_key_here"
For full functionality, you'll need to set up API keys for various services:
Copy the secrets template:
cp .streamlit/secrets.example .streamlit/secret.toml
Edit the secrets file with your actual API keys:
# HuggingFace API Token (required for E5-Large Multilingual embeddings via HF API)
HF_TOKEN = "hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Google Gemini API Key (required for Gemini LLM inference)
gemini_api_key = "AIzaSyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Environment Variables (alternative to secrets.toml):
export GOOGLE_API_KEY="your_gemini_key"
export HF_TOKEN="your_huggingface_token"
⚠️ Security Note: Never commit actual API keys to version control. The .streamlit/secret.toml file is already in .gitignore.
git clone https://github.com/Flowerf19/RAG.git
cd RAG
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
MIT License - see LICENSE file for details.
Built with FAISS, Ollama, spaCy, Whoosh, Streamlit, PaddleOCR, and HuggingFace Transformers.
RAGFlow Transforming documents into conversational knowledge bases.
156 commits
29 commits
Python
99.4%