Spaces:
Sleeping
Sleeping
Commit ·
b49169b
1
Parent(s): d94f39b
app.py
CHANGED
|
@@ -125,7 +125,7 @@ def answer(system: str, context: str, question: str, user_id="demo", history="No
|
|
| 125 |
sims = torch.matmul(store["vecs"], q_vec) # [N]
|
| 126 |
if sims.numel() == 0:
|
| 127 |
return "Knowledge base is empty or corrupted."
|
| 128 |
-
k = min(4,
|
| 129 |
idxs = torch.topk(sims, k=k).indices.tolist()
|
| 130 |
context_list += [store["texts"][i] for i in idxs]
|
| 131 |
elif history == "All":
|
|
@@ -160,7 +160,7 @@ def answer(system: str, context: str, question: str, user_id="demo", history="No
|
|
| 160 |
|
| 161 |
|
| 162 |
except Exception as e:
|
| 163 |
-
return f"Error in app.py: {e}, k={k}, q_vec.shape={q_vec.shape if 'q_vec' in locals() else 'N/A'}"
|
| 164 |
finally:
|
| 165 |
torch.cuda.empty_cache()
|
| 166 |
|
|
|
|
| 125 |
sims = torch.matmul(store["vecs"], q_vec) # [N]
|
| 126 |
if sims.numel() == 0:
|
| 127 |
return "Knowledge base is empty or corrupted."
|
| 128 |
+
k = min(4, store["vecs"].size(0))
|
| 129 |
idxs = torch.topk(sims, k=k).indices.tolist()
|
| 130 |
context_list += [store["texts"][i] for i in idxs]
|
| 131 |
elif history == "All":
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
except Exception as e:
|
| 163 |
+
return f"Error in app.py: {e}, k={k}, sims.numel()={sims.numel()}, q_vec.shape={q_vec.shape if 'q_vec' in locals() else 'N/A'}"
|
| 164 |
finally:
|
| 165 |
torch.cuda.empty_cache()
|
| 166 |
|