Skip to content

Commit b6c22d1

Browse files
committed
RAG settings only in expert mode
1 parent 18fd125 commit b6c22d1

File tree

1 file changed

+60
-62
lines changed

1 file changed

+60
-62
lines changed

ragadoc/ui_sidebar.py

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def render_sidebar():
1717
with st.sidebar:
1818
st.header("Settings")
1919

20-
# Global Model Selection
20+
# Chat Model Selection
2121
try:
2222
available_models = st.session_state.model_manager.get_available_models()
2323
if available_models:
2424
previous_model = st.session_state.selected_model
2525
st.session_state.selected_model = st.selectbox(
26-
"🤖 Chat Model (Global):",
26+
"🤖 Chat Model:",
2727
available_models,
2828
index=0 if not st.session_state.selected_model else
2929
(available_models.index(st.session_state.selected_model)
@@ -47,10 +47,10 @@ def render_sidebar():
4747
st.error(f"❌ Error connecting to Ollama: {e}")
4848
return
4949

50-
# Global Embedding Model Selection
50+
# Embedding Model Selection
5151
previous_embedding_model = st.session_state.rag_config["embedding_model"]
5252
embedding_model = st.selectbox(
53-
"🔍 Embedding Model (Global):",
53+
"🔍 Embedding Model:",
5454
["nomic-embed-text", "mxbai-embed-large", "all-minilm"],
5555
index=0 if st.session_state.rag_config["embedding_model"] == "nomic-embed-text" else
5656
(1 if st.session_state.rag_config["embedding_model"] == "mxbai-embed-large" else 2),
@@ -68,17 +68,66 @@ def render_sidebar():
6868
st.info("⚠️ Embedding model changed. Upload a new document to apply changes.")
6969
st.rerun()
7070

71+
# Expert Mode Toggle
72+
expert_mode = st.toggle(
73+
"🔧 Expert Mode",
74+
value=st.session_state.get('expert_mode', False),
75+
help="Show advanced RAG configuration settings"
76+
)
77+
st.session_state.expert_mode = expert_mode
78+
79+
# RAG Configuration (only shown in expert mode)
80+
if expert_mode:
81+
with st.expander("🔍 RAG Settings", expanded=False):
82+
# RAG parameters (excluding embedding model which is now global)
83+
chunk_size = st.slider("Chunk Size (tokens)", 32, 1024, st.session_state.rag_config["chunk_size"], 64)
84+
chunk_overlap = st.slider("Chunk Overlap (tokens)", 0, 200, st.session_state.rag_config["chunk_overlap"], 10)
85+
similarity_threshold = st.slider("Similarity Threshold", 0.0, 1.0, st.session_state.rag_config["similarity_threshold"], 0.05)
86+
top_k = st.slider("Max Retrieved Chunks", 1, 20, st.session_state.rag_config["top_k"], 1)
87+
88+
# Update configuration if changed (excluding embedding model)
89+
new_config = {
90+
"chunk_size": chunk_size,
91+
"chunk_overlap": chunk_overlap,
92+
"similarity_threshold": similarity_threshold,
93+
"top_k": top_k,
94+
"embedding_model": st.session_state.rag_config["embedding_model"] # Keep current embedding model
95+
}
96+
97+
if new_config != st.session_state.rag_config:
98+
st.session_state.rag_config = new_config
99+
st.info("⚠️ RAG settings changed. Upload a new document to apply changes.")
100+
101+
# RAG system status
102+
if st.session_state.rag_system:
103+
st.success("✅ RAG System Ready")
104+
105+
# Show available documents
106+
available_docs = st.session_state.rag_system.get_available_documents()
107+
if available_docs:
108+
st.info(f"📊 {len(available_docs)} document(s) in system")
109+
110+
# Show current document for current chat
111+
current_chat = st.session_state.chat_manager.get_current_chat()
112+
if current_chat and current_chat.rag_processed:
113+
stats = current_chat.rag_stats or {}
114+
st.info(f"📄 Current: {stats.get('total_chunks', 0)} chunks")
115+
else:
116+
st.warning("📄 No document in current chat")
117+
else:
118+
st.warning("📄 No documents processed yet")
119+
else:
120+
st.error("❌ RAG System Not Available")
121+
if st.button("🔄 Retry RAG Initialization"):
122+
if "rag_system" in st.session_state:
123+
del st.session_state["rag_system"]
124+
init_rag_system()
125+
st.rerun()
126+
71127
st.divider()
72128

73129
st.header("Chat History")
74130

75-
# Connection info
76-
ollama_base_url = get_ollama_base_url()
77-
if is_running_in_docker():
78-
st.caption(f"🐳 Docker → {ollama_base_url}")
79-
else:
80-
st.caption(f"💻 Direct → localhost:11434")
81-
82131
# New chat button
83132
if st.button("New Chat", use_container_width=True, type="primary"):
84133
# Stop any ongoing generation before creating new chat
@@ -92,57 +141,6 @@ def render_sidebar():
92141

93142
st.divider()
94143

95-
# RAG Configuration
96-
with st.expander("🔍 RAG Settings", expanded=False):
97-
st.info("🔍 **Smart Retrieval**: The system first finds ALL chunks above the similarity threshold, then limits to the max number.")
98-
99-
# RAG parameters (excluding embedding model which is now global)
100-
chunk_size = st.slider("Chunk Size (tokens)", 32, 1024, st.session_state.rag_config["chunk_size"], 64)
101-
chunk_overlap = st.slider("Chunk Overlap (tokens)", 0, 200, st.session_state.rag_config["chunk_overlap"], 10)
102-
similarity_threshold = st.slider("Similarity Threshold", 0.0, 1.0, st.session_state.rag_config["similarity_threshold"], 0.05)
103-
top_k = st.slider("Max Retrieved Chunks", 1, 20, st.session_state.rag_config["top_k"], 1)
104-
105-
# Update configuration if changed (excluding embedding model)
106-
new_config = {
107-
"chunk_size": chunk_size,
108-
"chunk_overlap": chunk_overlap,
109-
"similarity_threshold": similarity_threshold,
110-
"top_k": top_k,
111-
"embedding_model": st.session_state.rag_config["embedding_model"] # Keep current embedding model
112-
}
113-
114-
if new_config != st.session_state.rag_config:
115-
st.session_state.rag_config = new_config
116-
st.info("⚠️ RAG settings changed. Upload a new document to apply changes.")
117-
118-
# RAG system status
119-
if st.session_state.rag_system:
120-
st.success("✅ RAG System Ready")
121-
122-
# Show available documents
123-
available_docs = st.session_state.rag_system.get_available_documents()
124-
if available_docs:
125-
st.info(f"📊 {len(available_docs)} document(s) in system")
126-
127-
# Show current document for current chat
128-
current_chat = st.session_state.chat_manager.get_current_chat()
129-
if current_chat and current_chat.rag_processed:
130-
stats = current_chat.rag_stats or {}
131-
st.info(f"📄 Current: {stats.get('total_chunks', 0)} chunks")
132-
else:
133-
st.warning("📄 No document in current chat")
134-
else:
135-
st.warning("📄 No documents processed yet")
136-
else:
137-
st.error("❌ RAG System Not Available")
138-
if st.button("🔄 Retry RAG Initialization"):
139-
if "rag_system" in st.session_state:
140-
del st.session_state["rag_system"]
141-
init_rag_system()
142-
st.rerun()
143-
144-
st.divider()
145-
146144
# Chat history
147145
sorted_chats = st.session_state.chat_manager.get_sorted_chats()
148146
if sorted_chats:

0 commit comments

Comments
 (0)