flashrag-dev 0.1.4.dev20250104__tar.gz → 0.1.4.dev20250107__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/PKG-INFO +147 -83
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/README.md +145 -82
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/config/basic_config.yaml +40 -21
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/config/config.py +91 -35
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/dataset/__init__.py +0 -1
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/dataset/dataset.py +29 -22
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/dataset/utils.py +47 -14
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/evaluator/evaluator.py +1 -2
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/evaluator/metrics.py +37 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/evaluator/utils.py +1 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/generator/__init__.py +1 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/generator/generator.py +67 -44
- flashrag_dev-0.1.4.dev20250107/flashrag/generator/multimodal_generator.py +456 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/generator/openai_generator.py +28 -8
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/generator/utils.py +41 -1
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/pipeline/__init__.py +1 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/pipeline/active_pipeline.py +36 -15
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/pipeline/branching_pipeline.py +15 -9
- flashrag_dev-0.1.4.dev20250107/flashrag/pipeline/mm_pipeline.py +95 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/pipeline/pipeline.py +17 -9
- flashrag_dev-0.1.4.dev20250107/flashrag/prompt/__init__.py +2 -0
- flashrag_dev-0.1.4.dev20250107/flashrag/prompt/mm_prompt.py +87 -0
- flashrag_dev-0.1.4.dev20250107/flashrag/retriever/encoder.py +251 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/retriever/index_builder.py +148 -95
- flashrag_dev-0.1.4.dev20250107/flashrag/retriever/retriever.py +868 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/retriever/utils.py +59 -22
- flashrag_dev-0.1.4.dev20250107/flashrag/utils/pred_parse.py +84 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/utils/utils.py +51 -17
- flashrag_dev-0.1.4.dev20250107/flashrag/version.py +1 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag_dev.egg-info/PKG-INFO +147 -83
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag_dev.egg-info/SOURCES.txt +3 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag_dev.egg-info/requires.txt +13 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/setup.py +2 -1
- flashrag_dev-0.1.4.dev20250104/flashrag/prompt/__init__.py +0 -1
- flashrag_dev-0.1.4.dev20250104/flashrag/retriever/encoder.py +0 -118
- flashrag_dev-0.1.4.dev20250104/flashrag/retriever/retriever.py +0 -359
- flashrag_dev-0.1.4.dev20250104/flashrag/utils/pred_parse.py +0 -25
- flashrag_dev-0.1.4.dev20250104/flashrag/version.py +0 -1
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/LICENSE +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/config/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/evaluator/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/evaluator/_bleu.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/generator/fid.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/generator/stop_word_criteria.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/judger/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/judger/judger.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/pipeline/replug_utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/prompt/base_prompt.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/prompt/selfask_examplars.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/prompt/trace_examplars.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/refiner/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/refiner/kg_refiner.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/refiner/llmlingua_compressor.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/refiner/refiner.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/refiner/selective_context_compressor.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/retriever/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/retriever/__main__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/retriever/reranker.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/utils/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag/utils/constants.py +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag_dev.egg-info/dependency_links.txt +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/flashrag_dev.egg-info/top_level.txt +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/pyproject.toml +0 -0
- {flashrag_dev-0.1.4.dev20250104 → flashrag_dev-0.1.4.dev20250107}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: flashrag_dev
|
|
3
|
-
Version: 0.1.4.
|
|
3
|
+
Version: 0.1.4.dev20250107
|
|
4
4
|
Summary: A library for efficient Retrieval-Augmented Generation research
|
|
5
5
|
Home-page: https://github.com/RUC-NLPIR/FlashRAG
|
|
6
6
|
Author: Jiajie Jin, Yutao Zhu, Chenghao Zhang, Xinyu Yang, Zhicheng Dou
|
|
@@ -11,12 +11,12 @@ Description-Content-Type: text/markdown
|
|
|
11
11
|
Provides-Extra: core
|
|
12
12
|
Provides-Extra: retriever
|
|
13
13
|
Provides-Extra: generator
|
|
14
|
+
Provides-Extra: multimodal
|
|
14
15
|
Provides-Extra: full
|
|
15
16
|
License-File: LICENSE
|
|
16
17
|
|
|
17
18
|
# <div align="center">⚡FlashRAG: A Python Toolkit for Efficient RAG Research<div>
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
\[ English | [中文](README_zh.md) \]
|
|
20
20
|
<div align="center">
|
|
21
21
|
<a href="https://arxiv.org/abs/2405.13576" target="_blank"><img src=https://img.shields.io/badge/arXiv-b5212f.svg?logo=arxiv></a>
|
|
22
22
|
<a href="https://huggingface.co/datasets/RUC-NLPIR/FlashRAG_datasets/" target="_blank"><img src=https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace%20Datasets-27b3b4.svg></a>
|
|
@@ -30,25 +30,38 @@ License-File: LICENSE
|
|
|
30
30
|
<p>
|
|
31
31
|
<a href="#wrench-installation">Installation</a> |
|
|
32
32
|
<a href="#sparkles-features">Features</a> |
|
|
33
|
-
<a href="#
|
|
33
|
+
<a href="#rocket-quick-start">Quick-Start</a> |
|
|
34
34
|
<a href="#gear-components"> Components</a> |
|
|
35
35
|
<a href="#robot-supporting-methods"> Supporting Methods</a> |
|
|
36
|
-
<a href="#notebook-supporting-datasets"> Supporting Datasets</a> |
|
|
36
|
+
<a href="#notebook-supporting-datasets--document-corpus"> Supporting Datasets</a> |
|
|
37
37
|
<a href="#raised_hands-additional-faqs"> FAQs</a>
|
|
38
38
|
</p>
|
|
39
39
|
|
|
40
40
|
</h4>
|
|
41
|
-
FlashRAG is a Python toolkit for the reproduction and development of Retrieval Augmented Generation (RAG) research. Our toolkit includes 36 pre-processed benchmark RAG datasets and 15 state-of-the-art RAG algorithms.
|
|
41
|
+
FlashRAG is a Python toolkit for the reproduction and development of Retrieval Augmented Generation (RAG) research. Our toolkit includes 36 pre-processed benchmark RAG datasets and 15 state-of-the-art RAG algorithms.
|
|
42
42
|
|
|
43
43
|
<p align="center">
|
|
44
44
|
<img src="asset/framework.jpg">
|
|
45
45
|
</p>
|
|
46
46
|
|
|
47
47
|
With FlashRAG and provided resources, you can effortlessly reproduce existing SOTA works in the RAG domain or implement your custom RAG processes and components.
|
|
48
|
+
|
|
48
49
|
<p>
|
|
49
50
|
<a href="https://trendshift.io/repositories/10454" target="_blank"><img src="https://trendshift.io/api/badge/repositories/10454" alt="RUC-NLPIR%2FFlashRAG | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
|
50
51
|
</p>
|
|
51
52
|
|
|
53
|
+
## :link: Navigation
|
|
54
|
+
- [Features](#sparkles-features)
|
|
55
|
+
- [Roadmap](#mag_right-roadmap)
|
|
56
|
+
- [Changelog](#page_with_curl-changelog)
|
|
57
|
+
- [Installation](#wrench-installation)
|
|
58
|
+
- [Quick Start](#rocket-quick-start)
|
|
59
|
+
- [Components](#gear-components)
|
|
60
|
+
- [Supporting Methods](#robot-supporting-methods)
|
|
61
|
+
- [Supporting Datasets & Document Corpus](#notebook-supporting-datasets--document-corpus)
|
|
62
|
+
- [Additional FAQs](#raised_hands-additional-faqs)
|
|
63
|
+
- [License](#bookmark-license)
|
|
64
|
+
- [Citation](#star2-citation)
|
|
52
65
|
|
|
53
66
|
## :sparkles: Features
|
|
54
67
|
|
|
@@ -62,6 +75,8 @@ With FlashRAG and provided resources, you can effortlessly reproduce existing SO
|
|
|
62
75
|
|
|
63
76
|
- **Optimized Execution**: The library's efficiency is enhanced with tools like vLLM, FastChat for LLM inference acceleration, and Faiss for vector index management.
|
|
64
77
|
|
|
78
|
+
- **Easy to Use UI** : We have developed a very easy to use UI to easily and quickly configure and experience the RAG baselines we have implemented, as well as run evaluation scripts on a visual interface.
|
|
79
|
+
|
|
65
80
|
## :mag_right: Roadmap
|
|
66
81
|
|
|
67
82
|
FlashRAG is still under development and there are many issues and room for improvement. We will continue to update. And we also sincerely welcome contributions on this open-source toolkit.
|
|
@@ -73,8 +88,12 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
73
88
|
- [ ] Add more evaluation metrics (e.g., Unieval, name-entity F1) and benchmarks (e.g., RGB benchmark)
|
|
74
89
|
- [ ] Enhance code adaptability and readability
|
|
75
90
|
|
|
76
|
-
|
|
77
91
|
## :page_with_curl: Changelog
|
|
92
|
+
|
|
93
|
+
[25/01/07] We have currently support the aggregation of multiple retrievers, see it in [**multi retriever usage**](https://github.com/RUC-NLPIR/FlashRAG/blob/main/docs/multi_retriever_usage.md).
|
|
94
|
+
|
|
95
|
+
[25/01/07] We have integrated a very flexible and lightweight corpus chunking library [**Chunkie**](https://github.com/chonkie-ai/chonkie?tab=readme-ov-file#usage), which supports various custom chunking methods (tokens, sentences, semantic, etc.). Use it in [<u>chunking doc corpus</u>](docs/chunk-doc-corpus.md).
|
|
96
|
+
|
|
78
97
|
[24/10/21] We have released a version based on the Paddle framework that supports Chinese hardware platforms. Please refer to [FlashRAG Paddle](https://github.com/RUC-NLPIR/FlashRAG-Paddle) for details.
|
|
79
98
|
|
|
80
99
|
[24/10/13] A new in-domain dataset and corpus - [DomainRAG](https://arxiv.org/pdf/2406.05654) have been added to the dataset. The dataset is based on the internal enrollment data of Renmin University of China, covering seven types of tasks, which can be used for conducting domain-specific RAG testing.
|
|
@@ -87,13 +106,13 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
87
106
|
|
|
88
107
|
[24/08/02] We add support for a new method [<u>Spring</u>](https://arxiv.org/abs/2405.19670), significantly improve the performance of LLM by adding only a few token embeddings. See it result in [<u>result table</u>](#robot-supporting-methods).
|
|
89
108
|
|
|
109
|
+
<details>
|
|
110
|
+
<summary>Show more</summary>
|
|
111
|
+
|
|
90
112
|
[24/07/17] Due to some unknown issues with HuggingFace, our original dataset link has been invalid. We have updated it. Please check the [new link](https://huggingface.co/datasets/RUC-NLPIR/FlashRAG_datasets/) if you encounter any problems.
|
|
91
113
|
|
|
92
114
|
[24/07/06] We add support for a new method: [<u>Trace</u>](https://arxiv.org/abs/2406.11460), which refine text by constructing a knowledge graph. See it [<u>results</u>](#robot-supporting-methods) and [<u>details</u>](./docs/baseline_details.md).
|
|
93
115
|
|
|
94
|
-
<details>
|
|
95
|
-
<summary>Show more</summary>
|
|
96
|
-
|
|
97
116
|
[24/06/19] We add support for a new method: [<u>IRCoT</u>](https://arxiv.org/abs/2212.10509), and update the [<u>result table</u>](#robot-supporting-methods).
|
|
98
117
|
|
|
99
118
|
[24/06/15] We provide a [<u>demo</u>](./examples/quick_start/demo_en.py) to perform the RAG process using our toolkit.
|
|
@@ -108,15 +127,15 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
108
127
|
|
|
109
128
|
</details>
|
|
110
129
|
|
|
111
|
-
|
|
112
|
-
## :wrench: Installation
|
|
130
|
+
## :wrench: Installation
|
|
113
131
|
|
|
114
132
|
To get started with FlashRAG, you can simply install it with pip:
|
|
133
|
+
|
|
115
134
|
```base
|
|
116
135
|
pip install flashrag-dev --pre
|
|
117
136
|
```
|
|
118
137
|
|
|
119
|
-
Or you can clone it from Github and install (requires Python 3.
|
|
138
|
+
Or you can clone it from Github and install (requires Python 3.10+):
|
|
120
139
|
|
|
121
140
|
```bash
|
|
122
141
|
git clone https://github.com/RUC-NLPIR/FlashRAG.git
|
|
@@ -125,6 +144,7 @@ pip install -e .
|
|
|
125
144
|
```
|
|
126
145
|
|
|
127
146
|
If you want to use vllm, sentence-transformers or pyserini, you can install the optional dependencies:
|
|
147
|
+
|
|
128
148
|
```bash
|
|
129
149
|
# Install all extra dependencies
|
|
130
150
|
pip install flashrag[full]
|
|
@@ -140,6 +160,7 @@ pip install pyserini
|
|
|
140
160
|
```
|
|
141
161
|
|
|
142
162
|
Due to the incompatibility when installing `faiss` using `pip`, it is necessary to use the following conda command for installation.
|
|
163
|
+
|
|
143
164
|
```bash
|
|
144
165
|
# CPU-only version
|
|
145
166
|
conda install -c pytorch faiss-cpu=1.8.0
|
|
@@ -157,68 +178,106 @@ From the official Faiss repository ([source](https://github.com/facebookresearch
|
|
|
157
178
|
|
|
158
179
|
## :rocket: Quick Start
|
|
159
180
|
|
|
181
|
+
### Corpus Construction
|
|
182
|
+
To build an index, you first need to save your corpus as a `jsonl` file with each line representing a document.
|
|
160
183
|
|
|
161
|
-
|
|
184
|
+
```jsonl
|
|
185
|
+
{"id": "0", "contents": "content"}
|
|
186
|
+
{"id": "1", "contents": "content"}
|
|
187
|
+
...
|
|
188
|
+
```
|
|
162
189
|
|
|
163
|
-
|
|
190
|
+
If you want to use Wikipedia as your corpus, you can refer to our documentation [Processing Wikipedia](./docs/process-wiki.md) to convert it into an indexable format.
|
|
164
191
|
|
|
165
|
-
|
|
192
|
+
### Index Construction
|
|
166
193
|
|
|
167
|
-
|
|
194
|
+
You can use the following code to build your own index.
|
|
168
195
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
196
|
+
* For **dense retrieval methods**, especially popular embedding models, we use `faiss` to build the index.
|
|
197
|
+
|
|
198
|
+
* For **sparse retrieval methods (BM25)**, we use `Pyserini` or `bm25s` to build the corpus into a Lucene inverted index. The built index contains the original documents.
|
|
199
|
+
|
|
200
|
+
#### For Dense Retrieval Methods
|
|
174
201
|
|
|
175
|
-
|
|
202
|
+
Modify the parameters in the following code to your own.
|
|
176
203
|
|
|
177
204
|
```bash
|
|
178
|
-
|
|
205
|
+
python -m flashrag.retriever.index_builder \
|
|
206
|
+
--retrieval_method e5 \
|
|
207
|
+
--model_path /model/e5-base-v2/ \
|
|
208
|
+
--corpus_path indexes/sample_corpus.jsonl \
|
|
209
|
+
--save_dir indexes/ \
|
|
210
|
+
--use_fp16 \
|
|
211
|
+
--max_length 512 \
|
|
212
|
+
--batch_size 256 \
|
|
213
|
+
--pooling_method mean \
|
|
214
|
+
--faiss_type Flat
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
* ```--pooling_method```: If this parameter is not specified, we will automatically select it based on the model name and model file. However, since different embedding models use different pooling methods, **we may not have fully implemented them**. To ensure accuracy, you can **specify the pooling method corresponding to the retrieval model you are using** (`mean`, `pooler`, or `cls`).
|
|
179
218
|
|
|
180
|
-
|
|
181
|
-
cp ../methods/my_config.yaml .
|
|
219
|
+
* ```---instruction```: Some embedding models require additional instructions to be concatenated to the query before encoding, which can be specified here. Currently, we will automatically fill in the instructions for **E5** and **BGE** models, while other models need to be supplemented manually.
|
|
182
220
|
|
|
183
|
-
|
|
184
|
-
streamlit run demo_en.py
|
|
221
|
+
If the retrieval model supports the `sentence transformers` library, you can use the following code to build the index (**without considering the pooling method**).
|
|
185
222
|
|
|
186
|
-
|
|
187
|
-
|
|
223
|
+
```bash
|
|
224
|
+
python -m flashrag.retriever.index_builder \
|
|
225
|
+
--retrieval_method e5 \
|
|
226
|
+
--model_path /model/e5-base-v2/ \
|
|
227
|
+
--corpus_path indexes/sample_corpus.jsonl \
|
|
228
|
+
--save_dir indexes/ \
|
|
229
|
+
--use_fp16 \
|
|
230
|
+
--max_length 512 \
|
|
231
|
+
--batch_size 256 \
|
|
232
|
+
--pooling_method mean \
|
|
233
|
+
--sentence_transformer \
|
|
234
|
+
--faiss_type Flat
|
|
188
235
|
```
|
|
189
236
|
|
|
237
|
+
#### For Sparse Retrieval Methods (BM25)
|
|
190
238
|
|
|
191
|
-
|
|
239
|
+
If building a bm25 index, there is no need to specify `model_path`.
|
|
192
240
|
|
|
193
|
-
|
|
194
|
-
Run the following code to implement a naive RAG pipeline using provided toy datasets.
|
|
195
|
-
The default retriever is `e5-base-v2` and default generator is `Llama3-8B-instruct`. You need to fill in the corresponding model path in the following command. If you wish to use other models, please refer to the detailed instructions below.
|
|
241
|
+
##### Building Index with BM25s
|
|
196
242
|
|
|
197
243
|
```bash
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
244
|
+
python -m flashrag.retriever.index_builder \
|
|
245
|
+
--retrieval_method bm25 \
|
|
246
|
+
--corpus_path indexes/sample_corpus.jsonl \
|
|
247
|
+
--bm25_backend bm25s \
|
|
248
|
+
--save_dir indexes/
|
|
202
249
|
```
|
|
203
250
|
|
|
204
|
-
|
|
251
|
+
##### Building Index with Pyserini
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
python -m flashrag.retriever.index_builder \
|
|
255
|
+
--retrieval_method bm25 \
|
|
256
|
+
--corpus_path indexes/sample_corpus.jsonl \
|
|
257
|
+
--bm25_backend pyserini \
|
|
258
|
+
--save_dir indexes/
|
|
259
|
+
```
|
|
205
260
|
|
|
206
261
|
### Using the ready-made pipeline
|
|
207
262
|
|
|
208
263
|
You can use the pipeline class we have already built (as shown in [<u>pipelines</u>](#pipelines)) to implement the RAG process inside. In this case, you just need to configure the config and load the corresponding pipeline.
|
|
209
264
|
|
|
210
|
-
Firstly, load the entire process's config, which records various hyperparameters required in the RAG process. You can input yaml files as parameters or directly as variables.
|
|
265
|
+
Firstly, load the entire process's config, which records various hyperparameters required in the RAG process. You can input yaml files as parameters or directly as variables.
|
|
266
|
+
|
|
267
|
+
Please note that **variables as input take precedence over files**.
|
|
211
268
|
|
|
212
269
|
```python
|
|
213
270
|
from flashrag.config import Config
|
|
214
271
|
|
|
272
|
+
# hybrid load configs
|
|
215
273
|
config_dict = {'data_dir': 'dataset/'}
|
|
216
|
-
my_config = Config(
|
|
217
|
-
|
|
274
|
+
my_config = Config(
|
|
275
|
+
config_file_path = 'my_config.yaml',
|
|
276
|
+
config_dict = config_dict
|
|
218
277
|
```
|
|
219
278
|
|
|
220
279
|
We provide comprehensive guidance on how to set configurations, you can see our [<u>configuration guidance</u>](./docs/configuration.md).
|
|
221
|
-
You can also refer to the [<u>basic yaml file</u>](./flashrag/config/basic_config.yaml) we provide to set your own parameters.
|
|
280
|
+
You can also refer to the [<u>basic yaml file</u>](./flashrag/config/basic_config.yaml) we provide to set your own parameters.
|
|
222
281
|
|
|
223
282
|
Next, load the corresponding dataset and initialize the pipeline. The components in the pipeline will be automatically loaded.
|
|
224
283
|
|
|
@@ -229,8 +288,10 @@ from flashrag.prompt import PromptTemplate
|
|
|
229
288
|
from flashrag.config import Config
|
|
230
289
|
|
|
231
290
|
config_dict = {'data_dir': 'dataset/'}
|
|
232
|
-
my_config = Config(
|
|
233
|
-
|
|
291
|
+
my_config = Config(
|
|
292
|
+
config_file_path = 'my_config.yaml',
|
|
293
|
+
config_dict = config_dict
|
|
294
|
+
)
|
|
234
295
|
all_split = get_dataset(my_config)
|
|
235
296
|
test_data = all_split['test']
|
|
236
297
|
|
|
@@ -238,13 +299,17 @@ pipeline = SequentialPipeline(my_config)
|
|
|
238
299
|
```
|
|
239
300
|
|
|
240
301
|
You can specify your own input prompt using `PromptTemplete`:
|
|
302
|
+
|
|
241
303
|
```python
|
|
242
304
|
prompt_templete = PromptTemplate(
|
|
243
|
-
config,
|
|
305
|
+
config,
|
|
244
306
|
system_prompt = "Answer the question based on the given document. Only give me the answer and do not output any other words.\nThe following are given documents.\n\n{reference}",
|
|
245
307
|
user_prompt = "Question: {question}\nAnswer:"
|
|
246
308
|
)
|
|
247
|
-
pipeline = SequentialPipeline(
|
|
309
|
+
pipeline = SequentialPipeline(
|
|
310
|
+
my_config,
|
|
311
|
+
prompt_template = prompt_templete
|
|
312
|
+
)
|
|
248
313
|
```
|
|
249
314
|
|
|
250
315
|
Finally, execute `pipeline.run` to obtain the final result.
|
|
@@ -252,10 +317,11 @@ Finally, execute `pipeline.run` to obtain the final result.
|
|
|
252
317
|
```python
|
|
253
318
|
output_dataset = pipeline.run(test_data, do_eval=True)
|
|
254
319
|
```
|
|
320
|
+
|
|
255
321
|
The `output_dataset` contains the intermediate results and metric scores for each item in the input dataset.
|
|
256
322
|
Meanwhile, the dataset with intermediate results and the overall evaluation score will also be saved as a file (if `save_intermediate_data` and `save_metric_score` are specified).
|
|
257
323
|
|
|
258
|
-
### Build your own pipeline
|
|
324
|
+
### Build your own pipeline!
|
|
259
325
|
|
|
260
326
|
Sometimes you may need to implement more complex RAG process, and you can build your own pipeline to implement it.
|
|
261
327
|
You just need to inherit `BasicPipeline`, initialize the components you need, and complete the `run` function.
|
|
@@ -283,7 +349,6 @@ class ToyPipeline(BasicPipeline):
|
|
|
283
349
|
|
|
284
350
|
Please first understand the input and output forms of the components you need to use from our [<u>documentation</u>](./docs/basic_usage.md).
|
|
285
351
|
|
|
286
|
-
|
|
287
352
|
### Just use components
|
|
288
353
|
|
|
289
354
|
If you already have your own code and only want to use our components to embed the original code, you can refer to the [<u>basic introduction of the components</u>](./docs/basic_usage.md) to obtain the input and output formats of each component.
|
|
@@ -427,10 +492,10 @@ In each category, we have implemented corresponding common pipelines. Some pipel
|
|
|
427
492
|
</tbody>
|
|
428
493
|
</table>
|
|
429
494
|
|
|
430
|
-
|
|
431
495
|
## :robot: Supporting Methods
|
|
432
496
|
|
|
433
497
|
We have implemented 15 works with a consistent setting of:
|
|
498
|
+
|
|
434
499
|
- **Generator:** LLAMA3-8B-instruct with input length of 2048
|
|
435
500
|
- **Retriever:** e5-base-v2 as embedding model, retrieve 5 docs per query
|
|
436
501
|
- **Prompt:** A consistent default prompt, template can be found in the [<u>method details</u>](./docs/baseline_details.md).
|
|
@@ -441,35 +506,34 @@ For necessary settings and hyperparameters specific to some methods, we have doc
|
|
|
441
506
|
|
|
442
507
|
It’s important to note that, to ensure consistency, we have utilized a uniform setting. However, this setting may differ from the original setting of the method, leading to variations in results compared to the original outcomes.
|
|
443
508
|
|
|
444
|
-
|
|
445
|
-
|
|
|
446
|
-
|
|
447
|
-
|
|
|
448
|
-
|
|
|
449
|
-
| [
|
|
450
|
-
| [
|
|
451
|
-
| [
|
|
452
|
-
| [
|
|
453
|
-
| [
|
|
454
|
-
| [
|
|
455
|
-
| [
|
|
456
|
-
| [
|
|
457
|
-
| [
|
|
458
|
-
|[
|
|
459
|
-
| [
|
|
460
|
-
| [
|
|
461
|
-
| [
|
|
462
|
-
| [
|
|
463
|
-
| [IRCoT](https://aclanthology.org/2023.acl-long.557.pdf) | Loop | 33.3| 56.9|41.5|32.4 |45.6 |20.7 | |
|
|
464
|
-
|
|
509
|
+
| Method | Type | NQ (EM) | TriviaQA (EM) | Hotpotqa (F1) | 2Wiki (F1) | PopQA (F1) | WebQA(EM) | Specific setting |
|
|
510
|
+
| ----------------------------------------------------------------------------------------- | ----------- | ------- | ------------- | ------------- | ---------- | ---------- | --------- | ----------------------------------------------- |
|
|
511
|
+
| Naive Generation | Sequential | 22.6 | 55.7 | 28.4 | 33.9 | 21.7 | 18.8 | |
|
|
512
|
+
| Standard RAG | Sequential | 35.1 | 58.9 | 35.3 | 21.0 | 36.7 | 15.7 | |
|
|
513
|
+
| [AAR-contriever-kilt](https://aclanthology.org/2023.acl-long.136.pdf) | Sequential | 30.1 | 56.8 | 33.4 | 19.8 | 36.1 | 16.1 | |
|
|
514
|
+
| [LongLLMLingua](https://arxiv.org/abs/2310.06839) | Sequential | 32.2 | 59.2 | 37.5 | 25.0 | 38.7 | 17.5 | Compress Ratio=0.5 |
|
|
515
|
+
| [RECOMP-abstractive](https://arxiv.org/pdf/2310.04408) | Sequential | 33.1 | 56.4 | 37.5 | 32.4 | 39.9 | 20.2 | |
|
|
516
|
+
| [Selective-Context](https://arxiv.org/abs/2310.06201) | Sequential | 30.5 | 55.6 | 34.4 | 18.5 | 33.5 | 17.3 | Compress Ratio=0.5 |
|
|
517
|
+
| [Trace](https://arxiv.org/abs/2406.11460) | Sequential | 30.7 | 50.2 | 34.0 | 15.5 | 37.4 | 19.9 | |
|
|
518
|
+
| [Spring](https://arxiv.org/abs/2405.19670) | Sequential | 37.9 | 64.6 | 42.6 | 37.3 | 54.8 | 27.7 | Use Llama2-7B-chat with trained embedding table |
|
|
519
|
+
| [SuRe](https://arxiv.org/abs/2404.13081) | Branching | 37.1 | 53.2 | 33.4 | 20.6 | 48.1 | 24.2 | Use provided prompt |
|
|
520
|
+
| [REPLUG](https://arxiv.org/abs/2301.12652) | Branching | 28.9 | 57.7 | 31.2 | 21.1 | 27.8 | 20.2 | |
|
|
521
|
+
| [SKR](https://aclanthology.org/2023.findings-emnlp.691.pdf) | Conditional | 33.2 | 56.0 | 32.4 | 23.4 | 31.7 | 17.0 | Use infernece-time training data |
|
|
522
|
+
| [Adaptive-RAG](https://aclanthology.org/2024.naacl-long.389.pdf) | Conditional | 35.1 | 56.6 | 39.1 | 28.4 | 40.4 | 16.0 | |
|
|
523
|
+
| [Ret-Robust](https://arxiv.org/abs/2310.01558) | Loop | 42.9 | 68.2 | 35.8 | 43.4 | 57.2 | 33.7 | Use LLAMA2-13B with trained lora |
|
|
524
|
+
| [Self-RAG](https://arxiv.org/abs/2310.11511) | Loop | 36.4 | 38.2 | 29.6 | 25.1 | 32.7 | 21.9 | Use trained selfrag-llama2-7B |
|
|
525
|
+
| [FLARE](https://arxiv.org/abs/2305.06983) | Loop | 22.5 | 55.8 | 28.0 | 33.9 | 20.7 | 20.2 | |
|
|
526
|
+
| [Iter-Retgen](https://arxiv.org/abs/2305.15294), [ITRG](https://arxiv.org/abs/2310.05149) | Loop | 36.8 | 60.1 | 38.3 | 21.6 | 37.9 | 18.2 | |
|
|
527
|
+
| [IRCoT](https://aclanthology.org/2023.acl-long.557.pdf) | Loop | 33.3 | 56.9 | 41.5 | 32.4 | 45.6 | 20.7 | |
|
|
465
528
|
|
|
466
529
|
## :notebook: Supporting Datasets & Document Corpus
|
|
467
530
|
|
|
468
531
|
### Datasets
|
|
469
532
|
|
|
470
|
-
We have collected and processed 36 datasets widely used in RAG research, pre-processing them to ensure a consistent format for ease of use. For certain datasets (such as Wiki-asp), we have adapted them to fit the requirements of RAG tasks according to the methods commonly used within the community. All datasets are available at [<u>Huggingface datasets</u>](https://huggingface.co/datasets/RUC-NLPIR/FlashRAG_datasets).
|
|
533
|
+
We have collected and processed 36 datasets widely used in RAG research, pre-processing them to ensure a consistent format for ease of use. For certain datasets (such as Wiki-asp), we have adapted them to fit the requirements of RAG tasks according to the methods commonly used within the community. All datasets are available at [<u>Huggingface datasets</u>](https://huggingface.co/datasets/RUC-NLPIR/FlashRAG_datasets).
|
|
471
534
|
|
|
472
535
|
For each dataset, we save each split as a `jsonl` file, and each line is a dict as follows:
|
|
536
|
+
|
|
473
537
|
```python
|
|
474
538
|
{
|
|
475
539
|
'id': str,
|
|
@@ -479,11 +543,10 @@ For each dataset, we save each split as a `jsonl` file, and each line is a dict
|
|
|
479
543
|
}
|
|
480
544
|
```
|
|
481
545
|
|
|
482
|
-
|
|
483
546
|
Below is the list of datasets along with the corresponding sample sizes:
|
|
484
547
|
|
|
485
548
|
| Task | Dataset Name | Knowledge Source | # Train | # Dev | # Test |
|
|
486
|
-
|
|
549
|
+
| ------------------------- | --------------- | ---------------- | --------- | ------- | ------ |
|
|
487
550
|
| QA | NQ | wiki | 79,168 | 8,757 | 3,610 |
|
|
488
551
|
| QA | TriviaQA | wiki & web | 78,785 | 8,837 | 11,313 |
|
|
489
552
|
| QA | PopQA | wiki | / | / | 14,267 |
|
|
@@ -494,7 +557,7 @@ Below is the list of datasets along with the corresponding sample sizes:
|
|
|
494
557
|
| QA | WebQuestions | Google Freebase | 3,778 | / | 2,032 |
|
|
495
558
|
| QA | AmbigQA | wiki | 10,036 | 2,002 | / |
|
|
496
559
|
| QA | SIQA | - | 33,410 | 1,954 | / |
|
|
497
|
-
| QA | CommonSenseQA
|
|
560
|
+
| QA | CommonSenseQA | - | 9,741 | 1,221 | / |
|
|
498
561
|
| QA | BoolQ | wiki | 9,427 | 3,270 | / |
|
|
499
562
|
| QA | PIQA | - | 16,113 | 1,838 | / |
|
|
500
563
|
| QA | Fermi | wiki | 8,000 | 1,000 | 1,000 |
|
|
@@ -502,24 +565,24 @@ Below is the list of datasets along with the corresponding sample sizes:
|
|
|
502
565
|
| multi-hop QA | 2WikiMultiHopQA | wiki | 15,000 | 12,576 | / |
|
|
503
566
|
| multi-hop QA | Musique | wiki | 19,938 | 2,417 | / |
|
|
504
567
|
| multi-hop QA | Bamboogle | wiki | / | / | 125 |
|
|
505
|
-
| multi-hop QA | StrategyQA | wiki | 2290 | / | /
|
|
568
|
+
| multi-hop QA | StrategyQA | wiki | 2290 | / | / |
|
|
506
569
|
| Long-form QA | ASQA | wiki | 4,353 | 948 | / |
|
|
507
570
|
| Long-form QA | ELI5 | Reddit | 272,634 | 1,507 | / |
|
|
508
|
-
| Long-form QA | WikiPassageQA
|
|
571
|
+
| Long-form QA | WikiPassageQA | wiki | 3,332 | 417 | 416 |
|
|
509
572
|
| Open-Domain Summarization | WikiASP | wiki | 300,636 | 37,046 | 37,368 |
|
|
510
573
|
| multiple-choice | MMLU | - | 99,842 | 1,531 | 14,042 |
|
|
511
574
|
| multiple-choice | TruthfulQA | wiki | / | 817 | / |
|
|
512
575
|
| multiple-choice | HellaSWAG | ActivityNet | 39,905 | 10,042 | / |
|
|
513
576
|
| multiple-choice | ARC | - | 3,370 | 869 | 3,548 |
|
|
514
577
|
| multiple-choice | OpenBookQA | - | 4,957 | 500 | 500 |
|
|
515
|
-
| multiple-choice | QuaRTz
|
|
578
|
+
| multiple-choice | QuaRTz | - | 2696 | 384 | 784 |
|
|
516
579
|
| Fact Verification | FEVER | wiki | 104,966 | 10,444 | / |
|
|
517
580
|
| Dialog Generation | WOW | wiki | 63,734 | 3,054 | / |
|
|
518
581
|
| Entity Linking | AIDA CoNll-yago | Freebase & wiki | 18,395 | 4,784 | / |
|
|
519
582
|
| Entity Linking | WNED | Wiki | / | 8,995 | / |
|
|
520
583
|
| Slot Filling | T-REx | DBPedia | 2,284,168 | 5,000 | / |
|
|
521
584
|
| Slot Filling | Zero-shot RE | wiki | 147,909 | 3,724 | / |
|
|
522
|
-
| In-domain QA| DomainRAG
|
|
585
|
+
| In-domain QA | DomainRAG | Web pages of RUC | / | / | 485 |
|
|
523
586
|
|
|
524
587
|
### Document Corpus
|
|
525
588
|
|
|
@@ -529,23 +592,23 @@ Our toolkit supports jsonl format for retrieval document collections, with the f
|
|
|
529
592
|
{"id":"0", "contents": "...."}
|
|
530
593
|
{"id":"1", "contents": "..."}
|
|
531
594
|
```
|
|
595
|
+
|
|
532
596
|
The `contents` key is essential for building the index. For documents that include both text and title, we recommend setting the value of `contents` to `{title}\n{text}`. The corpus file can also contain other keys to record additional characteristics of the documents.
|
|
533
597
|
|
|
534
598
|
In the academic research, Wikipedia and MS MARCO are the most commonly used retrieval document collections. For Wikipedia, we provide a [<u>comprehensive script</u>](./docs/process-wiki.md) to process any Wikipedia dump into a clean corpus. Additionally, various processed versions of the Wikipedia corpus are available in many works, and we have listed some reference links.
|
|
535
599
|
|
|
536
|
-
|
|
537
600
|
For MS MARCO, it is already processed upon release and can be directly downloaded from its [<u>hosting link</u>](https://huggingface.co/datasets/Tevatron/msmarco-passage-corpus) on Hugging Face.
|
|
538
601
|
|
|
539
602
|
### Index
|
|
540
603
|
|
|
541
|
-
To facilitate easier replication of the experiments, we now provide a preprocessed index available in the ModelScope dataset page: [FlashRAG_Dataset/retrieval_corpus/wiki18_100w_e5_index.zip](https://www.modelscope.cn/datasets/hhjinjiajie/FlashRAG_Dataset/file/view/master?id=47985&status=2&fileName=retrieval_corpus%252Fwiki18_100w_e5_index.zip).
|
|
604
|
+
To facilitate easier replication of the experiments, we now provide a preprocessed index available in the ModelScope dataset page: [FlashRAG_Dataset/retrieval_corpus/wiki18_100w_e5_index.zip](https://www.modelscope.cn/datasets/hhjinjiajie/FlashRAG_Dataset/file/view/master?id=47985&status=2&fileName=retrieval_corpus%252Fwiki18_100w_e5_index.zip).
|
|
542
605
|
|
|
543
606
|
The index was created using the e5-base-v2 retriever on our uploaded wiki18_100w dataset, which is consistent with the index used in our experiments.
|
|
544
607
|
|
|
545
608
|
## :raised_hands: Additional FAQs
|
|
546
609
|
|
|
547
610
|
- [How should I set different experimental parameters?](./docs/configuration.md)
|
|
548
|
-
- [How to build my own corpus, such as a specific segmented Wikipedia?](./docs/process-wiki.md)
|
|
611
|
+
- [How to build my own corpus, such as a specific segmented Wikipedia?](./docs/process-wiki.md)
|
|
549
612
|
- [How to index my own corpus?](./docs/building-index.md)
|
|
550
613
|
- [How to reproduce supporting methods?](./docs/reproduce_experiment.md)
|
|
551
614
|
|
|
@@ -553,9 +616,10 @@ The index was created using the e5-base-v2 retriever on our uploaded wiki18_100w
|
|
|
553
616
|
|
|
554
617
|
FlashRAG is licensed under the [<u>MIT License</u>](./LICENSE).
|
|
555
618
|
|
|
556
|
-
|
|
557
619
|
## :star2: Citation
|
|
620
|
+
|
|
558
621
|
Please kindly cite our paper if helps your research:
|
|
622
|
+
|
|
559
623
|
```BibTex
|
|
560
624
|
@article{FlashRAG,
|
|
561
625
|
author={Jiajie Jin and
|