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 -2Showing whitespace changes
public/scripts/extensions/vectors/index.js+9 -2
@@ -81,6 +81,7 @@ const settings = {
8181
8282 // For chats
8383 enabled_chats: false,
84+ keep_hidden: false,
8485 template: 'Past events:\n{{text}}',
8586 depth: 2,
8687 position: extension_prompt_types.IN_PROMPT,
@@ -347,7 +348,7 @@ async function synchronizeChat(batchSize = 5) {
347348 return -1;
348349 }
349350
350351 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) }));
351352 const hashesInCollection = await getSavedHashes(chatId);
352353
353354 let newVectorItems = hashedMessages.filter(x => !hashesInCollection.includes(x.hash));
@@ -1496,10 +1497,11 @@ async function onViewStatsClick() {
14961497 { timeOut: 10000, escapeHtml: false },
14971498 );
14981499
1500+ $('#chat .mes.vectorized').removeClass('vectorized');
14991501 const chat = getContext().chat;
15001502 for (const message of chat) {
15011503 if (hashesInCollection.includes(getStringHash(substituteParams(message.mes)))) {
15021504 const messageElement = $(`#chat .mes[mesid="${chat.indexOf(message)}"]`);
15031505 messageElement.addClass('vectorized');
15041506 }
15051507 }
@@ -1726,6 +1728,11 @@ jQuery(async () => {
17261728 saveSettingsDebounced();
17271729 toggleSettings();
17281730 });
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+ });
17291736 $('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => {
17301737 settings.enabled_files = $('#vectors_enabled_files').prop('checked');
17311738 Object.assign(extension_settings.vectors, settings);
public/scripts/extensions/vectors/settings.html+4 -0
@@ -408,6 +408,10 @@
408408 <hr>
409409
410410 <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>
411415 <div id="vectors_advanced_settings">
412416 <label for="vectors_template" data-i18n="Injection Template">
413417 Injection Template