From 441dffc0da43f016ea702ae6a4e0b85b57c698f2 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 15 Jun 2025 01:48:17 +0300 Subject: [PATCH] Vectors: Allow chunk overlap when forced chunking on delimiter --- public/scripts/extensions/vectors/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public/scripts/extensions/vectors/index.js b/public/scripts/extensions/vectors/index.js index 81c40b3b9..c89c364af 100644 --- a/public/scripts/extensions/vectors/index.js +++ b/public/scripts/extensions/vectors/index.js @@ -586,9 +586,10 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla const delimiters = getChunkDelimiters(); // Overlap should not be included in chunk size. It will be later compensated by overlapChunks chunkSize = overlapSize > 0 ? (chunkSize - overlapSize) : chunkSize; + const applyOverlap = (x, y, z) => overlapSize > 0 ? overlapChunks(x, y, z, overlapSize) : x; const chunks = settings.only_custom_boundary && settings.force_chunk_delimiter - ? fileText.split(settings.force_chunk_delimiter) - : splitRecursive(fileText, chunkSize, delimiters).map((x, y, z) => overlapSize > 0 ? overlapChunks(x, y, z, overlapSize) : x); + ? fileText.split(settings.force_chunk_delimiter).map(applyOverlap) + : splitRecursive(fileText, chunkSize, delimiters).map(applyOverlap); console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks with ${overlapPercent}% overlap`, chunks); const items = chunks.map((chunk, index) => ({ hash: getStringHash(chunk), text: chunk, index: index }));