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>
This commit is contained in:
Copilot
2026-03-30 23:39:19 +03:00
committed by GitHub
parent b89293418d
commit c918f4f36d
2 changed files with 13 additions and 2 deletions
+9 -2
View File
@@ -81,6 +81,7 @@ const settings = {
// For chats
enabled_chats: false,
keep_hidden: false,
template: 'Past events:\n{{text}}',
depth: 2,
position: extension_prompt_types.IN_PROMPT,
@@ -347,7 +348,7 @@ async function synchronizeChat(batchSize = 5) {
return -1;
}
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) }));
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) }));
const hashesInCollection = await getSavedHashes(chatId);
let newVectorItems = hashedMessages.filter(x => !hashesInCollection.includes(x.hash));
@@ -1496,10 +1497,11 @@ async function onViewStatsClick() {
{ timeOut: 10000, escapeHtml: false },
);
$('#chat .mes.vectorized').removeClass('vectorized');
const chat = getContext().chat;
for (const message of chat) {
if (hashesInCollection.includes(getStringHash(substituteParams(message.mes)))) {
const messageElement = $(`.mes[mesid="${chat.indexOf(message)}"]`);
const messageElement = $(`#chat .mes[mesid="${chat.indexOf(message)}"]`);
messageElement.addClass('vectorized');
}
}
@@ -1726,6 +1728,11 @@ jQuery(async () => {
saveSettingsDebounced();
toggleSettings();
});
$('#vectors_keep_hidden').prop('checked', settings.keep_hidden).on('input', () => {
settings.keep_hidden = !!$('#vectors_keep_hidden').prop('checked');
Object.assign(extension_settings.vectors, settings);
saveSettingsDebounced();
});
$('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => {
settings.enabled_files = $('#vectors_enabled_files').prop('checked');
Object.assign(extension_settings.vectors, settings);
@@ -408,6 +408,10 @@
<hr>
<div id="vectors_chats_settings">
<label class="checkbox_label expander" for="vectors_keep_hidden" title="Keep hidden (system) messages in the vector index and include them in query results.">
<input id="vectors_keep_hidden" type="checkbox" class="checkbox">
<span data-i18n="Include hidden messages">Include hidden messages</span>
</label>
<div id="vectors_advanced_settings">
<label for="vectors_template" data-i18n="Injection Template">
Injection Template