Penality commited on
Commit
d7de38d
·
verified ·
1 Parent(s): 5cffc5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -110,17 +110,22 @@ def retrieve_document(query):
110
  return None
111
 
112
  try:
113
- print(embeddings_.content)
114
- # Convert response content to a byte stream
 
 
 
 
115
  byte_stream = io.BytesIO(embeddings_.content)
116
-
117
- # Load FAISS index from byte stream
118
- index = faiss.deserialize_index(byte_stream.read())
119
-
120
- print(f"Successfully loaded FAISS index with {index.ntotal} vectors.")
121
-
122
- # Now you can perform retrieval using `index.search()`
123
- # return index
 
124
 
125
  except Exception as e:
126
  print(f"Error loading FAISS index: {e}")
 
110
  return None
111
 
112
  try:
113
+ print("Response content length:", len(embeddings_.content)) # Debugging
114
+
115
+ if len(embeddings_.content) == 0:
116
+ raise ValueError("Received empty FAISS index file")
117
+
118
+ # Convert response content to a byte stream
119
  byte_stream = io.BytesIO(embeddings_.content)
120
+
121
+ # Write the received binary content to a temporary file
122
+ with open("downloaded_index.bin", "wb") as f:
123
+ f.write(byte_stream.read())
124
+
125
+ # Load FAISS index from file
126
+ index = faiss.read_index("downloaded_index.bin")
127
+
128
+ print(f"✅ Successfully loaded FAISS index with {index.ntotal} vectors.")
129
 
130
  except Exception as e:
131
  print(f"Error loading FAISS index: {e}")