Vectors: Allow chunk overlap when forced chunking on delimiter

This commit is contained in:
Cohee
2025-06-15 01:48:17 +03:00
parent cb8fd4f663
commit 441dffc0da
+3 -2
View File
@@ -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 }));