Vectors: Add only custom boundary chunking
| @@ -82,6 +82,7 @@ const settings = { | ||
| 82 | 82 | chunk_size: 5000, |
| 83 | 83 | chunk_count: 2, |
| 84 | 84 | overlap_percent: 0, |
| 85 | + only_custom_boundary: false, | |
| 85 | 86 | |
| 86 | 87 | // For Data Bank |
| 87 | 88 | size_threshold_db: 5, |
| @@ -571,7 +572,9 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla | ||
| 571 | 572 | const delimiters = getChunkDelimiters(); |
| 572 | 573 | // Overlap should not be included in chunk size. It will be later compensated by overlapChunks |
| 573 | 574 | chunkSize = overlapSize > 0 ? (chunkSize - overlapSize) : chunkSize; |
| 574 | - const chunks = splitRecursive(fileText, chunkSize, delimiters).map((x, y, z) => overlapSize > 0 ? overlapChunks(x, y, z, overlapSize) : x); | |
| 575 | + const chunks = settings.only_custom_boundary && settings.force_chunk_delimiter | |
| 576 | + ? fileText.split(settings.force_chunk_delimiter) | |
| 577 | + : splitRecursive(fileText, chunkSize, delimiters).map((x, y, z) => overlapSize > 0 ? overlapChunks(x, y, z, overlapSize) : x); | |
| 575 | 578 | console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks); |
| 576 | 579 | |
| 577 | 580 | const items = chunks.map((chunk, index) => ({ hash: getStringHash(chunk), text: chunk, index: index })); |
| @@ -1555,6 +1558,12 @@ jQuery(async () => { | ||
| 1555 | 1558 | saveSettingsDebounced(); |
| 1556 | 1559 | }); |
| 1557 | 1560 | |
| 1561 | + $('#vectors_only_custom_boundary').prop('checked', settings.only_custom_boundary).on('input', () => { | |
| 1562 | + settings.only_custom_boundary = !!$('#vectors_only_custom_boundary').prop('checked'); | |
| 1563 | + Object.assign(extension_settings.vectors, settings); | |
| 1564 | + saveSettingsDebounced(); | |
| 1565 | + }); | |
| 1566 | + | |
| 1558 | 1567 | $('#vectors_ollama_pull').on('click', (e) => { |
| 1559 | 1568 | const presetModel = extension_settings.vectors.ollama_model || ''; |
| 1560 | 1569 | e.preventDefault(); |
| @@ -186,6 +186,12 @@ | ||
| 186 | 186 | </label> |
| 187 | 187 | |
| 188 | 188 | <div id="vectors_files_settings" class="marginTopBot5"> |
| 189 | + <label class="checkbox_label" for="vectors_only_custom_boundary" title="Create a chunk for every custom Chunk boundary detected in the file text. Don't chunk on default boundaries."> | |
| 190 | + <input id="vectors_only_custom_boundary" type="checkbox" class="checkbox"> | |
| 191 | + <span data-i18n="Only chunk on custom boundary"> | |
| 192 | + Only chunk on custom boundary | |
| 193 | + </span> | |
| 194 | + </label> | |
| 189 | 195 | <label class="checkbox_label" for="vectors_translate_files" title="This can help with retrieval accuracy if using embedding models that are trained on English data. Uses the selected API from Chat Translation extension settings."> |
| 190 | 196 | <input id="vectors_translate_files" type="checkbox" class="checkbox"> |
| 191 | 197 | <span data-i18n="Translate files into English before processing"> |