cryogenic22 commited on
Commit
499ee3c
·
verified ·
1 Parent(s): 67f2631

Update utils/database.py

Browse files
Files changed (1) hide show
  1. utils/database.py +20 -0
utils/database.py CHANGED
@@ -236,6 +236,26 @@ def force_recreate_collections_tables(conn: sqlite3.Connection) -> bool:
236
  st.error(f"Error recreating collections tables: {e}")
237
  return False
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  def get_uncategorized_documents(conn: sqlite3.Connection) -> List[Dict]:
240
  """Get documents that aren't in any collection."""
241
  try:
 
236
  st.error(f"Error recreating collections tables: {e}")
237
  return False
238
 
239
+
240
+ def get_existing_vector_store(document_ids: List[int]) -> Optional[FAISS]:
241
+ """Retrieve existing vector store if available."""
242
+ try:
243
+ if st.session_state.get('vector_store'):
244
+ current_docs = set(document_ids)
245
+ stored_docs = set(
246
+ metadata['document_id']
247
+ for metadata in st.session_state.vector_store.docstore.get_all_metadatas()
248
+ )
249
+
250
+ # If the document sets match, reuse existing vector store
251
+ if current_docs == stored_docs:
252
+ return st.session_state.vector_store
253
+
254
+ return None
255
+ except Exception as e:
256
+ st.error(f"Error checking vector store: {e}")
257
+ return None
258
+
259
  def get_uncategorized_documents(conn: sqlite3.Connection) -> List[Dict]:
260
  """Get documents that aren't in any collection."""
261
  try: