Jeevant10 commited on
Commit
80b3e44
·
1 Parent(s): d2029d7

Add: handle case of no valid chunks in build_from_documents method

Browse files
Files changed (1) hide show
  1. src/vectorstore.py +7 -2
src/vectorstore.py CHANGED
@@ -32,8 +32,13 @@ class FaissVectorStore:
32
  chunk_overlap=self.chunk_overlap,
33
  )
34
  chunks = emb_pipe.chunk_documents(documents)
35
- embeddings = emb_pipe.embed_chunks(chunks)
36
- metadatas = [{"texts": chunk.page_content} for chunk in chunks]
 
 
 
 
 
37
  self.add_embeddings(np.array(embeddings).astype("float32"), metadatas)
38
  self.save()
39
  print(f"[INFO] Vector Store built and saved to {self.persist_dir}")
 
32
  chunk_overlap=self.chunk_overlap,
33
  )
34
  chunks = emb_pipe.chunk_documents(documents)
35
+ embeddings, valid_chunks = emb_pipe.embed_chunks(chunks)
36
+
37
+ if len(valid_chunks) == 0:
38
+ print("[WARNING] No valid chunks were embedded. Vector store will not be updated.")
39
+ return
40
+
41
+ metadatas = [{"texts": chunk.page_content} for chunk in valid_chunks]
42
  self.add_embeddings(np.array(embeddings).astype("float32"), metadatas)
43
  self.save()
44
  print(f"[INFO] Vector Store built and saved to {self.persist_dir}")