Ajaykanth Maddi commited on
Commit
705ed9c
·
1 Parent(s): b95dbac

Changes to use RAG26-Demo as dataset

Browse files
Files changed (1) hide show
  1. ragbench.py +17 -8
ragbench.py CHANGED
@@ -104,14 +104,13 @@ class RAGSystem:
104
 
105
 
106
  def load_embeddings_database(self):
107
- repo_id = HF_DATASET_REPO_NAME
108
 
109
  try:
110
  # 1. First verify the repo exists
111
  print("Checking Hugging Face repository...")
112
  api = HfApi()
113
  repo_info = api.repo_info(
114
- repo_id=repo_id,
115
  repo_type=HF_REPO_TYPE, # or "model" if you used model repo
116
  token=os.getenv("HF_TOKEN")
117
  )
@@ -119,7 +118,7 @@ class RAGSystem:
119
 
120
  # 2. List files to verify filename
121
  repo_files = api.list_repo_files(
122
- repo_id=repo_id,
123
  repo_type=HF_REPO_TYPE,
124
  )
125
  for index, item in enumerate(repo_files):
@@ -150,7 +149,7 @@ class RAGSystem:
150
  downloaded_files = []
151
  for filename in REQUIRED_FILES:
152
  file_path = hf_hub_download(
153
- repo_id=repo_id,
154
  filename=f"{folder_path}/{filename}",
155
  repo_type=HF_REPO_TYPE,
156
  local_dir=folder_path,
@@ -178,12 +177,22 @@ class RAGSystem:
178
  print(f"Chunk directory: {chunkDir}")
179
 
180
  # Load langchain_docs for BM25
181
- docs_path = os.path.join(f"{HF_DATASET_REPO_NAME}", chunkDir, f"chunks_{self.strategy}.pkl")
182
  print(f"Chunk strategy {self.strategy} pickle path : {docs_path}")
183
 
184
- if os.path.exists(docs_path):
185
- with open(docs_path, "rb") as f:
 
 
 
 
 
 
 
 
186
  langchain_docs = pickle.load(f)
 
 
187
  bm25 = BM25Retriever.from_documents(langchain_docs)
188
  bm25.k = 20
189
 
@@ -195,7 +204,7 @@ class RAGSystem:
195
  weights=[0.7, 0.3]
196
  )
197
  else:
198
- print(f".pkl not found at {docs_path}, using only FAISS retriever.")
199
  self.hybrid_retriever = self.vector_store.as_retriever(search_kwargs={"k": 20})
200
 
201
  def store_embeddings_database(self, save_faiss: bool = True):
 
104
 
105
 
106
  def load_embeddings_database(self):
 
107
 
108
  try:
109
  # 1. First verify the repo exists
110
  print("Checking Hugging Face repository...")
111
  api = HfApi()
112
  repo_info = api.repo_info(
113
+ repo_id=HF_DATASET_REPO_NAME,
114
  repo_type=HF_REPO_TYPE, # or "model" if you used model repo
115
  token=os.getenv("HF_TOKEN")
116
  )
 
118
 
119
  # 2. List files to verify filename
120
  repo_files = api.list_repo_files(
121
+ repo_id=HF_DATASET_REPO_NAME,
122
  repo_type=HF_REPO_TYPE,
123
  )
124
  for index, item in enumerate(repo_files):
 
149
  downloaded_files = []
150
  for filename in REQUIRED_FILES:
151
  file_path = hf_hub_download(
152
+ repo_id=HF_DATASET_REPO_NAME,
153
  filename=f"{folder_path}/{filename}",
154
  repo_type=HF_REPO_TYPE,
155
  local_dir=folder_path,
 
177
  print(f"Chunk directory: {chunkDir}")
178
 
179
  # Load langchain_docs for BM25
180
+ docs_path = os.path.join(chunkDir, f"chunks_{self.strategy}.pkl")
181
  print(f"Chunk strategy {self.strategy} pickle path : {docs_path}")
182
 
183
+ # 1. Try to download the chunk file
184
+ chunk_path = hf_hub_download(
185
+ repo_id=HF_DATASET_REPO_NAME,
186
+ filename=docs_path,
187
+ repo_type=HF_REPO_TYPE,
188
+ token=os.getenv("HF_TOKEN")
189
+ )
190
+
191
+ if os.path.exists(chunk_path):
192
+ with open(chunk_path, "rb") as f:
193
  langchain_docs = pickle.load(f)
194
+ print(f"Successfully loaded chunks from {chunk_path}, length: {len(langchain_docs)}")
195
+
196
  bm25 = BM25Retriever.from_documents(langchain_docs)
197
  bm25.k = 20
198
 
 
204
  weights=[0.7, 0.3]
205
  )
206
  else:
207
+ print(f".pkl not found at {chunk_path}, using only FAISS retriever.")
208
  self.hybrid_retriever = self.vector_store.as_retriever(search_kwargs={"k": 20})
209
 
210
  def store_embeddings_database(self, save_faiss: bool = True):