~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(embedding-settings): preserve model selection on dropdown rebuilds (#3863) (#3940)
LearningCircuit6f420e6d7673
diff --git a/src/local_deep_research/web/static/js/embedding_settings.js b/src/local_deep_research/web/static/js/embedding_settings.jsindex cab83ad940..57bbc2a38d 100644--- a/src/local_deep_research/web/static/js/embedding_settings.js+++ b/src/local_deep_research/web/static/js/embedding_settings.js@@ -6,7 +6,6 @@// Available providers and models loaded from APIlet providerOptions = [];let availableModels = {};-let currentSettings = null;let originalValues = {};let autoSaveListenersAttached = false;@@ -35,9 +34,6 @@ document.addEventListener('DOMContentLoaded', function() {document.getElementById('ollama-url').addEventListener('input', function() {// Mark as changed if needed});-- // Setup config form submission- document.getElementById('rag-config-form').addEventListener('submit', handleConfigSubmit);});/**@@ -78,7 +74,6 @@ async function loadCurrentSettings() {const data = await response.json();if (data.success && data.settings) {- currentSettings = data.settings;const settings = data.settings;// Set provider@@ -399,14 +394,20 @@ function attachAutoSaveListeners() {// Text separators - blurdocument.getElementById('text-separators').addEventListener('blur', function() {const rawValue = this.value.trim();- if (!rawValue) return;+ const oldValue = originalValues['local_search_text_separators'];+ if (!rawValue) {+ // Empty textarea acts as "reset to defaults" — save the default+ // array so a stale customization in the DB is overwritten. This+ // mirrors the behavior of the removed handleConfigSubmit path.+ saveSetting('local_search_text_separators', ["\n\n", "\n", ". ", " ", ""], 'Text separators', oldValue);+ return;+ }try {const value = JSON.parse(rawValue);if (!Array.isArray(value)) {showError('Text separators must be a JSON array');return;}- const oldValue = originalValues['local_search_text_separators'];saveSetting('local_search_text_separators', value, 'Text separators', oldValue);} catch {showError('Invalid JSON format for text separators');@@ -483,6 +484,11 @@ function updateModelOptions() {providerSelect.parentNode.insertBefore(warning, providerSelect.nextSibling);}+ // Preserve the user's current pick across rebuilds — without this the+ // synthetic change dispatch below would overwrite the saved model with+ // whatever option lands at index 0 (issue #3863).+ const previousValue = modelSelect.value;+// Clear existing optionsmodelSelect.innerHTML = '';@@ -514,6 +520,14 @@ function updateModelOptions() {modelSelect.appendChild(placeholder);}+ // Restore the previously selected model if it still exists in the rebuilt+ // list; otherwise fall back to the first non-disabled option.+ if (previousValue && Array.from(modelSelect.options).some(opt => opt.value === previousValue && !opt.disabled)) {+ modelSelect.value = previousValue;+ } else if (modelSelect.options.length > 0 && !modelSelect.options[0].disabled) {+ modelSelect.value = modelSelect.options[0].value;+ }+// Update description and model hintupdateModelDescription();updateModelHint();@@ -665,144 +679,6 @@ function updateProviderInfo() {providerInfo.innerHTML = infoHTML;}-/**- * Handle configuration form submission- */-async function handleConfigSubmit(event) {- event.preventDefault();- SafeLogger.log('🚀 Configuration form submitted!');-- const provider = document.getElementById('embedding-provider').value;-- // Save Ollama URL first if provider is ollama- if (provider === 'ollama') {- const ollamaUrlSaved = await saveOllamaUrl();- if (!ollamaUrlSaved) {- showError('Failed to save Ollama URL');- return;- }- }-- // Get text separators and parse JSON- let textSeparators;- const textSeparatorsValue = document.getElementById('text-separators').value.trim();- if (textSeparatorsValue) {- try {- textSeparators = JSON.parse(textSeparatorsValue);- if (!Array.isArray(textSeparators)) {- showError('Text separators must be a JSON array');- return;- }- } catch {- showError('Invalid JSON format for text separators');- return;- }- } else {- // Use default if empty- textSeparators = ["\n\n", "\n", ". ", " ", ""];- }-- const formData = {- embedding_provider: provider,- embedding_model: document.getElementById('embedding-model').value,- chunk_size: parseInt(document.getElementById('chunk-size').value, 10),- chunk_overlap: parseInt(document.getElementById('chunk-overlap').value, 10),- splitter_type: document.getElementById('splitter-type').value,- distance_metric: document.getElementById('distance-metric').value,- index_type: document.getElementById('index-type').value,- normalize_vectors: document.getElementById('normalize-vectors').checked,- text_separators: textSeparators- };-- SafeLogger.log('📋 Form data:', formData);-- // Validation- if (!formData.embedding_provider) {- SafeLogger.error('❌ No provider selected');- showError('Please select an embedding provider');- return;- }-- if (!formData.embedding_model) {- SafeLogger.error('❌ No model selected');- showError('Please select an embedding model');- return;- }-- if (formData.chunk_size < 100 || formData.chunk_size > 5000) {- SafeLogger.error('❌ Invalid chunk size:', formData.chunk_size);- showError('Chunk size must be between 100 and 5000 characters');- return;- }-- if (formData.chunk_overlap < 0 || formData.chunk_overlap > 1000) {- SafeLogger.error('❌ Invalid chunk overlap:', formData.chunk_overlap);- showError('Chunk overlap must be between 0 and 1000 characters');- return;- }-- SafeLogger.log('✅ Form validation passed');-- try {- const csrfToken = window.api ? window.api.getCsrfToken() : '';- SafeLogger.log('🔐 CSRF Token:', csrfToken ? 'Found' : 'Not found');-- const response = await safeFetch('/library/api/rag/configure', {- method: 'POST',- headers: {- 'Content-Type': 'application/json',- 'X-CSRFToken': csrfToken- },- body: JSON.stringify(formData)- });-- SafeLogger.log('📡 Response status:', response.status);- const responseText = await response.text();- SafeLogger.log('📄 Response text:', responseText);-- let data;- try {- data = JSON.parse(responseText);- } catch (parseError) {- SafeLogger.error('❌ Failed to parse JSON:', parseError);- SafeLogger.error('❌ Response was:', responseText);- showError('Server returned invalid response. Check console for details.');- return;- }-- if (data.success) {- SafeLogger.log('✅ Default settings saved successfully!');- if (window.ui && window.ui.showMessage) {- window.ui.showMessage('Default embedding settings saved successfully!', 'success', 6000);- } else {- showSuccess('Default embedding settings saved successfully! New collections will use these settings.');- }- currentSettings = formData;- // Update original values after batch save- originalValues['local_search_embedding_provider'] = formData.embedding_provider;- originalValues['local_search_embedding_model'] = formData.embedding_model;- originalValues['local_search_chunk_size'] = formData.chunk_size;- originalValues['local_search_chunk_overlap'] = formData.chunk_overlap;- originalValues['local_search_splitter_type'] = formData.splitter_type;- originalValues['local_search_distance_metric'] = formData.distance_metric;- originalValues['local_search_index_type'] = formData.index_type;- originalValues['local_search_normalize_vectors'] = formData.normalize_vectors;- originalValues['local_search_text_separators'] = formData.text_separators;- originalValues['embeddings.ollama.url'] = document.getElementById('ollama-url').value.trim();- // Update the saved defaults display- renderSavedDefaults(formData);- // Re-check provider availability (e.g. Ollama URL may have changed)- await loadAvailableModels();- } else {- SafeLogger.error('❌ Server returned error:', data.error);- showError('Failed to save default settings: ' + data.error);- }- } catch (error) {- SafeLogger.error('❌ Error updating configuration:', error);- showError('Failed to save configuration: ' + error.message);- }-}-/*** Test configuration by sending a real embedding request*/@@ -996,35 +872,3 @@ async function loadOllamaUrl() {SafeLogger.error('Error loading Ollama URL:', error);}}--/**- * Save Ollama URL to settings- */-async function saveOllamaUrl() {- const ollamaUrl = document.getElementById('ollama-url').value.trim();-- try {- const csrfToken = window.api ? window.api.getCsrfToken() : '';-- const response = await safeFetch('/settings/api/embeddings.ollama.url', {- method: 'PUT',- headers: {- 'Content-Type': 'application/json',- 'X-CSRFToken': csrfToken- },- body: JSON.stringify({- value: ollamaUrl- })- });-- const data = await response.json();- if (data.error) {- SafeLogger.error('Failed to save Ollama URL:', data.error);- return false;- }- return true;- } catch (error) {- SafeLogger.error('Error saving Ollama URL:', error);- return false;- }-}diff --git a/src/local_deep_research/web/templates/pages/embedding_settings.html b/src/local_deep_research/web/templates/pages/embedding_settings.htmlindex b692662250..174765a103 100644--- a/src/local_deep_research/web/templates/pages/embedding_settings.html+++ b/src/local_deep_research/web/templates/pages/embedding_settings.html@@ -80,7 +80,7 @@<!-- Default Embedding Configuration --><div class="ldr-config-section"><h3>Default Embedding Configuration</h3>- <form id="rag-config-form">+ <div><div class="ldr-form-group"><label for="embedding-provider">Provider</label><select id="embedding-provider" class="ldr-form-control">@@ -176,13 +176,10 @@</small></div>- <button type="submit" class="ldr-btn ldr-btn-primary">- <i aria-hidden="true" class="fas fa-save"></i> Save Default Settings- </button><small class="ldr-form-text ldr-text-muted ldr-mt-2">- <i aria-hidden="true" class="fas fa-info-circle"></i> These settings will be used as defaults for new collections. Existing collections will continue using their current settings unless re-indexed with new defaults.+ <i aria-hidden="true" class="fas fa-info-circle"></i> Changes save automatically. These settings are used as defaults for new collections; existing collections continue using their current settings unless re-indexed.</small>- </form>+ </div></div></div></div>