Chris4K commited on
Commit
52d5b06
1 Parent(s): 7803d2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -258,15 +258,20 @@ def search_embeddings(chunks, embedding_model, vector_store_type, search_type, q
258
  results = sorted(results, key=score_result, reverse=True)
259
  end_time = time.time()
260
 
261
- # Extract embeddings for each result and store them in the DataFrame
262
- embeddings = [embedding_model.embed_query(doc.page_content) for doc in results]
263
-
 
 
 
 
 
264
  # Create a DataFrame with the results and embeddings
265
  results_df = pd.DataFrame({
266
  'content': [doc.page_content for doc in results],
267
  'embedding': embeddings
268
  })
269
-
270
  return results_df, end_time - start_time, vector_store, results
271
 
272
  # Evaluation Metrics
@@ -393,6 +398,8 @@ def compare_embeddings(file, query, model_types, model_names, split_strategy, ch
393
  )
394
 
395
  # Storing embeddings into the results for future use
 
 
396
  result_embeddings = [doc.metadata['embedding'] for doc in results_raw] # Adjust this based on the actual attribute names
397
  # result_embeddings = [doc['embedding'] for doc in results_raw] # Assuming each result has an embedding
398
 
 
258
  results = sorted(results, key=score_result, reverse=True)
259
  end_time = time.time()
260
 
261
+ # Check if embeddings are available
262
+ embeddings = []
263
+ for doc in results:
264
+ if hasattr(doc, 'embedding'):
265
+ embeddings.append(doc.embedding) # Use the embedding if it exists
266
+ else:
267
+ embeddings.append(None) # Append None if embedding doesn't exist
268
+
269
  # Create a DataFrame with the results and embeddings
270
  results_df = pd.DataFrame({
271
  'content': [doc.page_content for doc in results],
272
  'embedding': embeddings
273
  })
274
+
275
  return results_df, end_time - start_time, vector_store, results
276
 
277
  # Evaluation Metrics
 
398
  )
399
 
400
  # Storing embeddings into the results for future use
401
+ for doc in results_raw:
402
+ print(doc) # or print(dir(doc)) to see available attributes
403
  result_embeddings = [doc.metadata['embedding'] for doc in results_raw] # Adjust this based on the actual attribute names
404
  # result_embeddings = [doc['embedding'] for doc in results_raw] # Assuming each result has an embedding
405