Spaces:

syedmudassir16 commited on
Commit
c47e967
1 Parent(s): cb9ab78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -41,14 +41,20 @@ class DocumentRetrievalAndGeneration:
41
 
42
  def create_faiss_index(self):
43
  all_texts = [split.page_content for split in self.all_splits]
44
- embeddings = self.embeddings.encode(all_texts, convert_to_tensor=True).cpu().numpy()
45
- vectordb = FAISS.from_embeddings(
46
- texts=all_texts, # Provide texts separately
47
- embeddings=embeddings, # Provide embeddings separately
48
- model=self.embeddings,
49
- metadatas=[{"source": f"doc_{i}"} for i in range(len(all_texts))]
 
 
 
 
 
 
 
50
  )
51
- return vectordb
52
 
53
  def initialize_llm(self, model_id):
54
  quantization_config = BitsAndBytesConfig(
 
41
 
42
  def create_faiss_index(self):
43
  all_texts = [split.page_content for split in self.all_splits]
44
+ embeddings = self.embeddings.encode(all_texts)
45
+
46
+ # Create FAISS index
47
+ vector_dimension = embeddings.shape[1]
48
+ index = faiss.IndexFlatL2(vector_dimension)
49
+ index.add(embeddings)
50
+
51
+ # Create and return FAISS object
52
+ return FAISS(
53
+ embedding_function=self.embeddings.encode,
54
+ index=index,
55
+ docstore=self.all_splits,
56
+ index_to_docstore_id={i: i for i in range(len(self.all_splits))}
57
  )
 
58
 
59
  def initialize_llm(self, model_id):
60
  quantization_config = BitsAndBytesConfig(