Update index.py

This commit is contained in:
Stéphan Peccini 2025-05-18 19:27:14 +02:00
parent 89d167a2f8
commit 50042f6655

View File

@ -98,7 +98,9 @@ def main():
) )
model = BGEM3FlagModel(MODEL_NAME, device="cpu") model = BGEM3FlagModel(MODEL_NAME, device="cpu")
emb = model.encode(new_docs, batch_size=BATCH, return_dict=False) emb_out = model.encode(new_docs, batch_size=BATCH)
# FlagEmbedding renvoie soit un ndarray, soit un dict {"embedding": …}
emb = emb_out["embedding"] if isinstance(emb_out, dict) else emb_out
emb = emb.astype("float32") emb = emb.astype("float32")
emb /= np.linalg.norm(emb, axis=1, keepdims=True) + 1e-12 emb /= np.linalg.norm(emb, axis=1, keepdims=True) + 1e-12