Vector Storage: Fix query summarizing for WI and files

c88edaa4ed20c6b22ca89fff91b2001a2fb08c8e

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +7 -6Ignore whitespace
public/scripts/extensions/vectors/index.js+7 -6
@@ -401,7 +401,7 @@ async function processFiles(chat) {
401 const dataBankCollectionIds = await ingestDataBankAttachments();401 const dataBankCollectionIds = await ingestDataBankAttachments();
402402
403 if (dataBankCollectionIds.length) {403 if (dataBankCollectionIds.length) {
404 const queryText = await getQueryText(chat);404 const queryText = await getQueryText(chat, 'file');
405 await injectDataBankChunks(queryText, dataBankCollectionIds);405 await injectDataBankChunks(queryText, dataBankCollectionIds);
406 }406 }
407407
@@ -435,7 +435,7 @@ async function processFiles(chat) {
435 await vectorizeFile(fileText, fileName, collectionId, settings.chunk_size, settings.overlap_percent);435 await vectorizeFile(fileText, fileName, collectionId, settings.chunk_size, settings.overlap_percent);
436 }436 }
437437
438 const queryText = await getQueryText(chat);438 const queryText = await getQueryText(chat, 'file');
439 const fileChunks = await retrieveFileChunks(queryText, collectionId);439 const fileChunks = await retrieveFileChunks(queryText, collectionId);
440440
441 message.mes = `${fileChunks}\n\n${message.mes}`;441 message.mes = `${fileChunks}\n\n${message.mes}`;
@@ -596,7 +596,7 @@ async function rearrangeChat(chat) {
596 return;596 return;
597 }597 }
598598
599 const queryText = await getQueryText(chat);599 const queryText = await getQueryText(chat, 'chat');
600600
601 if (queryText.length === 0) {601 if (queryText.length === 0) {
602 console.debug('Vectors: No text to query');602 console.debug('Vectors: No text to query');
@@ -683,15 +683,16 @@ const onChatEvent = debounce(async () => await moduleWorker.update(), debounce_t
683/**683/**
684 * Gets the text to query from the chat684 * Gets the text to query from the chat
685 * @param {object[]} chat Chat messages685 * @param {object[]} chat Chat messages
686 * @param {'file'|'chat'|'world-info'} initiator Initiator of the query
686 * @returns {Promise<string>} Text to query687 * @returns {Promise<string>} Text to query
687 */688 */
688async function getQueryText(chat) {689async function getQueryText(chat, initiator) {
689 let queryText = '';690 let queryText = '';
690 let i = 0;691 let i = 0;
691692
692 let hashedMessages = chat.map(x => ({ text: String(substituteParams(x.mes)) }));693 let hashedMessages = chat.map(x => ({ text: String(substituteParams(x.mes)) }));
693694
694 if (settings.summarize && settings.summarize_sent) {695 if (initiator === 'chat' && settings.enabled_chats && settings.summarize && settings.summarize_sent) {
695 hashedMessages = await summarize(hashedMessages, settings.summary_source);696 hashedMessages = await summarize(hashedMessages, settings.summary_source);
696 }697 }
697698
@@ -1279,7 +1280,7 @@ async function activateWorldInfo(chat) {
1279 }1280 }
12801281
1281 // Perform a multi-query1282 // Perform a multi-query
1282 const queryText = await getQueryText(chat);1283 const queryText = await getQueryText(chat, 'world-info');
12831284
1284 if (queryText.length === 0) {1285 if (queryText.length === 0) {
1285 console.debug('Vectors: No text to query for WI');1286 console.debug('Vectors: No text to query for WI');