flashrag-dev 0.1.4.dev20250512__tar.gz → 0.1.4.dev20250608__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.
Files changed (62) hide show
  1. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/PKG-INFO +1 -1
  2. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/prompt/base_prompt.py +23 -17
  3. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/encoder.py +2 -2
  4. flashrag_dev-0.1.4.dev20250608/flashrag/version.py +1 -0
  5. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag_dev.egg-info/PKG-INFO +1 -1
  6. flashrag_dev-0.1.4.dev20250512/flashrag/version.py +0 -1
  7. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/LICENSE +0 -0
  8. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/README.md +0 -0
  9. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/__init__.py +0 -0
  10. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/config/__init__.py +0 -0
  11. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/config/basic_config.yaml +0 -0
  12. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/config/config.py +0 -0
  13. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/dataset/__init__.py +0 -0
  14. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/dataset/dataset.py +0 -0
  15. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/dataset/utils.py +0 -0
  16. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/evaluator/__init__.py +0 -0
  17. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/evaluator/_bleu.py +0 -0
  18. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/evaluator/evaluator.py +0 -0
  19. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/evaluator/metrics.py +0 -0
  20. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/evaluator/utils.py +0 -0
  21. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/__init__.py +0 -0
  22. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/fid.py +0 -0
  23. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/generator.py +0 -0
  24. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/multimodal_generator.py +0 -0
  25. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/openai_generator.py +0 -0
  26. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/stop_word_criteria.py +0 -0
  27. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/generator/utils.py +0 -0
  28. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/judger/__init__.py +0 -0
  29. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/judger/judger.py +0 -0
  30. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/__init__.py +0 -0
  31. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/active_pipeline.py +0 -0
  32. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/branching_pipeline.py +0 -0
  33. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/mm_pipeline.py +0 -0
  34. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/pipeline.py +0 -0
  35. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/reasoning_pipeline.py +0 -0
  36. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/pipeline/replug_utils.py +0 -0
  37. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/prompt/__init__.py +0 -0
  38. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/prompt/mm_prompt.py +0 -0
  39. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/prompt/selfask_examplars.py +0 -0
  40. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/prompt/trace_examplars.py +0 -0
  41. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/refiner/__init__.py +0 -0
  42. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/refiner/kg_refiner.py +0 -0
  43. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/refiner/llmlingua_compressor.py +0 -0
  44. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/refiner/refiner.py +0 -0
  45. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/refiner/selective_context_compressor.py +0 -0
  46. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/__init__.py +0 -0
  47. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/__main__.py +0 -0
  48. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/index_builder.py +0 -0
  49. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/reranker.py +0 -0
  50. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/retriever.py +0 -0
  51. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/retriever/utils.py +0 -0
  52. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/utils/__init__.py +0 -0
  53. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/utils/constants.py +0 -0
  54. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/utils/pred_parse.py +0 -0
  55. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag/utils/utils.py +0 -0
  56. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag_dev.egg-info/SOURCES.txt +0 -0
  57. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag_dev.egg-info/dependency_links.txt +0 -0
  58. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag_dev.egg-info/requires.txt +0 -0
  59. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/flashrag_dev.egg-info/top_level.txt +0 -0
  60. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/pyproject.toml +0 -0
  61. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/setup.cfg +0 -0
  62. {flashrag_dev-0.1.4.dev20250512 → flashrag_dev-0.1.4.dev20250608}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag_dev
3
- Version: 0.1.4.dev20250512
3
+ Version: 0.1.4.dev20250608
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
@@ -23,16 +23,9 @@ class PromptTemplate:
23
23
  self.is_chat = False
24
24
  if "chat" in model_name or "instruct" in model_name:
25
25
  self.is_chat = True
26
- self.tokenizer = AutoTokenizer.from_pretrained(self.generator_path, trust_remote_code=True)
27
26
  else:
28
27
  self.is_chat = True
29
28
  self.enable_chat = True
30
- try:
31
- self.tokenizer = tiktoken.encoding_for_model(config['generator_model'])
32
- except Exception as e:
33
- print("Error: ", e)
34
- warnings.warn("This model is not supported by tiktoken. Use gpt-3.5-turbo instead.")
35
- self.tokenizer = tiktoken.encoding_for_model('gpt-3.5-turbo')
36
29
 
37
30
  if len(system_prompt) == 0 and len(user_prompt) == 0:
38
31
  system_prompt = self.base_system_prompt
@@ -41,8 +34,22 @@ class PromptTemplate:
41
34
  self.user_prompt = user_prompt
42
35
  self.enable_chat = enable_chat
43
36
  self.reference_template = reference_template
37
+ self.tokenizer = None
44
38
 
45
39
  # self._check_placeholder()
40
+ def _get_tokenizer(self):
41
+ if self.tokenizer is None:
42
+ if self.is_openai:
43
+ try:
44
+ self.tokenizer = tiktoken.encoding_for_model(self.config['generator_model'])
45
+ except Exception as e:
46
+ print("Error: ", e)
47
+ warnings.warn("This model is not supported by tiktoken. Use gpt-3.5-turbo instead.")
48
+ self.tokenizer = tiktoken.encoding_for_model('gpt-3.5-turbo')
49
+ else:
50
+ self.tokenizer = AutoTokenizer.from_pretrained(self.generator_path, trust_remote_code=True)
51
+ return self.tokenizer
52
+
46
53
 
47
54
  def _check_placeholder(self):
48
55
  # check placeholder in prompt
@@ -64,7 +71,7 @@ class PromptTemplate:
64
71
  assert isinstance(prompt, list)
65
72
  for message in prompt:
66
73
  role_content = message['content']
67
- encoded_message = self.tokenizer.encode(role_content)
74
+ encoded_message = self._get_tokenizer().encode(role_content)
68
75
 
69
76
  if total_tokens + len(encoded_message) <= self.max_input_len:
70
77
  truncated_messages.append(message)
@@ -78,23 +85,22 @@ class PromptTemplate:
78
85
  break
79
86
  else:
80
87
  assert isinstance(prompt, str)
81
- tokenized_prompt = self.tokenizer.encode(prompt,allowed_special={'<|endoftext|>'})
88
+ tokenized_prompt = self._get_tokenizer().encode(prompt,allowed_special={'<|endoftext|>'})
82
89
  half = int(self.max_input_len / 2)
83
- truncated_messages = self.tokenizer.decode(tokenized_prompt[:half]) + self.tokenizer.decode(tokenized_prompt[-half:])
90
+ truncated_messages = self._get_tokenizer().decode(tokenized_prompt[:half]) + self._get_tokenizer().decode(tokenized_prompt[-half:])
84
91
 
85
92
  return truncated_messages
86
93
 
87
94
  else:
88
- if self.tokenizer is None:
89
- self.tokenizer = AutoTokenizer.from_pretrained(self.generator_path, trust_remote_code=True)
90
95
  assert isinstance(prompt, str)
91
- tokenized_prompt = self.tokenizer(prompt, truncation=False, return_tensors="pt").input_ids[0]
96
+ # tokenized_prompt = self._get_tokenizer().encode(prompt, truncation=False, return_tensors="pt").input_ids[0]
97
+ tokenized_prompt = self._get_tokenizer().encode(prompt,truncation=False,return_tensors="pt")
92
98
 
93
99
  if len(tokenized_prompt) > self.max_input_len:
94
100
  print(f"The input text length is greater than the maximum length ({len(tokenized_prompt)} > {self.max_input_len}) and has been truncated!")
95
101
  half = int(self.max_input_len / 2)
96
- prompt = self.tokenizer.decode(tokenized_prompt[:half], skip_special_tokens=True) + \
97
- self.tokenizer.decode(tokenized_prompt[-half:], skip_special_tokens=True)
102
+ prompt = self._get_tokenizer().decode(tokenized_prompt[:half], skip_special_tokens=True) + \
103
+ self._get_tokenizer().decode(tokenized_prompt[-half:], skip_special_tokens=True)
98
104
  return prompt
99
105
 
100
106
 
@@ -107,7 +113,7 @@ class PromptTemplate:
107
113
  if self.is_openai:
108
114
  self.truncate_prompt(messages)
109
115
  else:
110
- prompt = self.tokenizer.apply_chat_template(
116
+ prompt = self._get_tokenizer().apply_chat_template(
111
117
  messages, tokenize=False, add_generation_prompt=True
112
118
  )
113
119
  return self.truncate_prompt(prompt)
@@ -136,7 +142,7 @@ class PromptTemplate:
136
142
  if user_prompt != "":
137
143
  input.append({"role": "user", "content": user_prompt})
138
144
  if not self.is_openai:
139
- input = self.tokenizer.apply_chat_template(input, tokenize=False, add_generation_prompt=True)
145
+ input = self._get_tokenizer().apply_chat_template(input, tokenize=False, add_generation_prompt=True)
140
146
  else:
141
147
  input = "\n\n".join([prompt for prompt in [system_prompt, user_prompt] if prompt != ""])
142
148
 
@@ -147,12 +147,12 @@ class STEncoder:
147
147
  class ClipEncoder:
148
148
  """ClipEncoder class for encoding queries using CLIP."""
149
149
 
150
- def __init__(self, model_name, model_path, slient=False):
150
+ def __init__(self, model_name, model_path, silent=False):
151
151
 
152
152
  self.model_name = model_name
153
153
  self.model_path = model_path
154
154
  self.load_clip_model()
155
- self.slient = slient
155
+ self.silent = silent
156
156
 
157
157
  def load_clip_model(self):
158
158
  from transformers import AutoModel, AutoProcessor
@@ -0,0 +1 @@
1
+ __version__ = "0.1.4dev20250608"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag-dev
3
- Version: 0.1.4.dev20250512
3
+ Version: 0.1.4.dev20250608
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
@@ -1 +0,0 @@
1
- __version__ = "0.1.4dev20250512"