flashrag-dev 0.1.4.dev20250403__tar.gz → 0.1.4.dev20250423__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.dev20250403 → flashrag_dev-0.1.4.dev20250423}/PKG-INFO +4 -1
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/README.md +3 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/openai_generator.py +39 -14
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/active_pipeline.py +9 -5
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/base_prompt.py +32 -19
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/reranker.py +1 -1
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/retriever.py +6 -5
- flashrag_dev-0.1.4.dev20250423/flashrag/version.py +1 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/PKG-INFO +4 -1
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/requires.txt +3 -3
- flashrag_dev-0.1.4.dev20250403/flashrag/version.py +0 -1
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/LICENSE +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/config/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/config/basic_config.yaml +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/config/config.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/dataset/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/dataset/dataset.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/dataset/utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/_bleu.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/evaluator.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/metrics.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/fid.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/generator.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/multimodal_generator.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/stop_word_criteria.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/judger/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/judger/judger.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/branching_pipeline.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/mm_pipeline.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/pipeline.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/reasoning_pipeline.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/replug_utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/mm_prompt.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/selfask_examplars.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/trace_examplars.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/kg_refiner.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/llmlingua_compressor.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/refiner.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/selective_context_compressor.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/__main__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/encoder.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/index_builder.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/__init__.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/constants.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/pred_parse.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/utils.py +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/SOURCES.txt +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/dependency_links.txt +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/top_level.txt +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/pyproject.toml +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/setup.cfg +0 -0
- {flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/setup.py +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.dev20250423
|
|
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
|
|
@@ -94,6 +94,7 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
94
94
|
- [ ] Inlcude more RAG approaches
|
|
95
95
|
- [ ] Add more evaluation metrics (e.g., Unieval, name-entity F1) and benchmarks (e.g., RGB benchmark)
|
|
96
96
|
- [ ] Enhance code adaptability and readability
|
|
97
|
+
- [ ] Add support for api-based retriever (vllm server)
|
|
97
98
|
|
|
98
99
|
## :page_with_curl: Changelog
|
|
99
100
|
[25/03/21] We have added support for **Reasoning Pipeline**, which is a new paradigm that combines reasoning ability and retrieval, representing work that includes [Search-o1](https://github.com/sunnynexus/Search-o1), [R1-Searcher](https://github.com/SsmallSong/R1-Searcher), [ReSearch](https://github.com/Agent-RL/ReSearch). We evaluate the performance of the pipeline on various RAG benchmarks, it can achieve F1 scores close to 60 on multi hop inference datasets such as Hotpotqe. See it in [**result table**](#robot-supporting-methods).
|
|
@@ -108,6 +109,8 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
108
109
|
|
|
109
110
|
[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/original_docs/multi_retriever_usage.md).
|
|
110
111
|
|
|
112
|
+
[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/original_docs/chunk-doc-corpus.md).
|
|
113
|
+
|
|
111
114
|
[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.
|
|
112
115
|
|
|
113
116
|
[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.
|
|
@@ -77,6 +77,7 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
77
77
|
- [ ] Inlcude more RAG approaches
|
|
78
78
|
- [ ] Add more evaluation metrics (e.g., Unieval, name-entity F1) and benchmarks (e.g., RGB benchmark)
|
|
79
79
|
- [ ] Enhance code adaptability and readability
|
|
80
|
+
- [ ] Add support for api-based retriever (vllm server)
|
|
80
81
|
|
|
81
82
|
## :page_with_curl: Changelog
|
|
82
83
|
[25/03/21] We have added support for **Reasoning Pipeline**, which is a new paradigm that combines reasoning ability and retrieval, representing work that includes [Search-o1](https://github.com/sunnynexus/Search-o1), [R1-Searcher](https://github.com/SsmallSong/R1-Searcher), [ReSearch](https://github.com/Agent-RL/ReSearch). We evaluate the performance of the pipeline on various RAG benchmarks, it can achieve F1 scores close to 60 on multi hop inference datasets such as Hotpotqe. See it in [**result table**](#robot-supporting-methods).
|
|
@@ -91,6 +92,8 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
91
92
|
|
|
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/original_docs/multi_retriever_usage.md).
|
|
93
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/original_docs/chunk-doc-corpus.md).
|
|
96
|
+
|
|
94
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.
|
|
95
98
|
|
|
96
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.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from typing import List
|
|
2
|
+
from typing import List, Union
|
|
3
3
|
from copy import deepcopy
|
|
4
4
|
import warnings
|
|
5
5
|
from tqdm import tqdm
|
|
@@ -63,16 +63,26 @@ class OpenaiGenerator:
|
|
|
63
63
|
def update_additional_setting(self):
|
|
64
64
|
pass
|
|
65
65
|
|
|
66
|
-
async def _get_response(self, messages:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
async def _get_response(self, messages: Union[list, str], mode: str = 'chat', **params):
|
|
67
|
+
print(messages)
|
|
68
|
+
print("----asd-asd-a--------")
|
|
69
|
+
if mode == 'chat':
|
|
70
|
+
response = await self.client.chat.completions.create(
|
|
71
|
+
model=self.model_name, messages=messages, **params
|
|
72
|
+
)
|
|
73
|
+
if not response.choices:
|
|
74
|
+
raise ValueError("No choices returned from API.")
|
|
75
|
+
return response.choices[0]
|
|
76
|
+
else:
|
|
77
|
+
response = await self.client.completions.create(
|
|
78
|
+
model=self.model_name, prompt=messages, **params
|
|
79
|
+
)
|
|
80
|
+
if not response.choices:
|
|
81
|
+
raise ValueError("No choices returned from API.")
|
|
82
|
+
return response.choices[0]
|
|
73
83
|
|
|
74
|
-
async def _get_batch_response(self, input_list: List[List], batch_size, **params):
|
|
75
|
-
tasks = [self._get_response(messages, **params) for messages in input_list]
|
|
84
|
+
async def _get_batch_response(self, input_list: List[List], batch_size, mode, **params):
|
|
85
|
+
tasks = [self._get_response(messages, mode, **params) for messages in input_list]
|
|
76
86
|
all_results = []
|
|
77
87
|
for idx in tqdm(range(0, len(tasks), batch_size), desc="Generation process: "):
|
|
78
88
|
batch_tasks = tasks[idx: idx + batch_size]
|
|
@@ -85,6 +95,10 @@ class OpenaiGenerator:
|
|
|
85
95
|
input_list = [[input_list]]
|
|
86
96
|
elif isinstance(input_list[0], dict):
|
|
87
97
|
input_list = [input_list]
|
|
98
|
+
if isinstance(input_list[0], list):
|
|
99
|
+
mode = 'chat'
|
|
100
|
+
else:
|
|
101
|
+
mode = 'completion'
|
|
88
102
|
|
|
89
103
|
if batch_size is None:
|
|
90
104
|
batch_size = self.batch_size
|
|
@@ -107,15 +121,26 @@ class OpenaiGenerator:
|
|
|
107
121
|
warnings.warn("Set logprobs to True to get generation scores.")
|
|
108
122
|
|
|
109
123
|
|
|
110
|
-
results = await self._get_batch_response(input_list, batch_size, **generation_params)
|
|
124
|
+
results = await self._get_batch_response(input_list, batch_size, mode, **generation_params)
|
|
111
125
|
|
|
112
126
|
response_texts = []
|
|
113
127
|
scores = []
|
|
114
128
|
for res in results:
|
|
115
|
-
|
|
129
|
+
if mode == 'chat':
|
|
130
|
+
text = res.message.content
|
|
131
|
+
else:
|
|
132
|
+
text = res.text
|
|
133
|
+
if 'stop' in generation_params and not any([text.endswith(stop_str) for stop_str in generation_params['stop']]):
|
|
134
|
+
# current openai api not support including stop, so need to add the stop token
|
|
135
|
+
text += generation_params['stop'][0]
|
|
136
|
+
response_texts.append(text)
|
|
116
137
|
if return_scores:
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
try:
|
|
139
|
+
score = np.exp([item.logprob for item in res.logprobs.content])
|
|
140
|
+
scores.append(score)
|
|
141
|
+
except:
|
|
142
|
+
warnings.warn('Fail to get logprobs in openai generation!')
|
|
143
|
+
scores.append(None)
|
|
119
144
|
return (response_texts, scores) if return_scores else response_texts
|
|
120
145
|
|
|
121
146
|
# ----------------- 同步包装接口 -----------------
|
|
@@ -931,12 +931,17 @@ class IRCOTPipeline(BasicPipeline):
|
|
|
931
931
|
):
|
|
932
932
|
# if not provide prompt template, use default template provided by IRCOT
|
|
933
933
|
if prompt_template is None:
|
|
934
|
+
if config['framework'] == 'openai':
|
|
935
|
+
enable_chat = True
|
|
936
|
+
else:
|
|
937
|
+
enable_chat = False
|
|
938
|
+
|
|
934
939
|
prompt_template = PromptTemplate(
|
|
935
940
|
config=config,
|
|
936
941
|
system_prompt=f"{self.IRCOT_INSTRUCTION}\n\n{self.IRCOT_EXAMPLE}",
|
|
937
942
|
user_prompt="{reference}Question: {question}\nThought:",
|
|
938
943
|
reference_template="Wikipedia Title: {title}\n{text}\n\n",
|
|
939
|
-
enable_chat=
|
|
944
|
+
enable_chat=enable_chat,
|
|
940
945
|
)
|
|
941
946
|
|
|
942
947
|
super().__init__(config, prompt_template)
|
|
@@ -957,7 +962,6 @@ class IRCOTPipeline(BasicPipeline):
|
|
|
957
962
|
questions = [item.question for item in items]
|
|
958
963
|
retrieval_results, scoress = self.retriever.batch_search(questions, return_score=True)
|
|
959
964
|
for retrieval_result, scores in zip(retrieval_results,scoress):
|
|
960
|
-
|
|
961
965
|
doc2score = {doc_item['id']: score for doc_item, score in zip(retrieval_result, scores)}
|
|
962
966
|
id2doc = {doc_item['id']: doc_item for doc_item in retrieval_result}
|
|
963
967
|
batch_retrieval_results.append(retrieval_result)
|
|
@@ -976,6 +980,7 @@ class IRCOTPipeline(BasicPipeline):
|
|
|
976
980
|
)
|
|
977
981
|
for item_id in active_item_ids
|
|
978
982
|
]
|
|
983
|
+
|
|
979
984
|
|
|
980
985
|
# Batch generation for active items
|
|
981
986
|
new_thoughts_batch = self.generator.generate(input_prompts, stop=['.', '\n'])
|
|
@@ -988,15 +993,14 @@ class IRCOTPipeline(BasicPipeline):
|
|
|
988
993
|
|
|
989
994
|
# Check for termination condition
|
|
990
995
|
# Store intermediate outputs
|
|
991
|
-
|
|
992
|
-
items[item_id].update_output(
|
|
996
|
+
items[item_id].update_output(
|
|
993
997
|
f'intermediate_output_iter{iter_num}',
|
|
994
998
|
{
|
|
995
999
|
'input_prompt': input_prompts[idx],
|
|
996
1000
|
'new_thought': new_thought,
|
|
997
1001
|
},
|
|
998
1002
|
)
|
|
999
|
-
|
|
1003
|
+
if "So the answer is:" not in new_thought:
|
|
1000
1004
|
new_active_item_ids.append(item_id)
|
|
1001
1005
|
|
|
1002
1006
|
# Update active item IDs for the next iteration
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/base_prompt.py
RENAMED
|
@@ -58,23 +58,29 @@ class PromptTemplate:
|
|
|
58
58
|
|
|
59
59
|
def truncate_prompt(self, prompt):
|
|
60
60
|
if self.is_openai:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
if self.enable_chat:
|
|
62
|
+
truncated_messages = []
|
|
63
|
+
total_tokens = 0
|
|
64
|
+
assert isinstance(prompt, list)
|
|
65
|
+
for message in prompt:
|
|
66
|
+
role_content = message['content']
|
|
67
|
+
encoded_message = self.tokenizer.encode(role_content)
|
|
68
|
+
|
|
69
|
+
if total_tokens + len(encoded_message) <= self.max_input_len:
|
|
70
|
+
truncated_messages.append(message)
|
|
71
|
+
total_tokens += len(encoded_message)
|
|
72
|
+
else:
|
|
73
|
+
print(f"The input text length is greater than the maximum length ({total_tokens + len(encoded_message)} > {self.max_input_len}) and has been truncated!")
|
|
74
|
+
remaining_tokens = self.max_input_len - total_tokens
|
|
75
|
+
truncated_message = self.encoding.decode(encoded_message[:remaining_tokens])
|
|
76
|
+
message['content'] = truncated_message
|
|
77
|
+
truncated_messages.append(message)
|
|
78
|
+
break
|
|
79
|
+
else:
|
|
80
|
+
assert isinstance(prompt, str)
|
|
81
|
+
tokenized_prompt = self.tokenizer.encode(prompt,allowed_special={'<|endoftext|>'})
|
|
82
|
+
half = int(self.max_input_len / 2)
|
|
83
|
+
truncated_messages = self.tokenizer.decode(tokenized_prompt[:half]) + self.tokenizer.decode(tokenized_prompt[-half:])
|
|
78
84
|
|
|
79
85
|
return truncated_messages
|
|
80
86
|
|
|
@@ -134,8 +140,15 @@ class PromptTemplate:
|
|
|
134
140
|
else:
|
|
135
141
|
input = "\n\n".join([prompt for prompt in [system_prompt, user_prompt] if prompt != ""])
|
|
136
142
|
|
|
137
|
-
if previous_gen is not None and previous_gen not in ["", " "]
|
|
138
|
-
|
|
143
|
+
if previous_gen is not None and previous_gen not in ["", " "]:
|
|
144
|
+
if self.is_openai:
|
|
145
|
+
if self.enable_chat:
|
|
146
|
+
input.append({"role": 'assistant', 'content': previous_gen})
|
|
147
|
+
else:
|
|
148
|
+
input += f'<|endoftext|>{previous_gen}'
|
|
149
|
+
|
|
150
|
+
else:
|
|
151
|
+
input += previous_gen
|
|
139
152
|
|
|
140
153
|
return self.truncate_prompt(input)
|
|
141
154
|
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/reranker.py
RENAMED
|
@@ -44,7 +44,7 @@ class BaseReranker:
|
|
|
44
44
|
doc_list = [doc_list]
|
|
45
45
|
|
|
46
46
|
assert len(query_list) == len(doc_list)
|
|
47
|
-
if topk
|
|
47
|
+
if topk > min([len(docs) for docs in doc_list]):
|
|
48
48
|
warnings.warn("The number of doc returned by the retriever is less than the topk.")
|
|
49
49
|
|
|
50
50
|
# get doc contents
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/retriever.py
RENAMED
|
@@ -242,10 +242,7 @@ class BM25Retriever(BaseTextRetriever):
|
|
|
242
242
|
else:
|
|
243
243
|
self.corpus = corpus
|
|
244
244
|
self.max_process_num = 8
|
|
245
|
-
|
|
246
|
-
is_zh = judge_zh(self.corpus[0]["contents"])
|
|
247
|
-
if is_zh:
|
|
248
|
-
self.searcher.set_language("zh")
|
|
245
|
+
|
|
249
246
|
elif self.backend == "bm25s":
|
|
250
247
|
import Stemmer
|
|
251
248
|
import bm25s
|
|
@@ -278,6 +275,9 @@ class BM25Retriever(BaseTextRetriever):
|
|
|
278
275
|
if num is None:
|
|
279
276
|
num = self.topk
|
|
280
277
|
if self.backend == "pyserini":
|
|
278
|
+
is_zh = judge_zh(query)
|
|
279
|
+
if is_zh:
|
|
280
|
+
self.searcher.set_language("zh")
|
|
281
281
|
hits = self.searcher.search(query, num)
|
|
282
282
|
if len(hits) < 1:
|
|
283
283
|
if return_score:
|
|
@@ -295,11 +295,12 @@ class BM25Retriever(BaseTextRetriever):
|
|
|
295
295
|
all_contents = [json.loads(self.searcher.doc(hit.docid).raw())["contents"] for hit in hits]
|
|
296
296
|
results = [
|
|
297
297
|
{
|
|
298
|
+
"id": hit.docid,
|
|
298
299
|
"title": content.split("\n")[0].strip('"'),
|
|
299
300
|
"text": "\n".join(content.split("\n")[1:]),
|
|
300
301
|
"contents": content,
|
|
301
302
|
}
|
|
302
|
-
for content in all_contents
|
|
303
|
+
for content, hit in zip(all_contents, hits)
|
|
303
304
|
]
|
|
304
305
|
else:
|
|
305
306
|
results = load_docs(self.corpus, [hit.docid for hit in hits])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.4dev20250423"
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/PKG-INFO
RENAMED
|
@@ -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.dev20250423
|
|
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
|
|
@@ -94,6 +94,7 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
94
94
|
- [ ] Inlcude more RAG approaches
|
|
95
95
|
- [ ] Add more evaluation metrics (e.g., Unieval, name-entity F1) and benchmarks (e.g., RGB benchmark)
|
|
96
96
|
- [ ] Enhance code adaptability and readability
|
|
97
|
+
- [ ] Add support for api-based retriever (vllm server)
|
|
97
98
|
|
|
98
99
|
## :page_with_curl: Changelog
|
|
99
100
|
[25/03/21] We have added support for **Reasoning Pipeline**, which is a new paradigm that combines reasoning ability and retrieval, representing work that includes [Search-o1](https://github.com/sunnynexus/Search-o1), [R1-Searcher](https://github.com/SsmallSong/R1-Searcher), [ReSearch](https://github.com/Agent-RL/ReSearch). We evaluate the performance of the pipeline on various RAG benchmarks, it can achieve F1 scores close to 60 on multi hop inference datasets such as Hotpotqe. See it in [**result table**](#robot-supporting-methods).
|
|
@@ -108,6 +109,8 @@ FlashRAG is still under development and there are many issues and room for impro
|
|
|
108
109
|
|
|
109
110
|
[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/original_docs/multi_retriever_usage.md).
|
|
110
111
|
|
|
112
|
+
[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/original_docs/chunk-doc-corpus.md).
|
|
113
|
+
|
|
111
114
|
[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.
|
|
112
115
|
|
|
113
116
|
[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.
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/requires.txt
RENAMED
|
@@ -16,7 +16,7 @@ transformers>=4.40.0
|
|
|
16
16
|
bm25s[core]==0.2.0
|
|
17
17
|
fschat
|
|
18
18
|
streamlit
|
|
19
|
-
chonkie
|
|
19
|
+
chonkie<1.1.0,>=1.0.2
|
|
20
20
|
gradio>=5.0.0
|
|
21
21
|
rouge-chinese
|
|
22
22
|
jieba
|
|
@@ -40,7 +40,7 @@ transformers>=4.40.0
|
|
|
40
40
|
bm25s[core]==0.2.0
|
|
41
41
|
fschat
|
|
42
42
|
streamlit
|
|
43
|
-
chonkie
|
|
43
|
+
chonkie<1.1.0,>=1.0.2
|
|
44
44
|
gradio>=5.0.0
|
|
45
45
|
rouge-chinese
|
|
46
46
|
jieba
|
|
@@ -64,7 +64,7 @@ transformers>=4.40.0
|
|
|
64
64
|
bm25s[core]==0.2.0
|
|
65
65
|
fschat
|
|
66
66
|
streamlit
|
|
67
|
-
chonkie
|
|
67
|
+
chonkie<1.1.0,>=1.0.2
|
|
68
68
|
gradio>=5.0.0
|
|
69
69
|
rouge-chinese
|
|
70
70
|
jieba
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.4dev20250403"
|
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/config/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/config/basic_config.yaml
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/dataset/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/dataset/dataset.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/_bleu.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/evaluator.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/metrics.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/evaluator/utils.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/generator.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/generator/utils.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/judger/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/mm_pipeline.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/pipeline.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/pipeline/replug_utils.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/mm_prompt.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/prompt/trace_examplars.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/kg_refiner.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/refiner/refiner.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/__main__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/encoder.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/retriever/utils.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/__init__.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/constants.py
RENAMED
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag/utils/pred_parse.py
RENAMED
|
File without changes
|
|
File without changes
|
{flashrag_dev-0.1.4.dev20250403 → flashrag_dev-0.1.4.dev20250423}/flashrag_dev.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|