flashrag-dev 0.1.4.dev20250423__tar.gz → 0.1.4.dev20250425__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.dev20250423 → flashrag_dev-0.1.4.dev20250425}/PKG-INFO +1 -1
  2. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/encoder.py +16 -13
  3. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/retriever.py +4 -2
  4. flashrag_dev-0.1.4.dev20250425/flashrag/version.py +1 -0
  5. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag_dev.egg-info/PKG-INFO +1 -1
  6. flashrag_dev-0.1.4.dev20250423/flashrag/version.py +0 -1
  7. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/LICENSE +0 -0
  8. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/README.md +0 -0
  9. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/__init__.py +0 -0
  10. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/config/__init__.py +0 -0
  11. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/config/basic_config.yaml +0 -0
  12. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/config/config.py +0 -0
  13. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/dataset/__init__.py +0 -0
  14. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/dataset/dataset.py +0 -0
  15. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/dataset/utils.py +0 -0
  16. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/evaluator/__init__.py +0 -0
  17. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/evaluator/_bleu.py +0 -0
  18. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/evaluator/evaluator.py +0 -0
  19. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/evaluator/metrics.py +0 -0
  20. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/evaluator/utils.py +0 -0
  21. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/__init__.py +0 -0
  22. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/fid.py +0 -0
  23. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/generator.py +0 -0
  24. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/multimodal_generator.py +0 -0
  25. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/openai_generator.py +0 -0
  26. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/stop_word_criteria.py +0 -0
  27. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/generator/utils.py +0 -0
  28. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/judger/__init__.py +0 -0
  29. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/judger/judger.py +0 -0
  30. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/__init__.py +0 -0
  31. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/active_pipeline.py +0 -0
  32. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/branching_pipeline.py +0 -0
  33. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/mm_pipeline.py +0 -0
  34. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/pipeline.py +0 -0
  35. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/reasoning_pipeline.py +0 -0
  36. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/pipeline/replug_utils.py +0 -0
  37. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/prompt/__init__.py +0 -0
  38. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/prompt/base_prompt.py +0 -0
  39. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/prompt/mm_prompt.py +0 -0
  40. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/prompt/selfask_examplars.py +0 -0
  41. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/prompt/trace_examplars.py +0 -0
  42. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/refiner/__init__.py +0 -0
  43. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/refiner/kg_refiner.py +0 -0
  44. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/refiner/llmlingua_compressor.py +0 -0
  45. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/refiner/refiner.py +0 -0
  46. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/refiner/selective_context_compressor.py +0 -0
  47. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/__init__.py +0 -0
  48. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/__main__.py +0 -0
  49. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/index_builder.py +0 -0
  50. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/reranker.py +0 -0
  51. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/retriever/utils.py +0 -0
  52. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/utils/__init__.py +0 -0
  53. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/utils/constants.py +0 -0
  54. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/utils/pred_parse.py +0 -0
  55. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag/utils/utils.py +0 -0
  56. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag_dev.egg-info/SOURCES.txt +0 -0
  57. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag_dev.egg-info/dependency_links.txt +0 -0
  58. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag_dev.egg-info/requires.txt +0 -0
  59. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/flashrag_dev.egg-info/top_level.txt +0 -0
  60. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/pyproject.toml +0 -0
  61. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/setup.cfg +0 -0
  62. {flashrag_dev-0.1.4.dev20250423 → flashrag_dev-0.1.4.dev20250425}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag_dev
3
- Version: 0.1.4.dev20250423
3
+ Version: 0.1.4.dev20250425
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
@@ -24,7 +24,7 @@ class Encoder:
24
24
  Encodes a list of queries into embeddings.
25
25
  """
26
26
 
27
- def __init__(self, model_name, model_path, pooling_method, max_length, use_fp16, instruction, silent=False):
27
+ def __init__(self, model_name, model_path, pooling_method, max_length, use_fp16=True, instruction="", silent=False):
28
28
  self.model_name = model_name
29
29
  self.model_path = model_path
30
30
  self.pooling_method = pooling_method
@@ -44,7 +44,9 @@ class Encoder:
44
44
  )
45
45
  inputs = {k: v.cuda() for k, v in inputs.items()}
46
46
 
47
- if "T5" in type(self.model).__name__ or (isinstance(self.model, torch.nn.DataParallel) and "T5" in type(self.model.module).__name__):
47
+ if "T5" in type(self.model).__name__ or (
48
+ isinstance(self.model, torch.nn.DataParallel) and "T5" in type(self.model.module).__name__
49
+ ):
48
50
  # T5-based retrieval model
49
51
  decoder_input_ids = torch.zeros((inputs["input_ids"].shape[0], 1), dtype=torch.long).to(
50
52
  inputs["input_ids"].device
@@ -54,11 +56,9 @@ class Encoder:
54
56
 
55
57
  else:
56
58
  output = self.model(**inputs, return_dict=True)
57
- pooler_output = output.get('pooler_output', None)
58
- last_hidden_state = output.get('last_hidden_state', None)
59
- query_emb = pooling(
60
- pooler_output, last_hidden_state, inputs["attention_mask"], self.pooling_method
61
- )
59
+ pooler_output = output.get("pooler_output", None)
60
+ last_hidden_state = output.get("last_hidden_state", None)
61
+ query_emb = pooling(pooler_output, last_hidden_state, inputs["attention_mask"], self.pooling_method)
62
62
  if "dpr" not in self.model_name:
63
63
  query_emb = torch.nn.functional.normalize(query_emb, dim=-1)
64
64
  query_emb = query_emb.detach().cpu().numpy()
@@ -117,7 +117,11 @@ class STEncoder:
117
117
  def encode(self, query_list: Union[List[str], str], batch_size=64, is_query=True) -> np.ndarray:
118
118
  query_list = parse_query(self.model_name, query_list, self.instruction, is_query)
119
119
  query_emb = self.model.encode(
120
- query_list, batch_size=batch_size, convert_to_numpy=True, normalize_embeddings=True, show_progress_bar=not self.silent
120
+ query_list,
121
+ batch_size=batch_size,
122
+ convert_to_numpy=True,
123
+ normalize_embeddings=True,
124
+ show_progress_bar=not self.silent,
121
125
  )
122
126
  query_emb = query_emb.astype(np.float32, order="C")
123
127
 
@@ -173,11 +177,10 @@ class ClipEncoder:
173
177
  # set model max length for model that not specified in config.json
174
178
  if self.processor is not None and self.processor.tokenizer.model_max_length > 100000:
175
179
  try:
176
- model_max_length = config['text_config']['max_position_embeddings']
180
+ model_max_length = config["text_config"]["max_position_embeddings"]
177
181
  except:
178
182
  model_max_length = 512
179
- self.processor.tokenizer.model_max_length = model_max_length
180
-
183
+ self.processor.tokenizer.model_max_length = model_max_length
181
184
 
182
185
  @torch.inference_mode()
183
186
  def single_batch_encode(self, query_list: Union[List[str], str], modal="image") -> np.ndarray:
@@ -207,7 +210,7 @@ class ClipEncoder:
207
210
  @torch.inference_mode()
208
211
  def encode_image(self, image_list: List) -> np.ndarray:
209
212
  # Each item in image_list: PIL Image, local path, or URL
210
- if self.model_type == "CLIPModel" or self.model_type == 'ChineseCLIPModel':
213
+ if self.model_type == "CLIPModel" or self.model_type == "ChineseCLIPModel":
211
214
  # need handle image
212
215
  image_list = [parse_image(image) for image in image_list]
213
216
  inputs = self.processor(images=image_list, return_tensors="pt")
@@ -224,7 +227,7 @@ class ClipEncoder:
224
227
  @torch.inference_mode()
225
228
  def encode_text(self, text_list: List[str]) -> np.ndarray:
226
229
  # Each item in image_list: PIL Image, local path, or URL
227
- if self.model_type == "CLIPModel" or self.model_type == 'ChineseCLIPModel':
230
+ if self.model_type == "CLIPModel" or self.model_type == "ChineseCLIPModel":
228
231
  inputs = self.processor(
229
232
  text=text_list,
230
233
  padding=True,
@@ -305,7 +305,8 @@ class BM25Retriever(BaseTextRetriever):
305
305
  else:
306
306
  results = load_docs(self.corpus, [hit.docid for hit in hits])
307
307
  elif self.backend == "bm25s":
308
- query_tokens = self.tokenizer.tokenize([query], return_as="tuple", update_vocab=False)
308
+ # query_tokens = self.tokenizer.tokenize([query], return_as="tuple", update_vocab=False)
309
+ query_tokens = bm25s.tokenize([query])
309
310
  results, scores = self.searcher.retrieve(query_tokens, k=num)
310
311
  results = list(results[0])
311
312
  scores = list(scores[0])
@@ -327,7 +328,8 @@ class BM25Retriever(BaseTextRetriever):
327
328
  results.append(item_result)
328
329
  scores.append(item_score)
329
330
  elif self.backend == "bm25s":
330
- query_tokens = self.tokenizer.tokenize(query, return_as="tuple", update_vocab=False)
331
+ # query_tokens = self.tokenizer.tokenize(query, return_as="tuple", update_vocab=False)
332
+ query_tokens = bm25s.tokenize(query)
331
333
  results, scores = self.searcher.retrieve(query_tokens, k=num)
332
334
  else:
333
335
  assert False, "Invalid bm25 backend!"
@@ -0,0 +1 @@
1
+ __version__ = "0.1.4dev20250425"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flashrag-dev
3
- Version: 0.1.4.dev20250423
3
+ Version: 0.1.4.dev20250425
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.4dev20250423"