mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Delete vectors on deleting chats
This commit is contained in:
@@ -323,6 +323,31 @@ async function queryCollection(collectionId, searchText, topK) {
|
||||
return results;
|
||||
}
|
||||
|
||||
async function purgeVectorIndex(collectionId) {
|
||||
try {
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
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', error);
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
if (!extension_settings.vectors) {
|
||||
extension_settings.vectors = settings;
|
||||
@@ -381,4 +406,6 @@ jQuery(async () => {
|
||||
eventSource.on(event_types.MESSAGE_SENT, onChatEvent);
|
||||
eventSource.on(event_types.MESSAGE_RECEIVED, onChatEvent);
|
||||
eventSource.on(event_types.MESSAGE_SWIPED, onChatEvent);
|
||||
eventSource.on(event_types.CHAT_DELETED, purgeVectorIndex);
|
||||
eventSource.on(event_types.GROUP_CHAT_DELETED, purgeVectorIndex);
|
||||
});
|
||||
|
@@ -816,12 +816,20 @@ function activateNaturalOrder(members, input, lastMessage, allowSelfResponses, i
|
||||
}
|
||||
|
||||
async function deleteGroup(id) {
|
||||
const group = groups.find((x) => x.id === id);
|
||||
|
||||
const response = await fetch("/deletegroup", {
|
||||
method: "POST",
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({ id: id }),
|
||||
});
|
||||
|
||||
if (group && Array.isArray(group.chats)) {
|
||||
for (const chatId of group.chats) {
|
||||
await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatId);
|
||||
}
|
||||
}
|
||||
|
||||
if (response.ok) {
|
||||
selected_group = null;
|
||||
delete tag_map[id];
|
||||
@@ -1493,6 +1501,8 @@ export async function deleteGroupChat(groupId, chatId) {
|
||||
} else {
|
||||
await createNewGroupChat(groupId);
|
||||
}
|
||||
|
||||
await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatId);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user