Ajaykanth Maddi commited on
Commit
68f5761
·
1 Parent(s): 6cd14c4

Changes to use RAG26-Demo as dataset

Browse files
Files changed (1) hide show
  1. ragbench.py +28 -29
ragbench.py CHANGED
@@ -140,40 +140,39 @@ class RAGSystem:
140
  # 1. Define all required files
141
  REQUIRED_FILES = [
142
  "index.faiss",
143
- "index.pkl",
144
- "langchain_docs.pkl" # Include if needed
145
  ]
146
 
147
  folder_path = f"{self.subset}/embeddings/{self.retriever_model_name.replace('/', ':')}"
148
  print(f"Folder path: {folder_path}")
149
- # try:
150
- # # 2. Download the embeddings files to cache
151
- # downloaded_files = []
152
- # for filename in REQUIRED_FILES:
153
- # file_path = hf_hub_download(
154
- # repo_id=repo_id,
155
- # filename=f"{folder_path}/{filename}",
156
- # repo_type=HF_REPO_TYPE,
157
- # local_dir=folder_path,
158
- # token=os.getenv("HF_TOKEN")
159
- # )
160
- # downloaded_files.append(file_path)
161
- # print(f"Downloaded: {filename} → {file_path}")
162
-
163
- # # 3. Get the common directory
164
- # index_dir = os.path.dirname(downloaded_files[0])
165
- # print(f"Final index directory: {index_dir}")
166
- # print(f"Files in directory: {os.listdir(index_dir)}")
167
-
168
- # # 4. Load FAISS
169
- # self.vector_store = FAISS.load_local(
170
- # folder_path=index_dir,
171
- # embeddings=self.embedder,
172
- # allow_dangerous_deserialization=True
173
- # )
174
 
175
- # except Exception as e:
176
- # print(f"Error loading index: {e}")
177
 
178
  # # Load langchain_docs for BM25
179
  # docs_path = os.path.join(index_dir, f"chunks_{self.strategy}.pkl")
 
140
  # 1. Define all required files
141
  REQUIRED_FILES = [
142
  "index.faiss",
143
+ "index.pkl"
 
144
  ]
145
 
146
  folder_path = f"{self.subset}/embeddings/{self.retriever_model_name.replace('/', ':')}"
147
  print(f"Folder path: {folder_path}")
148
+ try:
149
+ # 2. Download the embeddings files to cache
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,
157
+ token=os.getenv("HF_TOKEN")
158
+ )
159
+ downloaded_files.append(file_path)
160
+ print(f"Downloaded: {filename} → {file_path}")
161
+
162
+ # 3. Get the common directory
163
+ index_dir = os.path.dirname(downloaded_files[0])
164
+ print(f"Final index directory: {index_dir}")
165
+ print(f"Files in directory: {os.listdir(index_dir)}")
166
+
167
+ # 4. Load FAISS
168
+ self.vector_store = FAISS.load_local(
169
+ folder_path=index_dir,
170
+ embeddings=self.embedder,
171
+ allow_dangerous_deserialization=True
172
+ )
173
 
174
+ except Exception as e:
175
+ print(f"Error loading index: {e}")
176
 
177
  # # Load langchain_docs for BM25
178
  # docs_path = os.path.join(index_dir, f"chunks_{self.strategy}.pkl")