Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,7 +113,10 @@ def get_top_chunks(query, chunk_embeddings, text_chunks):
|
|
| 113 |
|
| 114 |
# Normalize all chunk embeddings to unit length for consistent comparison
|
| 115 |
# chunk_embeddings_normalized = chunk_embeddings / chunk_embeddings.norm(dim=1, keepdim=True)
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
# Calculate cosine similarity between query and all chunks using matrix multiplication
|
| 118 |
similarities = torch.matmul(chunk_embeddings_normalized, query_embedding_normalized)
|
| 119 |
|
|
|
|
| 113 |
|
| 114 |
# Normalize all chunk embeddings to unit length for consistent comparison
|
| 115 |
# chunk_embeddings_normalized = chunk_embeddings / chunk_embeddings.norm(dim=1, keepdim=True)
|
| 116 |
+
if chunk_embeddings.ndim == 1:
|
| 117 |
+
chunk_embeddings_normalized = chunk_embeddings / chunk_embeddings.norm()
|
| 118 |
+
else:
|
| 119 |
+
chunk_embeddings_normalized = chunk_embeddings / chunk_embeddings.norm(dim=1, keepdim=True)
|
| 120 |
# Calculate cosine similarity between query and all chunks using matrix multiplication
|
| 121 |
similarities = torch.matmul(chunk_embeddings_normalized, query_embedding_normalized)
|
| 122 |
|