Shreyas094 commited on
Commit
7efff23
·
verified ·
1 Parent(s): b45f3cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -455,20 +455,33 @@ def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=
455
  if os.path.exists("faiss_database"):
456
  logging.info("Loading FAISS database")
457
  database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
 
 
 
 
 
458
  else:
459
  logging.warning("No FAISS database found")
460
  yield "No documents available. Please upload PDF documents to answer questions."
461
  return
462
 
463
- retriever = database.as_retriever(search_kwargs={"k": 20}) # Increased k to 10
464
  logging.info(f"Retrieving relevant documents for query: {query}")
465
  relevant_docs = retriever.get_relevant_documents(query)
466
  logging.info(f"Number of relevant documents retrieved: {len(relevant_docs)}")
467
 
 
 
 
 
468
  # Filter relevant_docs based on selected documents
469
  filtered_docs = [doc for doc in relevant_docs if doc.metadata["source"] in selected_docs]
470
  logging.info(f"Number of filtered documents: {len(filtered_docs)}")
471
 
 
 
 
 
472
  if not filtered_docs:
473
  logging.warning(f"No relevant information found in the selected documents: {selected_docs}")
474
  yield "No relevant information found in the selected documents. Please try selecting different documents or rephrasing your query."
 
455
  if os.path.exists("faiss_database"):
456
  logging.info("Loading FAISS database")
457
  database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
458
+
459
+ # Log the contents of the FAISS database
460
+ logging.info(f"FAISS database contains {len(database.docstore._dict)} documents")
461
+ for doc_id, doc in database.docstore._dict.items():
462
+ logging.info(f"Document ID: {doc_id}, Source: {doc.metadata['source']}")
463
  else:
464
  logging.warning("No FAISS database found")
465
  yield "No documents available. Please upload PDF documents to answer questions."
466
  return
467
 
468
+ retriever = database.as_retriever(search_kwargs={"k": 20})
469
  logging.info(f"Retrieving relevant documents for query: {query}")
470
  relevant_docs = retriever.get_relevant_documents(query)
471
  logging.info(f"Number of relevant documents retrieved: {len(relevant_docs)}")
472
 
473
+ # Log details of retrieved documents
474
+ for i, doc in enumerate(relevant_docs):
475
+ logging.info(f"Relevant doc {i}: Source: {doc.metadata['source']}, Content preview: {doc.page_content[:100]}...")
476
+
477
  # Filter relevant_docs based on selected documents
478
  filtered_docs = [doc for doc in relevant_docs if doc.metadata["source"] in selected_docs]
479
  logging.info(f"Number of filtered documents: {len(filtered_docs)}")
480
 
481
+ # Log details of filtered documents
482
+ for i, doc in enumerate(filtered_docs):
483
+ logging.info(f"Filtered doc {i}: Source: {doc.metadata['source']}, Content preview: {doc.page_content[:100]}...")
484
+
485
  if not filtered_docs:
486
  logging.warning(f"No relevant information found in the selected documents: {selected_docs}")
487
  yield "No relevant information found in the selected documents. Please try selecting different documents or rephrasing your query."