Spaces:
Sleeping
Sleeping
alvinhenrick
commited on
Commit
•
5c6185a
1
Parent(s):
d5d304c
fix local cache bug
Browse files- medirag/cache/local.py +4 -13
medirag/cache/local.py
CHANGED
@@ -31,19 +31,10 @@ class SemanticCaching:
|
|
31 |
with open(self.json_file, 'r') as file:
|
32 |
local_cache = json.load(file)
|
33 |
if 'embeddings' in local_cache and len(local_cache['embeddings']) > 0:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
# The array is originally of shape (1, n, d), we need it to be (n, d)
|
39 |
-
if embeddings.ndim == 3:
|
40 |
-
embeddings = embeddings.reshape(-1, embeddings.shape[-1])
|
41 |
-
|
42 |
-
# Normalize the embeddings since we are using cosine similarity (IndexFlatIP)
|
43 |
-
faiss.normalize_L2(embeddings)
|
44 |
-
|
45 |
-
# Add the embeddings to the Faiss index
|
46 |
-
self.vector_index.add(embeddings)
|
47 |
return local_cache
|
48 |
else:
|
49 |
return local_cache
|
|
|
31 |
with open(self.json_file, 'r') as file:
|
32 |
local_cache = json.load(file)
|
33 |
if 'embeddings' in local_cache and len(local_cache['embeddings']) > 0:
|
34 |
+
for embedding in local_cache['embeddings']:
|
35 |
+
_embedding = np.array(embedding, dtype=np.float32)
|
36 |
+
# Add the embeddings to the Faiss index
|
37 |
+
self.vector_index.add(_embedding)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
return local_cache
|
39 |
else:
|
40 |
return local_cache
|