Yeroyan commited on
Commit
044429e
·
1 Parent(s): 7715ebe

Update Project Configs

Browse files
Files changed (4) hide show
  1. LICENSE +22 -0
  2. README.md +82 -66
  3. pyproject.toml +36 -8
  4. requirements.txt +25 -0
LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ara Yeroyan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
README.md CHANGED
@@ -1,18 +1,24 @@
1
  # Visual RAG Toolkit
2
 
3
  [![PyPI version](https://badge.fury.io/py/visual-rag-toolkit.svg)](https://badge.fury.io/py/visual-rag-toolkit)
 
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
  [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
6
 
7
- End-to-end visual document retrieval toolkit featuring **two-stage tile-level pooling for scalable search**. Supports multiple vision-language models (ColSmol, ColPali, ColQwen2, etc.) with a unified interface.
 
 
 
 
 
8
 
9
  ## 🎯 Key Features
10
 
11
- - **Modular Architecture** - Use only what you need: PDF processing, embedding, indexing, or retrieval independently
12
- - **Two-Stage Retrieval** - Our novel contribution: fast pooled prefetch + exact MaxSim reranking
13
- - **Multi-Model Support** - Works with ColSmol-500M, ColPali, ColQwen2, and more
14
- - **Special Token Handling** - Proper filtering of special tokens from query embeddings
15
- - **Production Ready** - Qdrant integration, Cloudinary uploads, batch processing, GPU support
16
 
17
  ## 📦 Installation
18
 
@@ -21,65 +27,65 @@ End-to-end visual document retrieval toolkit featuring **two-stage tile-level po
21
  pip install visual-rag-toolkit
22
 
23
  # With specific features
24
- pip install visual-rag-toolkit[embedding] # ColPali model support
25
  pip install visual-rag-toolkit[pdf] # PDF processing
26
  pip install visual-rag-toolkit[qdrant] # Vector database
27
  pip install visual-rag-toolkit[cloudinary] # Image CDN
 
28
 
29
  # All dependencies
30
  pip install visual-rag-toolkit[all]
31
  ```
32
 
33
- ## 🚀 Quick Start
34
 
35
- ### Complete Pipeline
36
 
37
- ```python
38
- from visual_rag import VisualEmbedder, PDFProcessor, TwoStageRetriever
39
 
40
- # 1. Process PDFs
41
- processor = PDFProcessor(dpi=140)
42
- images, texts = processor.process_pdf("report.pdf")
43
 
44
- # 2. Generate embeddings
45
- embedder = VisualEmbedder(model_name="vidore/colSmol-500M")
46
- embeddings = embedder.embed_images(images)
47
 
48
- # 3. Search with two-stage retrieval
49
- query_emb = embedder.embed_query("What is the budget allocation?")
50
- retriever = TwoStageRetriever(qdrant_client, "my_collection")
51
- results = retriever.search(query_emb, top_k=10, prefetch_k=200)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  ```
53
 
54
- ### Use Components Independently
55
-
56
- Each component works on its own - pick what you need:
57
 
58
  ```python
59
- # Just PDF processing (no embedding, no vector DB)
60
- from visual_rag.indexing import PDFProcessor
61
- processor = PDFProcessor()
62
- images, texts = processor.process_pdf("doc.pdf")
63
-
64
- # Just embedding (bring your own images)
65
- from visual_rag.embedding import VisualEmbedder
66
- embedder = VisualEmbedder()
67
- embeddings = embedder.embed_images(my_images)
68
-
69
- # Just Qdrant indexing (bring your own embeddings)
70
- from visual_rag.indexing import QdrantIndexer
71
- indexer = QdrantIndexer(url="...", api_key="...", collection_name="my_col")
72
- indexer.upload_batch(my_points)
73
-
74
- # Just retrieval (use existing collection)
75
- from visual_rag.retrieval import TwoStageRetriever
76
- retriever = TwoStageRetriever(client, "my_col")
77
- results = retriever.search(query_embedding)
78
  ```
79
 
80
- ## 🔬 Two-Stage Retrieval (Our Novel Contribution)
81
 
82
- Traditional ColBERT/ColPali uses exhaustive MaxSim scoring which is O(N × M) where N = query tokens and M = doc tokens. This doesn't scale.
83
 
84
  **Our approach:**
85
 
@@ -95,11 +101,7 @@ Stage 2: Exact MaxSim reranking on candidates
95
  └── Return top-k results (e.g., 10)
96
  ```
97
 
98
- **Benefits:**
99
- - 🚀 **5-10x faster** than full MaxSim at scale
100
- - 🎯 **95%+ accuracy** compared to exhaustive search
101
- - 💾 **Memory efficient** - don't load all embeddings upfront
102
- - 📈 **Scalable** - works with millions of documents
103
 
104
  ## 📁 Package Structure
105
 
@@ -122,9 +124,14 @@ visual-rag-toolkit/
122
  Configure via environment variables or YAML:
123
 
124
  ```bash
125
- # Environment variables
 
 
 
 
126
  export QDRANT_URL="https://your-cluster.qdrant.io"
127
  export QDRANT_API_KEY="your-api-key"
 
128
  export VISUALRAG_MODEL="vidore/colSmol-500M"
129
 
130
  # Special token handling (default: filter them out)
@@ -148,27 +155,36 @@ search:
148
  top_k: 10
149
  ```
150
 
151
- ## 📊 Benchmark Evaluation
152
-
153
- Run ViDoRe benchmark evaluation:
154
 
155
  ```bash
156
- cd benchmarks/
 
 
157
 
158
- # Single dataset
159
- python run_vidore.py --dataset vidore/docvqa_test_subsampled
160
 
161
- # With two-stage retrieval
162
- python run_vidore.py --dataset vidore/docvqa_test_subsampled --two-stage
163
 
164
- # All datasets
165
- python run_vidore.py --all
 
 
 
 
 
 
 
 
166
  ```
167
 
 
 
 
168
  ## 🔧 Development
169
 
170
  ```bash
171
- git clone https://github.com/your-org/visual-rag-toolkit
172
  cd visual-rag-toolkit
173
  pip install -e ".[dev]"
174
  pytest tests/ -v
@@ -181,9 +197,9 @@ If you use this toolkit in your research, please cite:
181
  ```bibtex
182
  @software{visual_rag_toolkit,
183
  title = {Visual RAG Toolkit: Scalable Visual Document Retrieval with Two-Stage Pooling},
184
- author = {Your Name},
185
- year = {2024},
186
- url = {https://github.com/your-org/visual-rag-toolkit}
187
  }
188
  ```
189
 
@@ -193,7 +209,7 @@ MIT License - see [LICENSE](LICENSE) for details.
193
 
194
  ## 🙏 Acknowledgments
195
 
196
- - [ColPali](https://github.com/illuin-tech/colpali) - Visual document retrieval models
197
  - [Qdrant](https://qdrant.tech/) - Vector database with multi-vector support
 
198
  - [ViDoRe](https://huggingface.co/spaces/vidore/vidore-leaderboard) - Benchmark dataset
199
 
 
1
  # Visual RAG Toolkit
2
 
3
  [![PyPI version](https://badge.fury.io/py/visual-rag-toolkit.svg)](https://badge.fury.io/py/visual-rag-toolkit)
4
+ [![CI](https://github.com/Ara-Yeroyan/visual-rag-toolkit/actions/workflows/ci.yaml/badge.svg)](https://github.com/Ara-Yeroyan/visual-rag-toolkit/actions/workflows/ci.yaml)
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
  [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
7
 
8
+ End-to-end visual document retrieval toolkit featuring **fast multi-stage retrieval** (prefetch with pooled vectors + exact MaxSim reranking).
9
+
10
+ This repo contains:
11
+ - a **Python package** (`visual_rag`)
12
+ - a **Streamlit demo app** (`demo/`)
13
+ - **benchmark & evaluation scripts** for ViDoRe v2 (`benchmarks/`)
14
 
15
  ## 🎯 Key Features
16
 
17
+ - **Modular**: PDF → images, embedding, Qdrant indexing, retrieval can be used independently.
18
+ - **Multi-stage retrieval**: two-stage and three-stage retrieval modes built for Qdrant named vectors.
19
+ - **Model-aware embedding**: ColSmol + ColPali support behind a single `VisualEmbedder` interface.
20
+ - **Token hygiene**: query special-token filtering by default for more stable MaxSim behavior.
21
+ - **Practical pipelines**: robust indexing, retries, optional Cloudinary image URLs, evaluation reporting.
22
 
23
  ## 📦 Installation
24
 
 
27
  pip install visual-rag-toolkit
28
 
29
  # With specific features
30
+ pip install visual-rag-toolkit[embedding] # ColSmol/ColPali embedding support
31
  pip install visual-rag-toolkit[pdf] # PDF processing
32
  pip install visual-rag-toolkit[qdrant] # Vector database
33
  pip install visual-rag-toolkit[cloudinary] # Image CDN
34
+ pip install visual-rag-toolkit[ui] # Streamlit demo dependencies
35
 
36
  # All dependencies
37
  pip install visual-rag-toolkit[all]
38
  ```
39
 
40
+ ### System dependencies (PDF)
41
 
42
+ `pdf2image` requires Poppler.
43
 
44
+ - macOS: `brew install poppler`
45
+ - Ubuntu/Debian: `sudo apt-get update && sudo apt-get install -y poppler-utils`
46
 
47
+ ## 🚀 Quick Start
 
 
48
 
49
+ ### Minimal: embed a query and run two-stage search (server-side)
 
 
50
 
51
+ ```python
52
+ from qdrant_client import QdrantClient
53
+ from visual_rag import VisualEmbedder, TwoStageRetriever
54
+
55
+ client = QdrantClient(url="https://YOUR_QDRANT", api_key="YOUR_KEY")
56
+ collection_name = "your_collection"
57
+
58
+ # Embed query tokens
59
+ embedder = VisualEmbedder(model_name="vidore/colpali-v1.3")
60
+ q = embedder.embed_query("What is the budget allocation?")
61
+
62
+ # Fast path: all stages computed in Qdrant (prefetch + exact rerank)
63
+ retriever = TwoStageRetriever(client, collection_name)
64
+ results = retriever.search_server_side(
65
+ query_embedding=q,
66
+ top_k=10,
67
+ prefetch_k=256,
68
+ stage1_mode="tokens_vs_experimental", # or: tokens_vs_tiles / pooled_query_vs_tiles / pooled_query_vs_global
69
+ )
70
+
71
+ for r in results[:3]:
72
+ print(r["id"], r["score_final"])
73
  ```
74
 
75
+ ### Process a PDF into images (no embedding, no vector DB)
 
 
76
 
77
  ```python
78
+ from pathlib import Path
79
+ from visual_rag import PDFProcessor
80
+
81
+ processor = PDFProcessor(dpi=140)
82
+ images, texts = processor.process_pdf(Path("report.pdf"))
83
+ print(len(images), "pages")
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ```
85
 
86
+ ## 🔬 Multi-stage Retrieval (Two-stage / Three-stage)
87
 
88
+ Traditional ColBERT-style MaxSim scoring compares all query tokens vs all document tokens, which becomes expensive at scale.
89
 
90
  **Our approach:**
91
 
 
101
  └── Return top-k results (e.g., 10)
102
  ```
103
 
104
+ Three-stage extends this with an additional “cheap prefetch” stage before stage 2.
 
 
 
 
105
 
106
  ## 📁 Package Structure
107
 
 
124
  Configure via environment variables or YAML:
125
 
126
  ```bash
127
+ # Qdrant credentials (preferred names used by the demo + scripts)
128
+ export SIGIR_QDRANT_URL="https://your-cluster.qdrant.io"
129
+ export SIGIR_QDRANT_KEY="your-api-key"
130
+
131
+ # Backwards-compatible fallbacks (also supported)
132
  export QDRANT_URL="https://your-cluster.qdrant.io"
133
  export QDRANT_API_KEY="your-api-key"
134
+
135
  export VISUALRAG_MODEL="vidore/colSmol-500M"
136
 
137
  # Special token handling (default: filter them out)
 
155
  top_k: 10
156
  ```
157
 
158
+ ## 🖥️ Demo (Streamlit)
 
 
159
 
160
  ```bash
161
+ pip install "visual-rag-toolkit[ui,qdrant,embedding,pdf]"
162
+ streamlit run demo/app.py
163
+ ```
164
 
165
+ ## 📊 Benchmark Evaluation
 
166
 
167
+ Run ViDoRe benchmark evaluation:
 
168
 
169
+ ```bash
170
+ # Example: evaluate a collection against ViDoRe BEIR datasets in Qdrant
171
+ python -m benchmarks.vidore_beir_qdrant.run_qdrant_beir \
172
+ --datasets vidore/esg_reports_v2 vidore/biomedical_lectures_v2 \
173
+ --collection YOUR_COLLECTION \
174
+ --mode two_stage \
175
+ --stage1-mode tokens_vs_experimental \
176
+ --prefetch-k 256 \
177
+ --top-k 100 \
178
+ --evaluation-scope union
179
  ```
180
 
181
+ More commands (including multi-stage variants and cropping configs) live in:
182
+ - `benchmarks/vidore_tatdqa_test/COMMANDS.md`
183
+
184
  ## 🔧 Development
185
 
186
  ```bash
187
+ git clone https://github.com/Ara-Yeroyan/visual-rag-toolkit
188
  cd visual-rag-toolkit
189
  pip install -e ".[dev]"
190
  pytest tests/ -v
 
197
  ```bibtex
198
  @software{visual_rag_toolkit,
199
  title = {Visual RAG Toolkit: Scalable Visual Document Retrieval with Two-Stage Pooling},
200
+ author = {Ara Yeroyan},
201
+ year = {2026},
202
+ url = {https://github.com/Ara-Yeroyan/visual-rag-toolkit}
203
  }
204
  ```
205
 
 
209
 
210
  ## 🙏 Acknowledgments
211
 
 
212
  - [Qdrant](https://qdrant.tech/) - Vector database with multi-vector support
213
+ - [ColPali](https://github.com/illuin-tech/colpali) - Visual document retrieval models
214
  - [ViDoRe](https://huggingface.co/spaces/vidore/vidore-leaderboard) - Benchmark dataset
215
 
pyproject.toml CHANGED
@@ -1,5 +1,5 @@
1
  [build-system]
2
- requires = ["hatchling"]
3
  build-backend = "hatchling.build"
4
 
5
  [project]
@@ -7,7 +7,7 @@ name = "visual-rag-toolkit"
7
  version = "0.1.0"
8
  description = "End-to-end visual document retrieval with ColPali, featuring two-stage pooling for scalable search"
9
  readme = "README.md"
10
- license = {text = "MIT"}
11
  requires-python = ">=3.9"
12
  authors = [
13
  {name = "Visual RAG Team"}
@@ -77,7 +77,19 @@ ui = [
77
 
78
  # All dependencies
79
  all = [
80
- "visual-rag-toolkit[embedding,pdf,qdrant,cloudinary,ui]",
 
 
 
 
 
 
 
 
 
 
 
 
81
  ]
82
 
83
  # Development dependencies
@@ -93,13 +105,29 @@ dev = [
93
  visual-rag = "visual_rag.cli.main:main"
94
 
95
  [project.urls]
96
- Homepage = "https://github.com/your-org/visual-rag-toolkit"
97
- Documentation = "https://github.com/your-org/visual-rag-toolkit#readme"
98
- Repository = "https://github.com/your-org/visual-rag-toolkit"
99
- Issues = "https://github.com/your-org/visual-rag-toolkit/issues"
100
 
101
  [tool.hatch.build.targets.wheel]
102
- packages = ["visual_rag"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  [tool.ruff]
105
  line-length = 100
 
1
  [build-system]
2
+ requires = ["hatchling>=1.21.0"]
3
  build-backend = "hatchling.build"
4
 
5
  [project]
 
7
  version = "0.1.0"
8
  description = "End-to-end visual document retrieval with ColPali, featuring two-stage pooling for scalable search"
9
  readme = "README.md"
10
+ license = {file = "LICENSE"}
11
  requires-python = ">=3.9"
12
  authors = [
13
  {name = "Visual RAG Team"}
 
77
 
78
  # All dependencies
79
  all = [
80
+ # embedding
81
+ "colpali-engine>=0.3.0",
82
+ "transformers>=4.35.0",
83
+ # pdf
84
+ "pdf2image>=1.16.0",
85
+ "pypdf>=3.0.0",
86
+ # qdrant
87
+ "qdrant-client>=1.7.0",
88
+ # cloudinary
89
+ "cloudinary>=1.30.0",
90
+ # ui
91
+ "streamlit>=1.25.0",
92
+ "httpx>=0.24.0",
93
  ]
94
 
95
  # Development dependencies
 
105
  visual-rag = "visual_rag.cli.main:main"
106
 
107
  [project.urls]
108
+ Homepage = "https://github.com/Ara-Yeroyan/visual-rag-toolkit"
109
+ Documentation = "https://github.com/Ara-Yeroyan/visual-rag-toolkit#readme"
110
+ Repository = "https://github.com/Ara-Yeroyan/visual-rag-toolkit"
111
+ Issues = "https://github.com/Ara-Yeroyan/visual-rag-toolkit/issues"
112
 
113
  [tool.hatch.build.targets.wheel]
114
+ packages = ["visual_rag", "benchmarks"]
115
+
116
+ [tool.hatch.build.targets.sdist]
117
+ # Keep source distributions clean (no local artifacts, eval results, caches).
118
+ exclude = [
119
+ "/results",
120
+ "/checkpoints",
121
+ "/.cache",
122
+ "/.streamlit",
123
+ "/.env",
124
+ "/.env.*",
125
+ "/**/__pycache__",
126
+ "/**/*.pyc",
127
+ "/**/*.pyo",
128
+ "/**/*.pyd",
129
+ "/**/.DS_Store",
130
+ ]
131
 
132
  [tool.ruff]
133
  line-length = 100
requirements.txt ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Core dependencies
2
+ numpy>=1.21.0
3
+ Pillow>=9.0.0
4
+ tqdm>=4.60.0
5
+ pyyaml>=6.0
6
+ python-dotenv>=0.19.0
7
+
8
+ # Vector database
9
+ qdrant-client>=1.7.0
10
+
11
+ # Streamlit UI
12
+ streamlit>=1.28.0
13
+ httpx>=0.24.0
14
+
15
+ # Data processing
16
+ pandas
17
+ altair
18
+ datasets
19
+
20
+ # PDF processing
21
+ pdf2image>=1.16.0
22
+ pypdf>=3.0.0
23
+
24
+ # ColPali dependencies (torch/transformers come from base image)
25
+ peft>=0.13.0