mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Clean-up vectors upon deleting a file from Data Bank
This commit is contained in:
@ -353,7 +353,8 @@ async function processFiles(chat) {
|
||||
message.mes = message.mes.substring(message.extra.fileLength);
|
||||
|
||||
const fileName = message.extra.file.name;
|
||||
const collectionId = `file_${getStringHash(fileName)}`;
|
||||
const fileUrl = message.extra.file.url;
|
||||
const collectionId = `file_${getStringHash(fileUrl)}`;
|
||||
const hashesInCollection = await getSavedHashes(collectionId);
|
||||
|
||||
// File is already in the collection
|
||||
@ -748,6 +749,37 @@ async function queryMultipleCollections(collectionIds, searchText, topK) {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges the vector index for a file.
|
||||
* @param {string} fileUrl File URL to purge
|
||||
*/
|
||||
async function purgeFileVectorIndex(fileUrl) {
|
||||
try {
|
||||
if (!settings.enabled_files) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Vectors: Purging file vector index for ${fileUrl}`);
|
||||
const collectionId = `file_${getStringHash(fileUrl)}`;
|
||||
|
||||
const response = await fetch('/api/vector/purge', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
collectionId: collectionId,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Could not delete vector index for collection ${collectionId}`);
|
||||
}
|
||||
|
||||
console.log(`Vectors: Purged vector index for collection ${collectionId}`);
|
||||
} catch (error) {
|
||||
console.error('Vectors: Failed to purge file', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges the vector index for a collection.
|
||||
* @param {string} collectionId Collection ID to purge
|
||||
@ -1025,4 +1057,5 @@ jQuery(async () => {
|
||||
eventSource.on(event_types.MESSAGE_SWIPED, onChatEvent);
|
||||
eventSource.on(event_types.CHAT_DELETED, purgeVectorIndex);
|
||||
eventSource.on(event_types.GROUP_CHAT_DELETED, purgeVectorIndex);
|
||||
eventSource.on(event_types.FILE_ATTACHMENT_DELETED, purgeFileVectorIndex);
|
||||
});
|
||||
|
Reference in New Issue
Block a user