alvinhenrick commited on
Commit
5c6185a
1 Parent(s): d5d304c

fix local cache bug

Browse files
Files changed (1) hide show
  1. 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
- # Convert the list of embeddings to a numpy array
35
- embeddings = np.array(local_cache['embeddings'], dtype=np.float32)
36
-
37
- # Reshape embeddings to ensure 2D shape
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