@absolutejs/rag 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -19308,7 +19308,10 @@ var sourceAwareUnits = (document, format, normalizedText) => {
19308
19308
  }
19309
19309
  };
19310
19310
  var overlapTail = (value, overlap) => {
19311
- if (overlap <= 0 || value.length <= overlap) {
19311
+ if (overlap <= 0) {
19312
+ return "";
19313
+ }
19314
+ if (value.length <= overlap) {
19312
19315
  return value;
19313
19316
  }
19314
19317
  const candidate = value.slice(-overlap);
@@ -19323,11 +19326,16 @@ var chunkFromUnits = (units, maxChunkLength, chunkOverlap, minChunkLength) => {
19323
19326
  };
19324
19327
  const mergeSmallChunk = (merged2, chunk) => {
19325
19328
  const last = merged2[merged2.length - 1];
19326
- if (!(last && chunk.length < minChunkLength)) {
19329
+ if (last === undefined || chunk.length >= minChunkLength) {
19330
+ merged2.push(chunk);
19331
+ return;
19332
+ }
19333
+ const candidate = normalizeWhitespace(`${last} ${chunk}`);
19334
+ if (candidate.length > maxChunkLength) {
19327
19335
  merged2.push(chunk);
19328
19336
  return;
19329
19337
  }
19330
- merged2[merged2.length - 1] = normalizeWhitespace(`${last} ${chunk}`);
19338
+ merged2[merged2.length - 1] = candidate;
19331
19339
  };
19332
19340
  const appendUnitToChunk = (trimmed) => {
19333
19341
  if (!current) {
@@ -19348,11 +19356,21 @@ var chunkFromUnits = (units, maxChunkLength, chunkOverlap, minChunkLength) => {
19348
19356
  const carry = overlapTail(current, chunkOverlap);
19349
19357
  current = carry.length > 0 ? `${carry} ${trimmed}`.trim() : trimmed;
19350
19358
  };
19359
+ const explodeOversized = (unit) => {
19360
+ if (unit.length <= maxChunkLength)
19361
+ return [unit];
19362
+ const sentences = sentenceUnits(unit);
19363
+ if (sentences.length > 1)
19364
+ return sentences.flatMap(explodeOversized);
19365
+ return fixedUnits(unit, maxChunkLength);
19366
+ };
19351
19367
  for (const unit of units) {
19352
- const trimmed = unit.trim();
19353
- if (!trimmed)
19354
- continue;
19355
- appendUnitToChunk(trimmed);
19368
+ for (const piece of explodeOversized(unit.trim())) {
19369
+ const trimmed = piece.trim();
19370
+ if (!trimmed)
19371
+ continue;
19372
+ appendUnitToChunk(trimmed);
19373
+ }
19356
19374
  }
19357
19375
  if (current) {
19358
19376
  appendChunk(current);
@@ -36337,5 +36355,5 @@ export {
36337
36355
  addRAGEvaluationSuiteCase
36338
36356
  };
36339
36357
 
36340
- //# debugId=E7024598E84C592764756E2164756E21
36358
+ //# debugId=A910166B20BDB76264756E2164756E21
36341
36359
  //# sourceMappingURL=index.js.map