Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -76,17 +76,19 @@ def retrieve_and_generate(question):
|
|
76 |
# Embed the question
|
77 |
question_embedding = embed_question(question, model, tokenizer)
|
78 |
|
|
|
|
|
|
|
79 |
# Search in FAISS index
|
80 |
try:
|
81 |
-
if question_embedding.ndim == 2 and question_embedding.shape[0] == 1:
|
82 |
-
logging.debug("Correct question embedding shape for FAISS search.")
|
83 |
-
else:
|
84 |
-
logging.error(f"Incorrect question embedding shape: {question_embedding.shape}")
|
85 |
_, indices = gpu_index.search(question_embedding, k=1)
|
|
|
|
|
|
|
86 |
logging.debug(f"Indices found: {indices}")
|
87 |
except Exception as e:
|
88 |
logging.error(f"Error during FAISS search: {e}")
|
89 |
-
return "An error occurred during search
|
90 |
|
91 |
# Retrieve the most relevant document
|
92 |
try:
|
|
|
76 |
# Embed the question
|
77 |
question_embedding = embed_question(question, model, tokenizer)
|
78 |
|
79 |
+
# Ensure the embedding is in the correct format for FAISS search
|
80 |
+
question_embedding = question_embedding.astype(np.float32)
|
81 |
+
|
82 |
# Search in FAISS index
|
83 |
try:
|
|
|
|
|
|
|
|
|
84 |
_, indices = gpu_index.search(question_embedding, k=1)
|
85 |
+
if indices.size == 0:
|
86 |
+
logging.error("No results found in FAISS search.")
|
87 |
+
return "No relevant document found."
|
88 |
logging.debug(f"Indices found: {indices}")
|
89 |
except Exception as e:
|
90 |
logging.error(f"Error during FAISS search: {e}")
|
91 |
+
return f"An error occurred during search: {e}"
|
92 |
|
93 |
# Retrieve the most relevant document
|
94 |
try:
|