From 21e0df937f57e14e23d2f605019be01658fe7b3a Mon Sep 17 00:00:00 2001 From: Neo Zhao Date: Tue, 16 Jan 2024 03:13:14 +0800 Subject: [PATCH] community[patch]: fix a bug that mistakenly handle zip iterator in FAISS.from_embeddings (#16020) **Description**: `zip` is iterator that will only produce result once, so the previous code will cause the `embeddings` to be an empty list. **Issue**: I could not find a related issue. **Dependencies**: this PR does not introduce or affect dependencies. --------- Co-authored-by: Bagatur --- libs/community/langchain_community/vectorstores/faiss.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/community/langchain_community/vectorstores/faiss.py b/libs/community/langchain_community/vectorstores/faiss.py index 4e7e5619e1..8ca609b725 100644 --- a/libs/community/langchain_community/vectorstores/faiss.py +++ b/libs/community/langchain_community/vectorstores/faiss.py @@ -986,11 +986,10 @@ class FAISS(VectorStore): text_embedding_pairs = zip(texts, text_embeddings) faiss = FAISS.from_embeddings(text_embedding_pairs, embeddings) """ - texts = [t[0] for t in text_embeddings] - embeddings = [t[1] for t in text_embeddings] + texts, embeddings = zip(*text_embeddings) return cls.__from( - texts, - embeddings, + list(texts), + list(embeddings), embedding, metadatas=metadatas, ids=ids,