Data Bank: display file ingestion progress

aaed09f6063e47543da807fcc20ea8d256f1d4b5

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

1 files changed, +13 -3Ignore whitespace
public/scripts/extensions/vectors/index.js+13 -3
@@ -44,6 +44,9 @@ const MODULE_NAME = 'vectors';
44export const EXTENSION_PROMPT_TAG = '3_vectors';44export const EXTENSION_PROMPT_TAG = '3_vectors';
45export const EXTENSION_PROMPT_TAG_DB = '4_vectors_data_bank';45export const EXTENSION_PROMPT_TAG_DB = '4_vectors_data_bank';
4646
47// Force solo chunks for sources that don't support batching.
48const getBatchSize = () => ['transformers', 'palm', 'ollama'].includes(settings.source) ? 1 : 5;
49
47const settings = {50const settings = {
48 // For both51 // For both
49 source: 'transformers',52 source: 'transformers',
@@ -125,7 +128,7 @@ async function onVectorizeAllClick() {
125 // upon request of a full vectorise128 // upon request of a full vectorise
126 cachedSummaries.clear();129 cachedSummaries.clear();
127130
128 const batchSize = 5;131 const batchSize = getBatchSize();
129 const elapsedLog = [];132 const elapsedLog = [];
130 let finished = false;133 let finished = false;
131 $('#vectorize_progress').show();134 $('#vectorize_progress').show();
@@ -560,7 +563,9 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla
560 fileText = translatedText;563 fileText = translatedText;
561 }564 }
562565
563 const toast = toastr.info('Vectorization may take some time, please wait...', `Ingesting file ${fileName}`);566 const batchSize = getBatchSize();
567 const toastBody = $('<span>').text('This may take a while. Please wait...');
568 const toast = toastr.info(toastBody, `Ingesting file ${fileName}`, { closeButton: false, escapeHtml: false, timeOut: 0, extendedTimeOut: 0 });
564 const overlapSize = Math.round(chunkSize * overlapPercent / 100);569 const overlapSize = Math.round(chunkSize * overlapPercent / 100);
565 const delimiters = getChunkDelimiters();570 const delimiters = getChunkDelimiters();
566 // Overlap should not be included in chunk size. It will be later compensated by overlapChunks571 // Overlap should not be included in chunk size. It will be later compensated by overlapChunks
@@ -569,7 +574,12 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla
569 console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks);574 console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks);
570575
571 const items = chunks.map((chunk, index) => ({ hash: getStringHash(chunk), text: chunk, index: index }));576 const items = chunks.map((chunk, index) => ({ hash: getStringHash(chunk), text: chunk, index: index }));
572 await insertVectorItems(collectionId, items);577
578 for (let i = 0; i < items.length; i += batchSize) {
579 toastBody.text(`${i}/${items.length} (${Math.round((i / items.length) * 100)}%) chunks processed`);
580 const chunkedBatch = items.slice(i, i + batchSize);
581 await insertVectorItems(collectionId, chunkedBatch);
582 }
573583
574 toastr.clear(toast);584 toastr.clear(toast);
575 console.log(`Vectors: Inserted ${chunks.length} vector items for file ${fileName} into ${collectionId}`);585 console.log(`Vectors: Inserted ${chunks.length} vector items for file ${fileName} into ${collectionId}`);