Spaces:
Sleeping
Sleeping
Commit
Β·
c75f2fc
1
Parent(s):
c45b00b
faster
Browse files
src/legisqa_local/app.py
CHANGED
|
@@ -31,13 +31,16 @@ def main():
|
|
| 31 |
setup_environment()
|
| 32 |
logger.info("β
Environment setup complete")
|
| 33 |
|
| 34 |
-
# Setup ChromaDB (download if needed)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Initialize vectorstore (load once and cache in session state)
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
# Main content
|
| 43 |
st.title(":classical_building: LegisQA :classical_building:")
|
|
|
|
| 31 |
setup_environment()
|
| 32 |
logger.info("β
Environment setup complete")
|
| 33 |
|
| 34 |
+
# Setup ChromaDB (download if needed) - run once per session
|
| 35 |
+
if "chromadb_inspected" not in st.session_state:
|
| 36 |
+
logger.info("πΎ Inspecting ChromaDB...")
|
| 37 |
+
inspect_chromadb()
|
| 38 |
+
logger.info("β
ChromaDB inspection complete")
|
| 39 |
+
st.session_state.chromadb_inspected = True
|
| 40 |
|
| 41 |
# Initialize vectorstore (load once and cache in session state)
|
| 42 |
+
if "vectorstore" not in st.session_state:
|
| 43 |
+
initialize_vectorstore()
|
| 44 |
|
| 45 |
# Main content
|
| 46 |
st.title(":classical_building: LegisQA :classical_building:")
|
src/legisqa_local/components/sidebar.py
CHANGED
|
@@ -12,17 +12,17 @@ def render_chromadb_status():
|
|
| 12 |
|
| 13 |
vectorstore = get_vectorstore()
|
| 14 |
if vectorstore is not None:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
st.success("β
ChromaDB Ready")
|
| 19 |
st.caption(f"π {count:,} documents loaded")
|
| 20 |
|
| 21 |
config = get_chroma_config()
|
| 22 |
st.caption(f"π Collection: {config['collection_name']}")
|
| 23 |
-
|
| 24 |
st.warning("β οΈ ChromaDB Loaded (verification failed)")
|
| 25 |
-
st.caption(
|
| 26 |
else:
|
| 27 |
st.info("β³ ChromaDB Loading...")
|
| 28 |
st.caption("Vectorstore is being initialized")
|
|
|
|
| 12 |
|
| 13 |
vectorstore = get_vectorstore()
|
| 14 |
if vectorstore is not None:
|
| 15 |
+
# Use cached count from session state to avoid network calls on every rerun
|
| 16 |
+
count = st.session_state.get("vectorstore_count")
|
| 17 |
+
if count is not None:
|
| 18 |
st.success("β
ChromaDB Ready")
|
| 19 |
st.caption(f"π {count:,} documents loaded")
|
| 20 |
|
| 21 |
config = get_chroma_config()
|
| 22 |
st.caption(f"π Collection: {config['collection_name']}")
|
| 23 |
+
else:
|
| 24 |
st.warning("β οΈ ChromaDB Loaded (verification failed)")
|
| 25 |
+
st.caption("Could not retrieve document count")
|
| 26 |
else:
|
| 27 |
st.info("β³ ChromaDB Loading...")
|
| 28 |
st.caption("Vectorstore is being initialized")
|
src/legisqa_local/core/vectorstore.py
CHANGED
|
@@ -36,13 +36,15 @@ def initialize_vectorstore():
|
|
| 36 |
vectorstore = load_vectorstore()
|
| 37 |
st.session_state.vectorstore = vectorstore
|
| 38 |
|
| 39 |
-
# Test the vectorstore to verify it's working
|
| 40 |
collection = vectorstore._collection
|
| 41 |
count = collection.count()
|
|
|
|
| 42 |
logger.info(f"β
Vectorstore initialized and cached - {count} documents available")
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
logger.error(f"β Error initializing vectorstore: {e}")
|
|
|
|
| 46 |
# Don't raise - let the app continue and show loading message to users
|
| 47 |
|
| 48 |
|
|
|
|
| 36 |
vectorstore = load_vectorstore()
|
| 37 |
st.session_state.vectorstore = vectorstore
|
| 38 |
|
| 39 |
+
# Test the vectorstore to verify it's working and cache the count
|
| 40 |
collection = vectorstore._collection
|
| 41 |
count = collection.count()
|
| 42 |
+
st.session_state.vectorstore_count = count # Cache count to avoid repeated network calls
|
| 43 |
logger.info(f"β
Vectorstore initialized and cached - {count} documents available")
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
logger.error(f"β Error initializing vectorstore: {e}")
|
| 47 |
+
st.session_state.vectorstore_count = None # Mark as failed
|
| 48 |
# Don't raise - let the app continue and show loading message to users
|
| 49 |
|
| 50 |
|