@@ -17,13 +17,13 @@ def render_sidebar():
17
17
with st .sidebar :
18
18
st .header ("Settings" )
19
19
20
- # Global Model Selection
20
+ # Chat Model Selection
21
21
try :
22
22
available_models = st .session_state .model_manager .get_available_models ()
23
23
if available_models :
24
24
previous_model = st .session_state .selected_model
25
25
st .session_state .selected_model = st .selectbox (
26
- "🤖 Chat Model (Global) :" ,
26
+ "🤖 Chat Model:" ,
27
27
available_models ,
28
28
index = 0 if not st .session_state .selected_model else
29
29
(available_models .index (st .session_state .selected_model )
@@ -47,10 +47,10 @@ def render_sidebar():
47
47
st .error (f"❌ Error connecting to Ollama: { e } " )
48
48
return
49
49
50
- # Global Embedding Model Selection
50
+ # Embedding Model Selection
51
51
previous_embedding_model = st .session_state .rag_config ["embedding_model" ]
52
52
embedding_model = st .selectbox (
53
- "🔍 Embedding Model (Global) :" ,
53
+ "🔍 Embedding Model:" ,
54
54
["nomic-embed-text" , "mxbai-embed-large" , "all-minilm" ],
55
55
index = 0 if st .session_state .rag_config ["embedding_model" ] == "nomic-embed-text" else
56
56
(1 if st .session_state .rag_config ["embedding_model" ] == "mxbai-embed-large" else 2 ),
@@ -68,17 +68,66 @@ def render_sidebar():
68
68
st .info ("⚠️ Embedding model changed. Upload a new document to apply changes." )
69
69
st .rerun ()
70
70
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
+
71
127
st .divider ()
72
128
73
129
st .header ("Chat History" )
74
130
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
-
82
131
# New chat button
83
132
if st .button ("New Chat" , use_container_width = True , type = "primary" ):
84
133
# Stop any ongoing generation before creating new chat
@@ -92,57 +141,6 @@ def render_sidebar():
92
141
93
142
st .divider ()
94
143
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
-
146
144
# Chat history
147
145
sorted_chats = st .session_state .chat_manager .get_sorted_chats ()
148
146
if sorted_chats :
0 commit comments