Data Bank: display file ingestion progress
| @@ -44,6 +44,9 @@ const MODULE_NAME = 'vectors'; | ||
| 44 | 44 | export const EXTENSION_PROMPT_TAG = '3_vectors'; |
| 45 | 45 | export const EXTENSION_PROMPT_TAG_DB = '4_vectors_data_bank'; |
| 46 | 46 | |
| 47 | +// Force solo chunks for sources that don't support batching. | |
| 48 | +const getBatchSize = () => ['transformers', 'palm', 'ollama'].includes(settings.source) ? 1 : 5; | |
| 49 | + | |
| 47 | 50 | const settings = { |
| 48 | 51 | // For both |
| 49 | 52 | source: 'transformers', |
| @@ -125,7 +128,7 @@ async function onVectorizeAllClick() { | ||
| 125 | 128 | // upon request of a full vectorise |
| 126 | 129 | cachedSummaries.clear(); |
| 127 | 130 | |
| 128 | 131 | const batchSize = 5getBatchSize(); |
| 129 | 132 | const elapsedLog = []; |
| 130 | 133 | let finished = false; |
| 131 | 134 | $('#vectorize_progress').show(); |
| @@ -560,7 +563,9 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla | ||
| 560 | 563 | fileText = translatedText; |
| 561 | 564 | } |
| 562 | 565 | |
| 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 | 569 | const overlapSize = Math.round(chunkSize * overlapPercent / 100); |
| 565 | 570 | const delimiters = getChunkDelimiters(); |
| 566 | 571 | // 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 | 574 | console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks); |
| 570 | 575 | |
| 571 | 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 | + } | |
| 573 | 583 | |
| 574 | 584 | toastr.clear(toast); |
| 575 | 585 | console.log(`Vectors: Inserted ${chunks.length} vector items for file ${fileName} into ${collectionId}`); |