Deprecate unscoped vectors
| @@ -110,9 +110,6 @@ enableExtensionsAutoUpdate: true | |||
| 110 | # Additional model tokenizers can be downloaded on demand. | 110 | # Additional model tokenizers can be downloaded on demand. |
| 111 | # Disabling will fallback to another locally available tokenizer. | 111 | # Disabling will fallback to another locally available tokenizer. |
| 112 | enableDownloadableTokenizers: true | 112 | enableDownloadableTokenizers: true |
| 113 | # Vector storage settings | ||
| 114 | vectors: | ||
| 115 | enableModelScopes: false | ||
| 116 | # Extension settings | 113 | # Extension settings |
| 117 | extras: | 114 | extras: |
| 118 | # Disables automatic model download from HuggingFace | 115 | # Disables automatic model download from HuggingFace |
| @@ -999,25 +999,6 @@ async function purgeAllVectorIndexes() { | |||
| 999 | } | 999 | } |
| 1000 | } | 1000 | } |
| 1001 | 1001 | ||
| 1002 | async function isModelScopesEnabled() { | ||
| 1003 | try { | ||
| 1004 | const response = await fetch('/api/vector/scopes-enabled', { | ||
| 1005 | method: 'GET', | ||
| 1006 | headers: getVectorHeaders(), | ||
| 1007 | }); | ||
| 1008 | |||
| 1009 | if (!response.ok) { | ||
| 1010 | return false; | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | const data = await response.json(); | ||
| 1014 | return data?.enabled ?? false; | ||
| 1015 | } catch (error) { | ||
| 1016 | console.error('Vectors: Failed to check model scopes', error); | ||
| 1017 | return false; | ||
| 1018 | } | ||
| 1019 | } | ||
| 1020 | |||
| 1021 | function toggleSettings() { | 1002 | function toggleSettings() { |
| 1022 | $('#vectors_files_settings').toggle(!!settings.enabled_files); | 1003 | $('#vectors_files_settings').toggle(!!settings.enabled_files); |
| 1023 | $('#vectors_chats_settings').toggle(!!settings.enabled_chats); | 1004 | $('#vectors_chats_settings').toggle(!!settings.enabled_chats); |
| @@ -1282,7 +1263,6 @@ jQuery(async () => { | |||
| 1282 | } | 1263 | } |
| 1283 | 1264 | ||
| 1284 | Object.assign(settings, extension_settings.vectors); | 1265 | Object.assign(settings, extension_settings.vectors); |
| 1285 | const scopesEnabled = await isModelScopesEnabled(); | ||
| 1286 | 1266 | ||
| 1287 | // Migrate from TensorFlow to Transformers | 1267 | // Migrate from TensorFlow to Transformers |
| 1288 | settings.source = settings.source !== 'local' ? settings.source : 'transformers'; | 1268 | settings.source = settings.source !== 'local' ? settings.source : 'transformers'; |
| @@ -1294,7 +1274,6 @@ jQuery(async () => { | |||
| 1294 | saveSettingsDebounced(); | 1274 | saveSettingsDebounced(); |
| 1295 | toggleSettings(); | 1275 | toggleSettings(); |
| 1296 | }); | 1276 | }); |
| 1297 | $('#vectors_modelWarning').hide(); | ||
| 1298 | $('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => { | 1277 | $('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => { |
| 1299 | settings.enabled_files = $('#vectors_enabled_files').prop('checked'); | 1278 | settings.enabled_files = $('#vectors_enabled_files').prop('checked'); |
| 1300 | Object.assign(extension_settings.vectors, settings); | 1279 | Object.assign(extension_settings.vectors, settings); |
| @@ -1334,31 +1313,26 @@ jQuery(async () => { | |||
| 1334 | saveSettingsDebounced(); | 1313 | saveSettingsDebounced(); |
| 1335 | }); | 1314 | }); |
| 1336 | $('#vectors_togetherai_model').val(settings.togetherai_model).on('change', () => { | 1315 | $('#vectors_togetherai_model').val(settings.togetherai_model).on('change', () => { |
| 1337 | !scopesEnabled && $('#vectors_modelWarning').show(); | ||
| 1338 | settings.togetherai_model = String($('#vectors_togetherai_model').val()); | 1316 | settings.togetherai_model = String($('#vectors_togetherai_model').val()); |
| 1339 | Object.assign(extension_settings.vectors, settings); | 1317 | Object.assign(extension_settings.vectors, settings); |
| 1340 | saveSettingsDebounced(); | 1318 | saveSettingsDebounced(); |
| 1341 | }); | 1319 | }); |
| 1342 | $('#vectors_openai_model').val(settings.openai_model).on('change', () => { | 1320 | $('#vectors_openai_model').val(settings.openai_model).on('change', () => { |
| 1343 | !scopesEnabled && $('#vectors_modelWarning').show(); | ||
| 1344 | settings.openai_model = String($('#vectors_openai_model').val()); | 1321 | settings.openai_model = String($('#vectors_openai_model').val()); |
| 1345 | Object.assign(extension_settings.vectors, settings); | 1322 | Object.assign(extension_settings.vectors, settings); |
| 1346 | saveSettingsDebounced(); | 1323 | saveSettingsDebounced(); |
| 1347 | }); | 1324 | }); |
| 1348 | $('#vectors_cohere_model').val(settings.cohere_model).on('change', () => { | 1325 | $('#vectors_cohere_model').val(settings.cohere_model).on('change', () => { |
| 1349 | !scopesEnabled && $('#vectors_modelWarning').show(); | ||
| 1350 | settings.cohere_model = String($('#vectors_cohere_model').val()); | 1326 | settings.cohere_model = String($('#vectors_cohere_model').val()); |
| 1351 | Object.assign(extension_settings.vectors, settings); | 1327 | Object.assign(extension_settings.vectors, settings); |
| 1352 | saveSettingsDebounced(); | 1328 | saveSettingsDebounced(); |
| 1353 | }); | 1329 | }); |
| 1354 | $('#vectors_ollama_model').val(settings.ollama_model).on('input', () => { | 1330 | $('#vectors_ollama_model').val(settings.ollama_model).on('input', () => { |
| 1355 | !scopesEnabled && $('#vectors_modelWarning').show(); | ||
| 1356 | settings.ollama_model = String($('#vectors_ollama_model').val()); | 1331 | settings.ollama_model = String($('#vectors_ollama_model').val()); |
| 1357 | Object.assign(extension_settings.vectors, settings); | 1332 | Object.assign(extension_settings.vectors, settings); |
| 1358 | saveSettingsDebounced(); | 1333 | saveSettingsDebounced(); |
| 1359 | }); | 1334 | }); |
| 1360 | $('#vectors_vllm_model').val(settings.vllm_model).on('input', () => { | 1335 | $('#vectors_vllm_model').val(settings.vllm_model).on('input', () => { |
| 1361 | !scopesEnabled && $('#vectors_modelWarning').show(); | ||
| 1362 | settings.vllm_model = String($('#vectors_vllm_model').val()); | 1336 | settings.vllm_model = String($('#vectors_vllm_model').val()); |
| 1363 | Object.assign(extension_settings.vectors, settings); | 1337 | Object.assign(extension_settings.vectors, settings); |
| 1364 | saveSettingsDebounced(); | 1338 | saveSettingsDebounced(); |
| @@ -96,14 +96,6 @@ | |||
| 96 | </i> | 96 | </i> |
| 97 | </div> | 97 | </div> |
| 98 | 98 | ||
| 99 | <small id="vectors_modelWarning"> | ||
| 100 | <i class="fa-solid fa-exclamation-triangle"></i> | ||
| 101 | <span> | ||
| 102 | Set <code>vectors.enableModelScopes</code> to true in config.yaml to switch between vectorization models without needing to purge existing vectors. | ||
| 103 | This option will soon be enabled by default. | ||
| 104 | </span> | ||
| 105 | </small> | ||
| 106 | |||
| 107 | <div class="flex-container alignItemsCenter" id="nomicai_apiKey"> | 99 | <div class="flex-container alignItemsCenter" id="nomicai_apiKey"> |
| 108 | <label for="api_key_nomicai" class="flex1"> | 100 | <label for="api_key_nomicai" class="flex1"> |
| 109 | <span data-i18n="NomicAI API Key">NomicAI API Key</span> | 101 | <span data-i18n="NomicAI API Key">NomicAI API Key</span> |
| @@ -4,7 +4,7 @@ const fs = require('fs'); | |||
| 4 | const express = require('express'); | 4 | const express = require('express'); |
| 5 | const sanitize = require('sanitize-filename'); | 5 | const sanitize = require('sanitize-filename'); |
| 6 | const { jsonParser } = require('../express-common'); | 6 | const { jsonParser } = require('../express-common'); |
| 7 | const { getConfigValue, color } = require('../util'); | 7 | const { getConfigValue } = require('../util'); |
| 8 | 8 | ||
| 9 | // Don't forget to add new sources to the SOURCES array | 9 | // Don't forget to add new sources to the SOURCES array |
| 10 | const SOURCES = [ | 10 | const SOURCES = [ |
| @@ -150,7 +150,7 @@ function getSourceSettings(source, request) { | |||
| 150 | extrasUrl: String(request.headers['x-extras-url']), | 150 | extrasUrl: String(request.headers['x-extras-url']), |
| 151 | extrasKey: String(request.headers['x-extras-key']), | 151 | extrasKey: String(request.headers['x-extras-key']), |
| 152 | }; | 152 | }; |
| 153 | case 'local': | 153 | case 'transformers': |
| 154 | return { | 154 | return { |
| 155 | model: getConfigValue('extras.embeddingModel', ''), | 155 | model: getConfigValue('extras.embeddingModel', ''), |
| 156 | }; | 156 | }; |
| @@ -159,6 +159,14 @@ function getSourceSettings(source, request) { | |||
| 159 | // TODO: Add support for multiple models | 159 | // TODO: Add support for multiple models |
| 160 | model: 'text-embedding-004', | 160 | model: 'text-embedding-004', |
| 161 | }; | 161 | }; |
| 162 | case 'mistral': | ||
| 163 | return { | ||
| 164 | model: 'mistral-embed', | ||
| 165 | }; | ||
| 166 | case 'nomicai': | ||
| 167 | return { | ||
| 168 | model: 'nomic-embed-text-v1.5', | ||
| 169 | }; | ||
| 162 | default: | 170 | default: |
| 163 | return {}; | 171 | return {}; |
| 164 | } | 172 | } |
| @@ -170,19 +178,7 @@ function getSourceSettings(source, request) { | |||
| 170 | * @returns {string} The model scope for the source | 178 | * @returns {string} The model scope for the source |
| 171 | */ | 179 | */ |
| 172 | function getModelScope(sourceSettings) { | 180 | function getModelScope(sourceSettings) { |
| 173 | const scopesEnabled = getConfigValue('vectors.enableModelScopes', false); | 181 | return (sourceSettings?.model || ''); |
| 174 | const warningShown = global.process.env.VECTORS_MODEL_SCOPE_WARNING_SHOWN === 'true'; | ||
| 175 | |||
| 176 | if (!scopesEnabled && !warningShown) { | ||
| 177 | console.log(); | ||
| 178 | console.warn(color.red('[DEPRECATION NOTICE]'), 'Model scopes for Vectore Storage are disabled, but will soon be required.'); | ||
| 179 | console.log(`To enable model scopes, set the ${color.cyan('vectors.enableModelScopes')} in config.yaml to ${color.green(true)}.`); | ||
| 180 | console.log('This message won\'t be shown again in the current session.'); | ||
| 181 | console.log(); | ||
| 182 | global.process.env.VECTORS_MODEL_SCOPE_WARNING_SHOWN = 'true'; | ||
| 183 | } | ||
| 184 | |||
| 185 | return scopesEnabled ? (sourceSettings?.model || '') : ''; | ||
| 186 | } | 182 | } |
| 187 | 183 | ||
| 188 | /** | 184 | /** |
| @@ -365,11 +361,6 @@ async function regenerateCorruptedIndexErrorHandler(req, res, error) { | |||
| 365 | 361 | ||
| 366 | const router = express.Router(); | 362 | const router = express.Router(); |
| 367 | 363 | ||
| 368 | router.get('/scopes-enabled', (_req, res) => { | ||
| 369 | const scopesEnabled = getConfigValue('vectors.enableModelScopes', false); | ||
| 370 | return res.json({ enabled: scopesEnabled }); | ||
| 371 | }); | ||
| 372 | |||
| 373 | router.post('/query', jsonParser, async (req, res) => { | 364 | router.post('/query', jsonParser, async (req, res) => { |
| 374 | try { | 365 | try { |
| 375 | if (!req.body.collectionId || !req.body.searchText) { | 366 | if (!req.body.collectionId || !req.body.searchText) { |