Data Bank: display file ingestion progress
| @@ -44,6 +44,9 @@ const MODULE_NAME = 'vectors'; | |||
| 44 | export const EXTENSION_PROMPT_TAG = '3_vectors'; | 44 | export const EXTENSION_PROMPT_TAG = '3_vectors'; |
| 45 | export const EXTENSION_PROMPT_TAG_DB = '4_vectors_data_bank'; | 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 | const settings = { | 50 | const settings = { |
| 48 | // For both | 51 | // For both |
| 49 | source: 'transformers', | 52 | source: 'transformers', |
| @@ -125,7 +128,7 @@ async function onVectorizeAllClick() { | |||
| 125 | // upon request of a full vectorise | 128 | // upon request of a full vectorise |
| 126 | cachedSummaries.clear(); | 129 | cachedSummaries.clear(); |
| 127 | 130 | ||
| 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 | } |
| 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 | 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 overlapChunks | 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 | 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); |
| 570 | 575 | ||
| 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 | } | ||
| 573 | 583 | ||
| 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}`); |