KoonJamesZ commited on
Commit
3359dd0
·
verified ·
1 Parent(s): 0d9f7d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -15,34 +15,34 @@ df['embeding_context'] = df['embeding_context'].astype(str).fillna('')
15
  # Filter out any rows where 'embeding_context' might be empty or invalid
16
  df = df[df['embeding_context'] != '']
17
 
18
- # Encode the 'embeding_context' column
19
- embedding_contexts = df['embeding_context'].tolist()
20
- embeddings_csv = model.encode(embedding_contexts, batch_size=12, max_length=1024)['dense_vecs']
21
-
22
- # Convert embeddings to numpy array
23
- embeddings_np = np.array(embeddings_csv).astype('float32')
24
-
25
- # FAISS index file path
26
- index_file_path = 'vector_store_bge_m3.index'
27
-
28
- # Check if FAISS index file already exists
29
- if os.path.exists(index_file_path):
30
- # Load the existing FAISS index from file
31
- index = faiss.read_index(index_file_path)
32
- print("FAISS index loaded from file.")
33
- else:
34
- # Initialize FAISS index (for L2 similarity)
35
- dim = embeddings_np.shape[1]
36
- index = faiss.IndexFlatL2(dim)
37
-
38
- # Add embeddings to the FAISS index
39
- index.add(embeddings_np)
40
-
41
- # Save the FAISS index to a file for future use
42
- faiss.write_index(index, index_file_path)
43
- print("FAISS index created and saved to file.")
44
-
45
- index = faiss.read_index(index_file_path)
46
 
47
 
48
  # Function to perform search and return all columns
 
15
  # Filter out any rows where 'embeding_context' might be empty or invalid
16
  df = df[df['embeding_context'] != '']
17
 
18
+ # # Encode the 'embeding_context' column
19
+ # embedding_contexts = df['embeding_context'].tolist()
20
+ # embeddings_csv = model.encode(embedding_contexts, batch_size=12, max_length=1024)['dense_vecs']
21
+
22
+ # # Convert embeddings to numpy array
23
+ # embeddings_np = np.array(embeddings_csv).astype('float32')
24
+
25
+ # # FAISS index file path
26
+ # index_file_path = 'vector_store_bge_m3.index'
27
+
28
+ # # Check if FAISS index file already exists
29
+ # if os.path.exists(index_file_path):
30
+ # # Load the existing FAISS index from file
31
+ # index = faiss.read_index(index_file_path)
32
+ # print("FAISS index loaded from file.")
33
+ # else:
34
+ # # Initialize FAISS index (for L2 similarity)
35
+ # dim = embeddings_np.shape[1]
36
+ # index = faiss.IndexFlatL2(dim)
37
+
38
+ # # Add embeddings to the FAISS index
39
+ # index.add(embeddings_np)
40
+
41
+ # # Save the FAISS index to a file for future use
42
+ # faiss.write_index(index, index_file_path)
43
+ # print("FAISS index created and saved to file.")
44
+
45
+ index = faiss.read_index('vector_store_bge_m3.index')
46
 
47
 
48
  # Function to perform search and return all columns