Vectors: Add only custom boundary chunking
| @@ -82,6 +82,7 @@ const settings = { | |||
| 82 | chunk_size: 5000, | 82 | chunk_size: 5000, |
| 83 | chunk_count: 2, | 83 | chunk_count: 2, |
| 84 | overlap_percent: 0, | 84 | overlap_percent: 0, |
| 85 | only_custom_boundary: false, | ||
| 85 | 86 | ||
| 86 | // For Data Bank | 87 | // For Data Bank |
| 87 | size_threshold_db: 5, | 88 | size_threshold_db: 5, |
| @@ -571,7 +572,9 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla | |||
| 571 | const delimiters = getChunkDelimiters(); | 572 | const delimiters = getChunkDelimiters(); |
| 572 | // Overlap should not be included in chunk size. It will be later compensated by overlapChunks | 573 | // Overlap should not be included in chunk size. It will be later compensated by overlapChunks |
| 573 | chunkSize = overlapSize > 0 ? (chunkSize - overlapSize) : chunkSize; | 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 | console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks); | 578 | console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks); |
| 576 | 579 | ||
| 577 | const items = chunks.map((chunk, index) => ({ hash: getStringHash(chunk), text: chunk, index: index })); | 580 | const items = chunks.map((chunk, index) => ({ hash: getStringHash(chunk), text: chunk, index: index })); |
| @@ -1555,6 +1558,12 @@ jQuery(async () => { | |||
| 1555 | saveSettingsDebounced(); | 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 | $('#vectors_ollama_pull').on('click', (e) => { | 1567 | $('#vectors_ollama_pull').on('click', (e) => { |
| 1559 | const presetModel = extension_settings.vectors.ollama_model || ''; | 1568 | const presetModel = extension_settings.vectors.ollama_model || ''; |
| 1560 | e.preventDefault(); | 1569 | e.preventDefault(); |
| @@ -186,6 +186,12 @@ | |||
| 186 | </label> | 186 | </label> |
| 187 | 187 | ||
| 188 | <div id="vectors_files_settings" class="marginTopBot5"> | 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 | <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."> | 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 | <input id="vectors_translate_files" type="checkbox" class="checkbox"> | 196 | <input id="vectors_translate_files" type="checkbox" class="checkbox"> |
| 191 | <span data-i18n="Translate files into English before processing"> | 197 | <span data-i18n="Translate files into English before processing"> |