Yoxas commited on
Commit
523f972
·
verified ·
1 Parent(s): 55ff761

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -61,7 +61,8 @@ def embed_question(question, model, tokenizer):
61
  with torch.no_grad():
62
  outputs = model(**inputs)
63
  embedding = outputs.last_hidden_state.mean(dim=1).cpu().numpy().astype(np.float32)
64
- logging.debug(f"Question embedding: {embedding}")
 
65
  return embedding
66
  except Exception as e:
67
  logging.error(f"Error embedding question: {e}")
@@ -77,6 +78,10 @@ def retrieve_and_generate(question):
77
 
78
  # Search in FAISS index
79
  try:
 
 
 
 
80
  _, indices = gpu_index.search(question_embedding, k=1)
81
  logging.debug(f"Indices found: {indices}")
82
  except Exception as e:
 
61
  with torch.no_grad():
62
  outputs = model(**inputs)
63
  embedding = outputs.last_hidden_state.mean(dim=1).cpu().numpy().astype(np.float32)
64
+ logging.debug(f"Question embedding shape: {embedding.shape}")
65
+ logging.debug(f"Question embedding content: {embedding}")
66
  return embedding
67
  except Exception as e:
68
  logging.error(f"Error embedding question: {e}")
 
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: