Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,7 +50,17 @@ class DocumentRetrievalAndGeneration:
|
|
| 50 |
|
| 51 |
def create_faiss_index(self):
|
| 52 |
all_texts = [split.page_content for split in self.all_splits]
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
index = faiss.IndexFlatL2(embeddings.shape[1])
|
| 55 |
index.add(embeddings)
|
| 56 |
gpu_resource = faiss.StandardGpuResources()
|
|
|
|
| 50 |
|
| 51 |
def create_faiss_index(self):
|
| 52 |
all_texts = [split.page_content for split in self.all_splits]
|
| 53 |
+
|
| 54 |
+
batch_size = 32
|
| 55 |
+
all_embeddings = []
|
| 56 |
+
|
| 57 |
+
for i in range(0, len(all_texts), batch_size):
|
| 58 |
+
batch_texts = all_texts[i:i+batch_size]
|
| 59 |
+
batch_embeddings = self.encode_texts(batch_texts)
|
| 60 |
+
all_embeddings.append(batch_embeddings)
|
| 61 |
+
print(f"Processed batch {i//batch_size + 1}/{(len(all_texts) + batch_size - 1)//batch_size}")
|
| 62 |
+
|
| 63 |
+
embeddings = np.vstack(all_embeddings)
|
| 64 |
index = faiss.IndexFlatL2(embeddings.shape[1])
|
| 65 |
index.add(embeddings)
|
| 66 |
gpu_resource = faiss.StandardGpuResources()
|