Ajaykanth Maddi commited on
Commit ·
ae3a183
1
Parent(s): e070e90
Updated the FAISS path
Browse files- ragbench.py +18 -18
ragbench.py
CHANGED
|
@@ -158,7 +158,7 @@ class RAGSystem:
|
|
| 158 |
REQUIRED_FILES = [
|
| 159 |
"index.faiss",
|
| 160 |
"index.pkl",
|
| 161 |
-
|
| 162 |
]
|
| 163 |
|
| 164 |
try:
|
|
@@ -189,24 +189,24 @@ class RAGSystem:
|
|
| 189 |
except Exception as e:
|
| 190 |
print(f"Error loading index: {e}")
|
| 191 |
|
| 192 |
-
#
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
|
| 211 |
def store_embeddings_database(self, save_faiss: bool = True):
|
| 212 |
"""Build and store FAISS index from chunks"""
|
|
|
|
| 158 |
REQUIRED_FILES = [
|
| 159 |
"index.faiss",
|
| 160 |
"index.pkl",
|
| 161 |
+
"langchain_docs.pkl" # Include if needed
|
| 162 |
]
|
| 163 |
|
| 164 |
try:
|
|
|
|
| 189 |
except Exception as e:
|
| 190 |
print(f"Error loading index: {e}")
|
| 191 |
|
| 192 |
+
# Load langchain_docs for BM25
|
| 193 |
+
docs_path = os.path.join(index_dir, "langchain_docs.pkl")
|
| 194 |
+
if os.path.exists(docs_path):
|
| 195 |
+
with open(docs_path, "rb") as f:
|
| 196 |
+
langchain_docs = pickle.load(f)
|
| 197 |
+
bm25 = BM25Retriever.from_documents(langchain_docs)
|
| 198 |
+
bm25.k = 20
|
| 199 |
|
| 200 |
+
self.hybrid_retriever = EnsembleRetriever(
|
| 201 |
+
retrievers=[
|
| 202 |
+
self.vector_store.as_retriever(search_kwargs={"k": 20}),
|
| 203 |
+
bm25
|
| 204 |
+
],
|
| 205 |
+
weights=[0.7, 0.3]
|
| 206 |
+
)
|
| 207 |
+
else:
|
| 208 |
+
print(f"docs.pkl not found at {docs_path}, using only FAISS retriever.")
|
| 209 |
+
self.hybrid_retriever = self.vector_store.as_retriever(search_kwargs={"k": 20})
|
| 210 |
|
| 211 |
def store_embeddings_database(self, save_faiss: bool = True):
|
| 212 |
"""Build and store FAISS index from chunks"""
|