Add opt-in toggle to keep hidden messages in chat vector index (#5378) * Initial plan * Add opt-in toggle to keep hidden messages in chat vector index Agent-Logs-Url: https://github.com/SillyTavern/SillyTavern/sessions/eadc80a1-a417-40df-a374-76d7c4a46ce3 Co-authored-by: Cohee1207 <18619528+Cohee1207@users.noreply.github.com> * Revert package-lock changes * Fix: Remove 'vectorized' class from chat messages before adding it --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Cohee1207 <18619528+Cohee1207@users.noreply.github.com>

c918f4f36d6d28519ce60e722f4f72f062b204d0

Copilot <198982749+Copilot@users.noreply.github.com>

Signed
2 files changed, +13 -2Ignore whitespace
public/scripts/extensions/vectors/index.js+9 -2
@@ -81,6 +81,7 @@ const settings = {
8181
82 // For chats82 // For chats
83 enabled_chats: false,83 enabled_chats: false,
84 keep_hidden: false,
84 template: 'Past events:\n{{text}}',85 template: 'Past events:\n{{text}}',
85 depth: 2,86 depth: 2,
86 position: extension_prompt_types.IN_PROMPT,87 position: extension_prompt_types.IN_PROMPT,
@@ -347,7 +348,7 @@ async function synchronizeChat(batchSize = 5) {
347 return -1;348 return -1;
348 }349 }
349350
350 const hashedMessages = context.chat.filter(x => !x.is_system).map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)), index: context.chat.indexOf(x) }));351 const hashedMessages = context.chat.filter(x => settings.keep_hidden || !x.is_system).map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)), index: context.chat.indexOf(x) }));
351 const hashesInCollection = await getSavedHashes(chatId);352 const hashesInCollection = await getSavedHashes(chatId);
352353
353 let newVectorItems = hashedMessages.filter(x => !hashesInCollection.includes(x.hash));354 let newVectorItems = hashedMessages.filter(x => !hashesInCollection.includes(x.hash));
@@ -1496,10 +1497,11 @@ async function onViewStatsClick() {
1496 { timeOut: 10000, escapeHtml: false },1497 { timeOut: 10000, escapeHtml: false },
1497 );1498 );
14981499
1500 $('#chat .mes.vectorized').removeClass('vectorized');
1499 const chat = getContext().chat;1501 const chat = getContext().chat;
1500 for (const message of chat) {1502 for (const message of chat) {
1501 if (hashesInCollection.includes(getStringHash(substituteParams(message.mes)))) {1503 if (hashesInCollection.includes(getStringHash(substituteParams(message.mes)))) {
1502 const messageElement = $(`.mes[mesid="${chat.indexOf(message)}"]`);1504 const messageElement = $(`#chat .mes[mesid="${chat.indexOf(message)}"]`);
1503 messageElement.addClass('vectorized');1505 messageElement.addClass('vectorized');
1504 }1506 }
1505 }1507 }
@@ -1726,6 +1728,11 @@ jQuery(async () => {
1726 saveSettingsDebounced();1728 saveSettingsDebounced();
1727 toggleSettings();1729 toggleSettings();
1728 });1730 });
1731 $('#vectors_keep_hidden').prop('checked', settings.keep_hidden).on('input', () => {
1732 settings.keep_hidden = !!$('#vectors_keep_hidden').prop('checked');
1733 Object.assign(extension_settings.vectors, settings);
1734 saveSettingsDebounced();
1735 });
1729 $('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => {1736 $('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => {
1730 settings.enabled_files = $('#vectors_enabled_files').prop('checked');1737 settings.enabled_files = $('#vectors_enabled_files').prop('checked');
1731 Object.assign(extension_settings.vectors, settings);1738 Object.assign(extension_settings.vectors, settings);
public/scripts/extensions/vectors/settings.html+4 -0
@@ -408,6 +408,10 @@
408 <hr>408 <hr>
409409
410 <div id="vectors_chats_settings">410 <div id="vectors_chats_settings">
411 <label class="checkbox_label expander" for="vectors_keep_hidden" title="Keep hidden (system) messages in the vector index and include them in query results.">
412 <input id="vectors_keep_hidden" type="checkbox" class="checkbox">
413 <span data-i18n="Include hidden messages">Include hidden messages</span>
414 </label>
411 <div id="vectors_advanced_settings">415 <div id="vectors_advanced_settings">
412 <label for="vectors_template" data-i18n="Injection Template">416 <label for="vectors_template" data-i18n="Injection Template">
413 Injection Template417 Injection Template