mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#1152 Filter repeating message hashes when inserting vectors
This commit is contained in:
@ -182,14 +182,17 @@ async function rearrangeChat(chat) {
|
|||||||
// Get the most relevant messages, excluding the last few
|
// Get the most relevant messages, excluding the last few
|
||||||
const queryHashes = (await queryCollection(chatId, queryText, settings.insert)).filter(onlyUnique);
|
const queryHashes = (await queryCollection(chatId, queryText, settings.insert)).filter(onlyUnique);
|
||||||
const queriedMessages = [];
|
const queriedMessages = [];
|
||||||
|
const insertedHashes = new Set();
|
||||||
const retainMessages = chat.slice(-settings.protect);
|
const retainMessages = chat.slice(-settings.protect);
|
||||||
|
|
||||||
for (const message of chat) {
|
for (const message of chat) {
|
||||||
if (retainMessages.includes(message)) {
|
if (retainMessages.includes(message) || !message.mes) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (message.mes && queryHashes.includes(getStringHash(message.mes))) {
|
const hash = getStringHash(message.mes);
|
||||||
|
if (queryHashes.includes(hash) && !insertedHashes.has(hash)) {
|
||||||
queriedMessages.push(message);
|
queriedMessages.push(message);
|
||||||
|
insertedHashes.add(hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user