Spaces:
Paused
Paused
Update utils/database.py
Browse files- utils/database.py +13 -3
utils/database.py
CHANGED
|
@@ -144,12 +144,16 @@ def verify_vector_store(vector_store):
|
|
| 144 |
st.error(f"Vector store verification failed: {e}")
|
| 145 |
return False
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
def handle_document_upload(uploaded_files):
|
| 150 |
"""Handle document upload with improved chunking and progress tracking."""
|
| 151 |
try:
|
| 152 |
# Initialize session state variables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
if 'qa_system' not in st.session_state:
|
| 154 |
st.session_state.qa_system = None
|
| 155 |
if 'vector_store' not in st.session_state:
|
|
@@ -221,6 +225,8 @@ def handle_document_upload(uploaded_files):
|
|
| 221 |
return
|
| 222 |
|
| 223 |
progress_bar.progress(80)
|
|
|
|
|
|
|
| 224 |
|
| 225 |
# Initialize vector store (90% progress)
|
| 226 |
status_container.info("🔄 Initializing vector store...")
|
|
@@ -233,7 +239,9 @@ def handle_document_upload(uploaded_files):
|
|
| 233 |
|
| 234 |
st.session_state.vector_store = vector_store
|
| 235 |
progress_bar.progress(90)
|
| 236 |
-
|
|
|
|
|
|
|
| 237 |
# Initialize QA system (100% progress)
|
| 238 |
status_container.info("🔄 Setting up QA system...")
|
| 239 |
qa_system = initialize_qa_system(vector_store)
|
|
@@ -267,6 +275,7 @@ def handle_document_upload(uploaded_files):
|
|
| 267 |
st.session_state.vector_store = None
|
| 268 |
st.session_state.qa_system = None
|
| 269 |
st.session_state.chat_ready = False
|
|
|
|
| 270 |
|
| 271 |
finally:
|
| 272 |
if st.session_state.get('qa_system') is not None:
|
|
@@ -389,6 +398,7 @@ Accuracy: Double-check all information for accuracy and completeness before prov
|
|
| 389 |
st.error(f"Error initializing QA system: {e}")
|
| 390 |
return None
|
| 391 |
|
|
|
|
| 392 |
# FAISS vector store initialization
|
| 393 |
def initialize_faiss(embeddings, documents, document_names):
|
| 394 |
"""Initialize FAISS vector store."""
|
|
|
|
| 144 |
st.error(f"Vector store verification failed: {e}")
|
| 145 |
return False
|
| 146 |
|
|
|
|
|
|
|
| 147 |
def handle_document_upload(uploaded_files):
|
| 148 |
"""Handle document upload with improved chunking and progress tracking."""
|
| 149 |
try:
|
| 150 |
# Initialize session state variables
|
| 151 |
+
# Initialize persistence manager
|
| 152 |
+
persistence = PersistenceManager()
|
| 153 |
+
|
| 154 |
+
# Generate a session ID based on timestamp and files
|
| 155 |
+
session_id = f"session_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
| 156 |
+
|
| 157 |
if 'qa_system' not in st.session_state:
|
| 158 |
st.session_state.qa_system = None
|
| 159 |
if 'vector_store' not in st.session_state:
|
|
|
|
| 225 |
return
|
| 226 |
|
| 227 |
progress_bar.progress(80)
|
| 228 |
+
# After chunking documents
|
| 229 |
+
persistence.save_chunks(chunks, chunk_metadatas, session_id)
|
| 230 |
|
| 231 |
# Initialize vector store (90% progress)
|
| 232 |
status_container.info("🔄 Initializing vector store...")
|
|
|
|
| 239 |
|
| 240 |
st.session_state.vector_store = vector_store
|
| 241 |
progress_bar.progress(90)
|
| 242 |
+
persistence.save_vector_store(vector_store, session_id)
|
| 243 |
+
# Store session ID in state
|
| 244 |
+
st.session_state.current_session_id = session_id
|
| 245 |
# Initialize QA system (100% progress)
|
| 246 |
status_container.info("🔄 Setting up QA system...")
|
| 247 |
qa_system = initialize_qa_system(vector_store)
|
|
|
|
| 275 |
st.session_state.vector_store = None
|
| 276 |
st.session_state.qa_system = None
|
| 277 |
st.session_state.chat_ready = False
|
| 278 |
+
st.error(f"Error in document upload: {str(e)}")
|
| 279 |
|
| 280 |
finally:
|
| 281 |
if st.session_state.get('qa_system') is not None:
|
|
|
|
| 398 |
st.error(f"Error initializing QA system: {e}")
|
| 399 |
return None
|
| 400 |
|
| 401 |
+
|
| 402 |
# FAISS vector store initialization
|
| 403 |
def initialize_faiss(embeddings, documents, document_names):
|
| 404 |
"""Initialize FAISS vector store."""
|