Ajaykanth Maddi commited on
Commit
a7a7df6
·
1 Parent(s): f836d6d

Updated the FAISS path

Browse files
Files changed (1) hide show
  1. ragbench.py +36 -15
ragbench.py CHANGED
@@ -150,24 +150,45 @@ class RAGSystem:
150
  encode_kwargs={'normalize_embeddings': True}
151
  )
152
 
153
- # Define repository and file naming pattern on Hugging Face Hub
154
- repo_id = "bfrogs/rag26-emanual" # Replace with your HF repo
155
- filename = f"faiss_index_{self.subset}_{self.dataset_type}_{self.strategy}/index.faiss"
156
 
157
- # Download from Hugging Face Hub
158
- index_path = hf_hub_download(
159
- repo_id=repo_id,
160
- filename=filename,
161
- repo_type="dataset", # Specify as dataset to avoid confusion
162
- cache_dir="hf_cache", # Local cache directory
163
- token=os.getenv("HF_TOKEN") # Get token from environment
164
- )
165
 
166
- if os.path.exists(index_path):
167
- self.vector_store = FAISS.load_local(index_path, self.embedder, allow_dangerous_deserialization=True)
168
- else:
169
- print(f"FAISS index not found at: {index_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  self.store_embeddings_database()
 
 
 
 
 
 
171
 
172
  # Load langchain_docs for BM25
173
  docs_path = os.path.join(index_path, "langchain_docs.pkl")
 
150
  encode_kwargs={'normalize_embeddings': True}
151
  )
152
 
153
+ # Define repository and directory pattern on Hugging Face Hub
154
+ repo_id = "bfrogs/rag26-emanual"
155
+ index_dir = f"faiss_index_{self.subset}_{self.dataset_type}_{self.strategy}"
156
 
157
+ # # Download from Hugging Face Hub
158
+ # index_path = hf_hub_download(
159
+ # repo_id=repo_id,
160
+ # filename=filename,
161
+ # repo_type="dataset", # Specify as dataset to avoid confusion
162
+ # cache_dir="hf_cache", # Local cache directory
163
+ # token=os.getenv("HF_TOKEN") # Get token from environment
164
+ # )
165
 
166
+ # Download all components of the FAISS index
167
+ try:
168
+ # Download each component file
169
+ for component in ["index.faiss", "index.pkl"]: # Add other components if needed
170
+ hf_hub_download(
171
+ repo_id=repo_id,
172
+ filename=f"{index_dir}/{component}",
173
+ repo_type="dataset",
174
+ cache_dir="hf_cache",
175
+ token=os.getenv("HF_TOKEN")
176
+ )
177
+
178
+ # Load the index from the local cache directory
179
+ cache_path = os.path.join("hf_cache", "models--bfrogs--rag26-emanual", "snapshots", "11157ec499368516cb1c49db0d5cd854919ae17c", index_dir)
180
+ self.vector_store = FAISS.load_local(cache_path, self.embedder, allow_dangerous_deserialization=True)
181
+
182
+ except Exception as e:
183
+ print(f"Failed to download or load FAISS index: {e}")
184
+ print("Falling back to creating new embeddings...")
185
  self.store_embeddings_database()
186
+
187
+ # if os.path.exists(index_path):
188
+ # self.vector_store = FAISS.load_local(index_path, self.embedder, allow_dangerous_deserialization=True)
189
+ # else:
190
+ # print(f"FAISS index not found at: {index_path}")
191
+ # self.store_embeddings_database()
192
 
193
  # Load langchain_docs for BM25
194
  docs_path = os.path.join(index_path, "langchain_docs.pkl")