@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.
@@ -19029,7 +19029,10 @@ var sourceAwareUnits = (document, format, normalizedText) => {
19029
19029
  }
19030
19030
  };
19031
19031
  var overlapTail = (value, overlap) => {
19032
- if (overlap <= 0 || value.length <= overlap) {
19032
+ if (overlap <= 0) {
19033
+ return "";
19034
+ }
19035
+ if (value.length <= overlap) {
19033
19036
  return value;
19034
19037
  }
19035
19038
  const candidate = value.slice(-overlap);
@@ -19044,11 +19047,16 @@ var chunkFromUnits = (units, maxChunkLength, chunkOverlap, minChunkLength) => {
19044
19047
  };
19045
19048
  const mergeSmallChunk = (merged2, chunk) => {
19046
19049
  const last = merged2[merged2.length - 1];
19047
- if (!(last && chunk.length < minChunkLength)) {
19050
+ if (last === undefined || chunk.length >= minChunkLength) {
19051
+ merged2.push(chunk);
19052
+ return;
19053
+ }
19054
+ const candidate = normalizeWhitespace(`${last} ${chunk}`);
19055
+ if (candidate.length > maxChunkLength) {
19048
19056
  merged2.push(chunk);
19049
19057
  return;
19050
19058
  }
19051
- merged2[merged2.length - 1] = normalizeWhitespace(`${last} ${chunk}`);
19059
+ merged2[merged2.length - 1] = candidate;
19052
19060
  };
19053
19061
  const appendUnitToChunk = (trimmed) => {
19054
19062
  if (!current) {
@@ -19069,11 +19077,21 @@ var chunkFromUnits = (units, maxChunkLength, chunkOverlap, minChunkLength) => {
19069
19077
  const carry = overlapTail(current, chunkOverlap);
19070
19078
  current = carry.length > 0 ? `${carry} ${trimmed}`.trim() : trimmed;
19071
19079
  };
19080
+ const explodeOversized = (unit) => {
19081
+ if (unit.length <= maxChunkLength)
19082
+ return [unit];
19083
+ const sentences = sentenceUnits(unit);
19084
+ if (sentences.length > 1)
19085
+ return sentences.flatMap(explodeOversized);
19086
+ return fixedUnits(unit, maxChunkLength);
19087
+ };
19072
19088
  for (const unit of units) {
19073
- const trimmed = unit.trim();
19074
- if (!trimmed)
19075
- continue;
19076
- appendUnitToChunk(trimmed);
19089
+ for (const piece of explodeOversized(unit.trim())) {
19090
+ const trimmed = piece.trim();
19091
+ if (!trimmed)
19092
+ continue;
19093
+ appendUnitToChunk(trimmed);
19094
+ }
19077
19095
  }
19078
19096
  if (current) {
19079
19097
  appendChunk(current);
@@ -31307,5 +31325,5 @@ export {
31307
31325
  RAG_NATIVE_QUERY_CANDIDATE_LIMIT
31308
31326
  };
31309
31327
 
31310
- //# debugId=7D3E433ED526972764756E2164756E21
31328
+ //# debugId=86AE9E92B8164CAE64756E2164756E21
31311
31329
  //# sourceMappingURL=index.js.map