@remnic/core 9.57.5 → 9.57.6
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/access-admin-ops-surface.d.ts +1 -1
- package/dist/access-authorization-probe.d.ts +1 -1
- package/dist/access-boundary.d.ts +1 -1
- package/dist/access-cli.js +5 -5
- package/dist/access-extraction-force-flush.d.ts +1 -1
- package/dist/access-http-lcm-compaction.d.ts +1 -1
- package/dist/access-http-lifecycle-flush.d.ts +1 -1
- package/dist/access-http-offline-stream.d.ts +1 -1
- package/dist/access-http.d.ts +2 -2
- package/dist/access-lcm-surface.d.ts +1 -1
- package/dist/access-mcp.d.ts +1 -1
- package/dist/access-observe-write-surface.d.ts +1 -1
- package/dist/access-operations.d.ts +4 -4
- package/dist/access-recall-concurrency.d.ts +1 -1
- package/dist/access-recall-response.d.ts +1 -1
- package/dist/access-recall-surface.d.ts +1 -1
- package/dist/access-schema.d.ts +88 -88
- package/dist/access-service-helpers.d.ts +1 -1
- package/dist/access-service.d.ts +1 -1
- package/dist/access-surface-catalog.d.ts +1 -1
- package/dist/buffer-surprise.js +3 -3
- package/dist/{chunk-AW4A4XOP.js → chunk-DUHMYBVE.js} +2 -2
- package/dist/chunk-LMXUWAXW.js +200 -0
- package/dist/chunk-LMXUWAXW.js.map +1 -0
- package/dist/{chunk-P4BC54KI.js → chunk-P6WBAR27.js} +8 -32
- package/dist/chunk-P6WBAR27.js.map +1 -0
- package/dist/{chunk-C5B3CIMJ.js → chunk-REVMY7RA.js} +4 -4
- package/dist/{chunk-66SLUXKM.js → chunk-TEHPIMXD.js} +2 -2
- package/dist/chunking.d.ts +3 -1
- package/dist/chunking.js +7 -3
- package/dist/{cli-DTOkYhKI.d.ts → cli-CQdYilcx.d.ts} +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +2 -2
- package/dist/external-wiki-access.d.ts +1 -1
- package/dist/external-wiki-mcp-tools.d.ts +1 -1
- package/dist/index.d.ts +680 -680
- package/dist/index.js +5 -5
- package/dist/mcp-memory-inspector-app.d.ts +1 -1
- package/dist/orchestrator.js +5 -5
- package/dist/{public-http-C01DLhAp.d.ts → public-http-Dw0bJhcC.d.ts} +1 -1
- package/dist/schemas.d.ts +138 -138
- package/dist/semantic-chunking.js +2 -2
- package/dist/shared-context/manager.d.ts +8 -8
- package/dist/support-passport/index.d.ts +4 -4
- package/dist/transfer/types.d.ts +66 -66
- package/package.json +2 -2
- package/src/chunking.ts +119 -34
- package/src/semantic-chunking.ts +10 -48
- package/dist/chunk-P4BC54KI.js.map +0 -1
- package/dist/chunk-UQ7RN5HK.js +0 -126
- package/dist/chunk-UQ7RN5HK.js.map +0 -1
- package/dist/{access-service-D9xXmKvd.d.ts → access-service-4DO8XMq6.d.ts} +64 -64
- /package/dist/{chunk-AW4A4XOP.js.map → chunk-DUHMYBVE.js.map} +0 -0
- /package/dist/{chunk-C5B3CIMJ.js.map → chunk-REVMY7RA.js.map} +0 -0
- /package/dist/{chunk-66SLUXKM.js.map → chunk-TEHPIMXD.js.map} +0 -0
package/src/chunking.ts
CHANGED
|
@@ -47,51 +47,136 @@ function estimateTokens(text: string): number {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Split text into sentences.
|
|
50
|
-
*
|
|
50
|
+
*
|
|
51
|
+
* The scan stays linear and does not use a backtracking regular expression.
|
|
52
|
+
* ASCII punctuation keeps its old whitespace rule. Unicode terminators also
|
|
53
|
+
* split when the next sentence starts immediately, as in CJK text.
|
|
51
54
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
const UNICODE_SENTENCE_TERMINATORS = "。.!?؟۔।॥。…";
|
|
56
|
+
const ASCII_SENTENCE_TERMINATORS = ".!?";
|
|
57
|
+
const CJK_NO_SPACE_TERMINATORS = "。.!?。";
|
|
58
|
+
const CLOSING_PUNCTUATION = "\"'”’»」』)]】〉》)]}";
|
|
59
|
+
const DIGITS = "01234567890123456789";
|
|
60
|
+
const SENTENCE_SEGMENTER =
|
|
61
|
+
typeof Intl.Segmenter === "function"
|
|
62
|
+
? new Intl.Segmenter(undefined, { granularity: "sentence" })
|
|
63
|
+
: undefined;
|
|
64
|
+
|
|
65
|
+
function isSentenceTerminator(character: string): boolean {
|
|
66
|
+
return (
|
|
67
|
+
ASCII_SENTENCE_TERMINATORS.includes(character) ||
|
|
68
|
+
UNICODE_SENTENCE_TERMINATORS.includes(character)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isCjk(character: string): boolean {
|
|
73
|
+
return /[\u3000-\u9fff\uf900-\ufaff\uac00-\ud7af]/u.test(character);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type SentenceList = string[] & { separators: string[] };
|
|
77
|
+
|
|
78
|
+
function splitSentencesFallback(text: string): SentenceList {
|
|
79
|
+
const sentences = [] as unknown as SentenceList;
|
|
80
|
+
Object.defineProperty(sentences, "separators", {
|
|
81
|
+
value: [],
|
|
82
|
+
writable: true,
|
|
83
|
+
});
|
|
66
84
|
let start = 0;
|
|
85
|
+
let separator = "";
|
|
67
86
|
for (let i = 0; i < text.length; i++) {
|
|
68
87
|
const ch = text[i];
|
|
69
|
-
if (
|
|
70
|
-
|
|
88
|
+
if (!isSentenceTerminator(ch)) continue;
|
|
89
|
+
|
|
71
90
|
let end = i;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
let hasUnicodeTerminator = UNICODE_SENTENCE_TERMINATORS.includes(ch);
|
|
92
|
+
while (end + 1 < text.length && isSentenceTerminator(text[end + 1])) {
|
|
93
|
+
end++;
|
|
94
|
+
hasUnicodeTerminator ||= UNICODE_SENTENCE_TERMINATORS.includes(text[end]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const isFullwidthDecimal =
|
|
98
|
+
ch === "." &&
|
|
99
|
+
DIGITS.includes(text[i - 1] ?? "") &&
|
|
100
|
+
DIGITS.includes(text[end + 1] ?? "");
|
|
101
|
+
while (end + 1 < text.length && CLOSING_PUNCTUATION.includes(text[end + 1])) {
|
|
75
102
|
end++;
|
|
76
103
|
}
|
|
104
|
+
|
|
77
105
|
const after = text[end + 1];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
106
|
+
const boundary =
|
|
107
|
+
!isFullwidthDecimal &&
|
|
108
|
+
(hasUnicodeTerminator || after === undefined || /\s/u.test(after));
|
|
109
|
+
if (boundary) {
|
|
82
110
|
const sentence = text.slice(start, end + 1).trim();
|
|
83
|
-
if (sentence.length > 0)
|
|
84
|
-
|
|
111
|
+
if (sentence.length > 0) {
|
|
112
|
+
sentences.push(sentence);
|
|
113
|
+
if (sentences.length > 1) sentences.separators.push(separator);
|
|
114
|
+
}
|
|
115
|
+
let nextStart = end + 1;
|
|
116
|
+
while (nextStart < text.length && /\s/u.test(text[nextStart])) nextStart++;
|
|
117
|
+
separator = text.slice(end + 1, nextStart);
|
|
118
|
+
start = nextStart;
|
|
85
119
|
}
|
|
86
120
|
i = end;
|
|
87
121
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
122
|
+
|
|
123
|
+
const remaining = text.slice(start).trim();
|
|
124
|
+
if (remaining.length > 0) {
|
|
125
|
+
sentences.push(remaining);
|
|
126
|
+
if (sentences.length > 1) sentences.separators.push(separator);
|
|
92
127
|
}
|
|
93
128
|
return sentences;
|
|
94
129
|
}
|
|
130
|
+
export function splitSentences(text: string): string[] {
|
|
131
|
+
const canUseSegmenter =
|
|
132
|
+
SENTENCE_SEGMENTER !== undefined &&
|
|
133
|
+
!/\s/u.test(text) &&
|
|
134
|
+
[...text].some((character) => UNICODE_SENTENCE_TERMINATORS.includes(character));
|
|
135
|
+
if (canUseSegmenter) {
|
|
136
|
+
const segments = Array.from(SENTENCE_SEGMENTER.segment(text), ({ segment }) =>
|
|
137
|
+
segment.trim(),
|
|
138
|
+
).filter((segment) => segment.length > 0) as SentenceList;
|
|
139
|
+
if (
|
|
140
|
+
segments.length > 1 &&
|
|
141
|
+
segments.slice(0, -1).every((segment) =>
|
|
142
|
+
[...segment].some((character) =>
|
|
143
|
+
UNICODE_SENTENCE_TERMINATORS.includes(character),
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
) {
|
|
147
|
+
Object.defineProperty(segments, "separators", {
|
|
148
|
+
value: Array(segments.length - 1).fill(""),
|
|
149
|
+
writable: true,
|
|
150
|
+
});
|
|
151
|
+
return segments;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return splitSentencesFallback(text);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function endsWithoutSpace(text: string): boolean {
|
|
158
|
+
let index = text.length - 1;
|
|
159
|
+
while (index >= 0 && CLOSING_PUNCTUATION.includes(text[index])) index--;
|
|
160
|
+
const terminator = text[index] ?? "";
|
|
161
|
+
if (CJK_NO_SPACE_TERMINATORS.includes(terminator)) {
|
|
162
|
+
return isCjk(text[index - 1] ?? "");
|
|
163
|
+
}
|
|
164
|
+
return terminator === "…" && isCjk(text[index - 1] ?? "");
|
|
165
|
+
}
|
|
166
|
+
export function joinSentences(sentences: string[]): string {
|
|
167
|
+
let result = "";
|
|
168
|
+
const separators = (sentences as Partial<SentenceList>).separators;
|
|
169
|
+
for (let i = 0; i < sentences.length; i++) {
|
|
170
|
+
const sentence = sentences[i];
|
|
171
|
+
if (result.length > 0) {
|
|
172
|
+
const separator = separators?.[i - 1];
|
|
173
|
+
result += separator ?? (endsWithoutSpace(result) ? "" : " ");
|
|
174
|
+
}
|
|
175
|
+
result += sentence;
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
95
180
|
|
|
96
181
|
/**
|
|
97
182
|
* Chunk content into overlapping segments at sentence boundaries.
|
|
@@ -152,7 +237,7 @@ export function chunkContent(
|
|
|
152
237
|
|
|
153
238
|
if (atTarget || isLastSentence) {
|
|
154
239
|
// Create chunk from accumulated sentences
|
|
155
|
-
const chunkContent = currentChunkSentences
|
|
240
|
+
const chunkContent = joinSentences(currentChunkSentences);
|
|
156
241
|
chunks.push({
|
|
157
242
|
content: chunkContent,
|
|
158
243
|
index: chunkIndex,
|
|
@@ -216,14 +301,14 @@ export function reassembleChunks(chunks: string[]): string {
|
|
|
216
301
|
const prevEnd = prevSentences.slice(-(j + 1));
|
|
217
302
|
const currStart = currSentences.slice(0, j + 1);
|
|
218
303
|
|
|
219
|
-
if (prevEnd
|
|
304
|
+
if (joinSentences(prevEnd) === joinSentences(currStart)) {
|
|
220
305
|
overlapCount = j + 1;
|
|
221
306
|
}
|
|
222
307
|
}
|
|
223
308
|
|
|
224
309
|
// Add non-overlapping portion
|
|
225
310
|
if (overlapCount > 0 && overlapCount < currSentences.length) {
|
|
226
|
-
result.push(currSentences.slice(overlapCount)
|
|
311
|
+
result.push(joinSentences(currSentences.slice(overlapCount)));
|
|
227
312
|
} else if (overlapCount === 0) {
|
|
228
313
|
// No detected overlap, add full chunk
|
|
229
314
|
result.push(currChunk);
|
|
@@ -231,5 +316,5 @@ export function reassembleChunks(chunks: string[]): string {
|
|
|
231
316
|
// If overlapCount === currSentences.length, skip (fully contained)
|
|
232
317
|
}
|
|
233
318
|
|
|
234
|
-
return result
|
|
319
|
+
return joinSentences(result);
|
|
235
320
|
}
|
package/src/semantic-chunking.ts
CHANGED
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
* natural topic boundaries, producing more coherent chunks.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
chunkContent,
|
|
11
|
+
joinSentences,
|
|
12
|
+
splitSentences,
|
|
13
|
+
type Chunk,
|
|
14
|
+
type ChunkResult,
|
|
15
|
+
} from "./chunking.js";
|
|
10
16
|
|
|
11
17
|
// ---------------------------------------------------------------------------
|
|
12
18
|
// Configuration
|
|
@@ -177,50 +183,6 @@ export function findLocalMinima(
|
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
// ---------------------------------------------------------------------------
|
|
180
|
-
// Sentence tokenizer
|
|
181
|
-
// ---------------------------------------------------------------------------
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Split text into sentences at punctuation boundaries.
|
|
185
|
-
* Preserves punctuation with the preceding sentence.
|
|
186
|
-
*/
|
|
187
|
-
function splitSentences(text: string): string[] {
|
|
188
|
-
// Linear character scan instead of a regex. Every regex form of this split is
|
|
189
|
-
// either polynomial (CodeQL js/polynomial-redos) or — once bounded/anchored to
|
|
190
|
-
// satisfy CodeQL — mishandles long runs or interior punctuation (a global
|
|
191
|
-
// match drops a skipped prefix; a sticky match stops at the first non-boundary
|
|
192
|
-
// `.`, e.g. "v1.2.3" / "example.com", returning the whole document as one
|
|
193
|
-
// sentence and bypassing chunking). The scan is O(n), drops nothing, and
|
|
194
|
-
// handles interior punctuation correctly; normal prose splits identically to
|
|
195
|
-
// the previous /[^.!?]*[.!?]+(?:\s+|$)/g form.
|
|
196
|
-
const sentences: string[] = [];
|
|
197
|
-
let start = 0;
|
|
198
|
-
for (let i = 0; i < text.length; i++) {
|
|
199
|
-
const ch = text[i];
|
|
200
|
-
if (ch !== "." && ch !== "!" && ch !== "?") continue;
|
|
201
|
-
let end = i;
|
|
202
|
-
while (end + 1 < text.length) {
|
|
203
|
-
const n = text[end + 1];
|
|
204
|
-
if (n !== "." && n !== "!" && n !== "?") break;
|
|
205
|
-
end++;
|
|
206
|
-
}
|
|
207
|
-
const after = text[end + 1];
|
|
208
|
-
// A real boundary only if the terminator run ends the string or is followed
|
|
209
|
-
// by whitespace. Interior punctuation (no following whitespace) is left in
|
|
210
|
-
// place and the scan continues.
|
|
211
|
-
if (after === undefined || /\s/.test(after)) {
|
|
212
|
-
const sentence = text.slice(start, end + 1).trim();
|
|
213
|
-
if (sentence.length > 0) sentences.push(sentence);
|
|
214
|
-
start = end + 1;
|
|
215
|
-
}
|
|
216
|
-
i = end;
|
|
217
|
-
}
|
|
218
|
-
if (start < text.length) {
|
|
219
|
-
const remaining = text.slice(start).trim();
|
|
220
|
-
if (remaining.length > 0) sentences.push(remaining);
|
|
221
|
-
}
|
|
222
|
-
return sentences;
|
|
223
|
-
}
|
|
224
186
|
|
|
225
187
|
// ---------------------------------------------------------------------------
|
|
226
188
|
// Token estimation
|
|
@@ -316,7 +278,7 @@ function mergeShortSegments(
|
|
|
316
278
|
|
|
317
279
|
for (let i = 0; i < segments.length; i++) {
|
|
318
280
|
buffer = [...buffer, ...segments[i]];
|
|
319
|
-
const tokenCount = estimateTokens(buffer
|
|
281
|
+
const tokenCount = estimateTokens(joinSentences(buffer));
|
|
320
282
|
|
|
321
283
|
if (tokenCount >= minTokens || i === segments.length - 1) {
|
|
322
284
|
merged.push(buffer);
|
|
@@ -344,7 +306,7 @@ function splitLongSegment(
|
|
|
344
306
|
maxTokens: number,
|
|
345
307
|
targetTokens: number,
|
|
346
308
|
): SemanticChunk[] {
|
|
347
|
-
const text = segment
|
|
309
|
+
const text = joinSentences(segment);
|
|
348
310
|
// Cap targetTokens to maxTokens so recursive splitting never produces
|
|
349
311
|
// segments larger than the configured maximum (Finding 2, PR #420).
|
|
350
312
|
const cappedTarget = Math.min(targetTokens, maxTokens);
|
|
@@ -511,7 +473,7 @@ export async function semanticChunkContent(
|
|
|
511
473
|
|
|
512
474
|
for (let segIdx = 0; segIdx < segments.length; segIdx++) {
|
|
513
475
|
const segment = segments[segIdx];
|
|
514
|
-
const segText = segment
|
|
476
|
+
const segText = joinSentences(segment);
|
|
515
477
|
const segTokens = estimateTokens(segText);
|
|
516
478
|
|
|
517
479
|
if (segTokens > cfg.maxTokens) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/semantic-chunking.ts"],"sourcesContent":["/**\n * Semantic Chunking with Smoothing-Based Topic Boundaries (Issue #368)\n *\n * An optional alternative to the recursive chunker in chunking.ts.\n * Uses sentence embeddings + cosine similarity + smoothing to detect\n * natural topic boundaries, producing more coherent chunks.\n */\n\nimport { chunkContent, type Chunk, type ChunkResult } from \"./chunking.js\";\n\n// ---------------------------------------------------------------------------\n// Configuration\n// ---------------------------------------------------------------------------\n\nexport interface SemanticChunkingConfig {\n /** Target tokens per chunk. Default: 200. */\n targetTokens: number;\n /** Minimum tokens for a segment before merging with neighbor. Default: 100. */\n minTokens: number;\n /** Maximum tokens for a segment before recursive splitting. Default: 400. */\n maxTokens: number;\n /** Window size for the moving-average smoothing filter. Default: 3. */\n smoothingWindowSize: number;\n /** How many standard deviations below the mean constitutes a boundary. Default: 1.0. */\n boundaryThresholdStdDevs: number;\n /** Batch size for embedding requests. Default: 32. */\n embeddingBatchSize: number;\n /** Fall back to recursive chunking when embeddings are unavailable. Default: true. */\n fallbackToRecursive: boolean;\n}\n\nexport const DEFAULT_SEMANTIC_CHUNKING_CONFIG: SemanticChunkingConfig = {\n targetTokens: 200,\n minTokens: 100,\n maxTokens: 400,\n smoothingWindowSize: 3,\n boundaryThresholdStdDevs: 1.0,\n embeddingBatchSize: 32,\n fallbackToRecursive: true,\n};\n\n// ---------------------------------------------------------------------------\n// Result types\n// ---------------------------------------------------------------------------\n\nexport interface SemanticChunk extends Chunk {\n /** Optional topic hint derived from position. */\n topicLabel?: string;\n /** Cosine similarity score at the trailing boundary of this chunk. */\n boundaryScore: number;\n}\n\nexport interface SemanticChunkResult {\n /** Whether content was split into multiple chunks. */\n chunked: boolean;\n /** The chunks produced. */\n chunks: SemanticChunk[];\n /** Sentence indices where topic splits occurred. */\n boundaries: number[];\n /** Which algorithm produced the result. */\n method: \"semantic\" | \"recursive-fallback\";\n}\n\n// ---------------------------------------------------------------------------\n// Embedding function signature\n// ---------------------------------------------------------------------------\n\n/** Caller-provided function that embeds an array of texts, returning vectors. */\nexport type EmbedFn = (texts: string[]) => Promise<number[][]>;\n\n// ---------------------------------------------------------------------------\n// Math utilities (exported for testing)\n// ---------------------------------------------------------------------------\n\n/**\n * Cosine similarity between two vectors.\n * Returns a value in [-1, 1]. Identical direction = 1, orthogonal = 0.\n *\n * NOTE: This duplicates cosineSimilarity in recall-mmr.ts and embedding-fallback.ts.\n * Consider extracting to a shared math utility in a future refactor.\n */\nexport function cosineSimilarity(a: number[], b: number[]): number {\n if (a.length !== b.length) {\n throw new Error(\n `cosineSimilarity: vector length mismatch (${a.length} vs ${b.length})`,\n );\n }\n if (a.length === 0) return 0;\n\n let dot = 0;\n let magA = 0;\n let magB = 0;\n for (let i = 0; i < a.length; i++) {\n dot += a[i] * b[i];\n magA += a[i] * a[i];\n magB += b[i] * b[i];\n }\n\n const denom = Math.sqrt(magA) * Math.sqrt(magB);\n if (denom === 0) return 0;\n return dot / denom;\n}\n\n/**\n * Arithmetic mean of a numeric series.\n */\nexport function mean(series: number[]): number {\n if (series.length === 0) return 0;\n let sum = 0;\n for (const v of series) sum += v;\n return sum / series.length;\n}\n\n/**\n * Population standard deviation of a numeric series.\n */\nexport function stddev(series: number[]): number {\n if (series.length === 0) return 0;\n const m = mean(series);\n let sumSq = 0;\n for (const v of series) {\n const d = v - m;\n sumSq += d * d;\n }\n return Math.sqrt(sumSq / series.length);\n}\n\n/**\n * Simple moving average over a 1D series.\n * The window is centered: for window size W, each output[i] averages\n * series[i - floor(W/2) .. i + floor(W/2)], clamped to bounds.\n *\n * Even window sizes are rounded up to the next odd value so the window\n * is symmetric around the center point (Finding 4, PR #420).\n */\nexport function movingAverage(series: number[], windowSize: number): number[] {\n if (series.length === 0) return [];\n if (windowSize < 1) windowSize = 1;\n // Round even values up to the next odd so the window is symmetric.\n if (windowSize % 2 === 0) windowSize = windowSize + 1;\n\n const halfW = Math.floor(windowSize / 2);\n const result: number[] = new Array(series.length);\n\n for (let i = 0; i < series.length; i++) {\n const lo = Math.max(0, i - halfW);\n const hi = Math.min(series.length - 1, i + halfW);\n let sum = 0;\n for (let j = lo; j <= hi; j++) sum += series[j];\n result[i] = sum / (hi - lo + 1);\n }\n return result;\n}\n\n/**\n * Find indices in the series that are local minima AND below the threshold.\n * A local minimum is a point lower than both its immediate neighbors\n * (or lower-or-equal at series boundaries).\n */\nexport function findLocalMinima(\n series: number[],\n threshold: number,\n): number[] {\n if (series.length <= 2) return [];\n\n const minima: number[] = [];\n for (let i = 1; i < series.length - 1; i++) {\n if (\n series[i] < series[i - 1] &&\n series[i] < series[i + 1] &&\n series[i] < threshold\n ) {\n minima.push(i);\n }\n }\n return minima;\n}\n\n// ---------------------------------------------------------------------------\n// Sentence tokenizer\n// ---------------------------------------------------------------------------\n\n/**\n * Split text into sentences at punctuation boundaries.\n * Preserves punctuation with the preceding sentence.\n */\nfunction splitSentences(text: string): string[] {\n // Linear character scan instead of a regex. Every regex form of this split is\n // either polynomial (CodeQL js/polynomial-redos) or — once bounded/anchored to\n // satisfy CodeQL — mishandles long runs or interior punctuation (a global\n // match drops a skipped prefix; a sticky match stops at the first non-boundary\n // `.`, e.g. \"v1.2.3\" / \"example.com\", returning the whole document as one\n // sentence and bypassing chunking). The scan is O(n), drops nothing, and\n // handles interior punctuation correctly; normal prose splits identically to\n // the previous /[^.!?]*[.!?]+(?:\\s+|$)/g form.\n const sentences: string[] = [];\n let start = 0;\n for (let i = 0; i < text.length; i++) {\n const ch = text[i];\n if (ch !== \".\" && ch !== \"!\" && ch !== \"?\") continue;\n let end = i;\n while (end + 1 < text.length) {\n const n = text[end + 1];\n if (n !== \".\" && n !== \"!\" && n !== \"?\") break;\n end++;\n }\n const after = text[end + 1];\n // A real boundary only if the terminator run ends the string or is followed\n // by whitespace. Interior punctuation (no following whitespace) is left in\n // place and the scan continues.\n if (after === undefined || /\\s/.test(after)) {\n const sentence = text.slice(start, end + 1).trim();\n if (sentence.length > 0) sentences.push(sentence);\n start = end + 1;\n }\n i = end;\n }\n if (start < text.length) {\n const remaining = text.slice(start).trim();\n if (remaining.length > 0) sentences.push(remaining);\n }\n return sentences;\n}\n\n// ---------------------------------------------------------------------------\n// Token estimation\n// ---------------------------------------------------------------------------\n\n/** Rough token estimate: ~4 chars per token for English. */\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n// ---------------------------------------------------------------------------\n// Core semantic chunking\n// ---------------------------------------------------------------------------\n\n/**\n * Batch-embed sentences using the provided embed function.\n * Respects the configured batch size.\n */\nasync function batchEmbed(\n sentences: string[],\n embedFn: EmbedFn,\n batchSize: number,\n): Promise<number[][]> {\n const allEmbeddings: number[][] = [];\n\n for (let i = 0; i < sentences.length; i += batchSize) {\n const batch = sentences.slice(i, i + batchSize);\n const batchResult = await embedFn(batch);\n for (const vec of batchResult) {\n allEmbeddings.push(vec);\n }\n }\n\n return allEmbeddings;\n}\n\nfunction findEmbeddingDimensionMismatch(\n embeddings: number[][],\n): { expected: number; actual: number; index: number } | null {\n if (embeddings.length <= 1) return null;\n const expected = embeddings[0].length;\n for (let i = 1; i < embeddings.length; i++) {\n const actual = embeddings[i].length;\n if (actual !== expected) {\n return { expected, actual, index: i };\n }\n }\n return null;\n}\n\n/**\n * Build segments from boundary indices.\n * boundaries are sentence indices at which splits occur (i.e., the split\n * happens AFTER the boundary index sentence).\n */\nfunction buildSegments(\n sentences: string[],\n boundaries: number[],\n): string[][] {\n const sorted = [...boundaries].sort((a, b) => a - b);\n const segments: string[][] = [];\n let start = 0;\n\n for (const b of sorted) {\n // Split after sentence at index b: segment is [start .. b]\n const splitPoint = b + 1;\n if (splitPoint > start && splitPoint <= sentences.length) {\n segments.push(sentences.slice(start, splitPoint));\n start = splitPoint;\n }\n }\n\n // Remaining sentences\n if (start < sentences.length) {\n segments.push(sentences.slice(start));\n }\n\n return segments;\n}\n\n/**\n * Merge short segments (below minTokens) with their neighbor.\n * Prefers merging forward; falls back to merging backward.\n */\nfunction mergeShortSegments(\n segments: string[][],\n minTokens: number,\n): string[][] {\n if (segments.length <= 1) return segments;\n\n const merged: string[][] = [];\n let buffer: string[] = [];\n\n for (let i = 0; i < segments.length; i++) {\n buffer = [...buffer, ...segments[i]];\n const tokenCount = estimateTokens(buffer.join(\" \"));\n\n if (tokenCount >= minTokens || i === segments.length - 1) {\n merged.push(buffer);\n buffer = [];\n }\n }\n\n // If the last merge left a dangling buffer, attach it to the last segment\n if (buffer.length > 0) {\n if (merged.length > 0) {\n merged[merged.length - 1] = [...merged[merged.length - 1], ...buffer];\n } else {\n merged.push(buffer);\n }\n }\n\n return merged;\n}\n\n/**\n * Split an oversized segment using recursive chunking.\n */\nfunction splitLongSegment(\n segment: string[],\n maxTokens: number,\n targetTokens: number,\n): SemanticChunk[] {\n const text = segment.join(\" \");\n // Cap targetTokens to maxTokens so recursive splitting never produces\n // segments larger than the configured maximum (Finding 2, PR #420).\n const cappedTarget = Math.min(targetTokens, maxTokens);\n const result: ChunkResult = chunkContent(text, {\n targetTokens: cappedTarget,\n minTokens: Math.min(cappedTarget, maxTokens),\n overlapSentences: 0,\n });\n\n return result.chunks.map((c) => ({\n content: c.content,\n index: c.index,\n tokenCount: c.tokenCount,\n boundaryScore: 0,\n }));\n}\n\n/**\n * Semantic chunking with smoothing-based topic boundary detection.\n *\n * @param content - Full text to chunk.\n * @param embedFn - Async function that embeds an array of texts.\n * @param config - Optional partial config overrides.\n * @returns SemanticChunkResult\n */\nexport async function semanticChunkContent(\n content: string,\n embedFn: EmbedFn,\n config?: Partial<SemanticChunkingConfig>,\n): Promise<SemanticChunkResult> {\n const cfg: SemanticChunkingConfig = {\n ...DEFAULT_SEMANTIC_CHUNKING_CONFIG,\n ...config,\n };\n\n // Guard against non-positive batch size which would cause an infinite loop\n const batchSize = Math.max(1, cfg.embeddingBatchSize);\n\n // --- Empty / trivially short input ---\n if (!content || content.trim().length === 0) {\n return {\n chunked: false,\n chunks: [],\n boundaries: [],\n method: \"semantic\",\n };\n }\n\n const sentences = splitSentences(content);\n\n if (sentences.length <= 1) {\n const tokenCount = estimateTokens(content);\n return {\n chunked: false,\n chunks: [\n {\n content: content.trim(),\n index: 0,\n tokenCount,\n boundaryScore: 1,\n },\n ],\n boundaries: [],\n method: \"semantic\",\n };\n }\n\n // If total tokens is short enough, return as single chunk\n const totalTokens = estimateTokens(content);\n if (totalTokens <= cfg.minTokens) {\n return {\n chunked: false,\n chunks: [\n {\n content: content.trim(),\n index: 0,\n tokenCount: totalTokens,\n boundaryScore: 1,\n },\n ],\n boundaries: [],\n method: \"semantic\",\n };\n }\n\n // --- Attempt embedding ---\n let embeddings: number[][];\n try {\n embeddings = await batchEmbed(sentences, embedFn, batchSize);\n } catch {\n // Embedding failed — fall back if configured\n if (cfg.fallbackToRecursive) {\n return buildRecursiveFallback(content, cfg);\n }\n throw new Error(\n \"Semantic chunking failed: embedding function threw and fallbackToRecursive is disabled\",\n );\n }\n\n if (embeddings.length !== sentences.length) {\n if (cfg.fallbackToRecursive) {\n return buildRecursiveFallback(content, cfg);\n }\n throw new Error(\n `Semantic chunking failed: expected ${sentences.length} embeddings but received ${embeddings.length}`,\n );\n }\n\n const dimensionMismatch = findEmbeddingDimensionMismatch(embeddings);\n if (dimensionMismatch) {\n if (cfg.fallbackToRecursive) {\n return buildRecursiveFallback(content, cfg);\n }\n throw new Error(\n `Semantic chunking failed: embedding vectors have mismatched dimensions ` +\n `(${dimensionMismatch.expected} vs ${dimensionMismatch.actual} at index ${dimensionMismatch.index})`,\n );\n }\n\n // --- Compute pairwise cosine similarity ---\n const similarities: number[] = [];\n for (let i = 0; i < sentences.length - 1; i++) {\n similarities.push(cosineSimilarity(embeddings[i], embeddings[i + 1]));\n }\n\n // If only one pair (2 sentences), nothing to smooth or split meaningfully.\n // However, if the combined content exceeds maxTokens, apply recursive splitting.\n if (similarities.length <= 1) {\n if (totalTokens > cfg.maxTokens) {\n return buildRecursiveFallback(content, cfg);\n }\n return {\n chunked: false,\n chunks: [\n {\n content: content.trim(),\n index: 0,\n tokenCount: totalTokens,\n boundaryScore: similarities.length === 1 ? similarities[0] : 1,\n },\n ],\n boundaries: [],\n method: \"semantic\",\n };\n }\n\n // --- Smooth the similarity series ---\n const smoothed = movingAverage(similarities, cfg.smoothingWindowSize);\n\n // --- Detect boundaries: local minima below (mean - k * stddev) ---\n const m = mean(smoothed);\n const s = stddev(smoothed);\n const threshold = m - cfg.boundaryThresholdStdDevs * s;\n const rawBoundaries = findLocalMinima(smoothed, threshold);\n\n // --- Build segments, merge short, split long ---\n let segments = buildSegments(sentences, rawBoundaries);\n segments = mergeShortSegments(segments, cfg.minTokens);\n\n // --- Convert segments to chunks, splitting oversized ones ---\n const chunks: SemanticChunk[] = [];\n const finalBoundaries: number[] = [];\n let sentenceOffset = 0;\n\n for (let segIdx = 0; segIdx < segments.length; segIdx++) {\n const segment = segments[segIdx];\n const segText = segment.join(\" \");\n const segTokens = estimateTokens(segText);\n\n if (segTokens > cfg.maxTokens) {\n // Recursive split for oversized segment\n const subChunks = splitLongSegment(segment, cfg.maxTokens, cfg.targetTokens);\n for (const sc of subChunks) {\n chunks.push({\n ...sc,\n index: chunks.length,\n });\n }\n } else {\n // Compute boundary score: the similarity at the trailing edge\n const trailingSentenceIdx = sentenceOffset + segment.length - 1;\n let bScore = 1;\n if (\n trailingSentenceIdx < similarities.length &&\n segIdx < segments.length - 1\n ) {\n bScore = smoothed[trailingSentenceIdx] ?? similarities[trailingSentenceIdx] ?? 1;\n }\n\n chunks.push({\n content: segText,\n index: chunks.length,\n tokenCount: segTokens,\n boundaryScore: bScore,\n });\n }\n\n // Record boundaries (all but the last segment produce a boundary)\n if (segIdx < segments.length - 1) {\n finalBoundaries.push(sentenceOffset + segment.length - 1);\n }\n sentenceOffset += segment.length;\n }\n\n return {\n chunked: chunks.length > 1,\n chunks,\n boundaries: finalBoundaries,\n method: \"semantic\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// Recursive fallback helper\n// ---------------------------------------------------------------------------\n\nfunction buildRecursiveFallback(\n content: string,\n cfg: SemanticChunkingConfig,\n): SemanticChunkResult {\n // Cap targetTokens to maxTokens so the recursive fallback path honours the\n // same constraint as splitLongSegment (PR #439 post-merge cursor[bot] finding).\n const cappedTarget = Math.min(cfg.targetTokens, cfg.maxTokens);\n const result: ChunkResult = chunkContent(content, {\n targetTokens: cappedTarget,\n minTokens: Math.min(cfg.minTokens, cappedTarget),\n overlapSentences: 0,\n });\n\n return {\n chunked: result.chunked,\n chunks: result.chunks.map((c) => ({\n ...c,\n boundaryScore: 0,\n })),\n boundaries: [],\n method: \"recursive-fallback\",\n };\n}\n"],"mappings":";;;;;AA+BO,IAAM,mCAA2D;AAAA,EACtE,cAAc;AAAA,EACd,WAAW;AAAA,EACX,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,0BAA0B;AAAA,EAC1B,oBAAoB;AAAA,EACpB,qBAAqB;AACvB;AA0CO,SAAS,iBAAiB,GAAa,GAAqB;AACjE,MAAI,EAAE,WAAW,EAAE,QAAQ;AACzB,UAAM,IAAI;AAAA,MACR,6CAA6C,EAAE,MAAM,OAAO,EAAE,MAAM;AAAA,IACtE;AAAA,EACF;AACA,MAAI,EAAE,WAAW,EAAG,QAAO;AAE3B,MAAI,MAAM;AACV,MAAI,OAAO;AACX,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,WAAO,EAAE,CAAC,IAAI,EAAE,CAAC;AACjB,YAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;AAClB,YAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;AAAA,EACpB;AAEA,QAAM,QAAQ,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;AAC9C,MAAI,UAAU,EAAG,QAAO;AACxB,SAAO,MAAM;AACf;AAKO,SAAS,KAAK,QAA0B;AAC7C,MAAI,OAAO,WAAW,EAAG,QAAO;AAChC,MAAI,MAAM;AACV,aAAW,KAAK,OAAQ,QAAO;AAC/B,SAAO,MAAM,OAAO;AACtB;AAKO,SAAS,OAAO,QAA0B;AAC/C,MAAI,OAAO,WAAW,EAAG,QAAO;AAChC,QAAM,IA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,cAAc;AAAA,IACd,WAAW,KAAK,IAAI,IAAI,WAAW,YAAY;AAAA,IAC/C,kBAAkB;AAAA,EACpB,CAAC;AAED,SAAO;AAAA,IACL,SAAS,OAAO;AAAA,IAChB,QAAQ,OAAO,OAAO,IAAI,CAAC,OAAO;AAAA,MAChC,GAAG;AAAA,MACH,eAAe;AAAA,IACjB,EAAE;AAAA,IACF,YAAY,CAAC;AAAA,IACb,QAAQ;AAAA,EACV;AACF;","names":[]}
|
package/dist/chunk-UQ7RN5HK.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// src/chunking.ts
|
|
2
|
-
var DEFAULT_CHUNKING_CONFIG = {
|
|
3
|
-
targetTokens: 200,
|
|
4
|
-
minTokens: 150,
|
|
5
|
-
overlapSentences: 2
|
|
6
|
-
};
|
|
7
|
-
function estimateTokens(text) {
|
|
8
|
-
return Math.ceil(text.length / 4);
|
|
9
|
-
}
|
|
10
|
-
function splitSentences(text) {
|
|
11
|
-
const sentences = [];
|
|
12
|
-
let start = 0;
|
|
13
|
-
for (let i = 0; i < text.length; i++) {
|
|
14
|
-
const ch = text[i];
|
|
15
|
-
if (ch !== "." && ch !== "!" && ch !== "?") continue;
|
|
16
|
-
let end = i;
|
|
17
|
-
while (end + 1 < text.length) {
|
|
18
|
-
const n = text[end + 1];
|
|
19
|
-
if (n !== "." && n !== "!" && n !== "?") break;
|
|
20
|
-
end++;
|
|
21
|
-
}
|
|
22
|
-
const after = text[end + 1];
|
|
23
|
-
if (after === void 0 || /\s/.test(after)) {
|
|
24
|
-
const sentence = text.slice(start, end + 1).trim();
|
|
25
|
-
if (sentence.length > 0) sentences.push(sentence);
|
|
26
|
-
start = end + 1;
|
|
27
|
-
}
|
|
28
|
-
i = end;
|
|
29
|
-
}
|
|
30
|
-
if (start < text.length) {
|
|
31
|
-
const remaining = text.slice(start).trim();
|
|
32
|
-
if (remaining.length > 0) sentences.push(remaining);
|
|
33
|
-
}
|
|
34
|
-
return sentences;
|
|
35
|
-
}
|
|
36
|
-
function chunkContent(content, config = DEFAULT_CHUNKING_CONFIG) {
|
|
37
|
-
const totalTokens = estimateTokens(content);
|
|
38
|
-
if (totalTokens < config.minTokens) {
|
|
39
|
-
return {
|
|
40
|
-
chunked: false,
|
|
41
|
-
chunks: [{
|
|
42
|
-
content,
|
|
43
|
-
index: 0,
|
|
44
|
-
tokenCount: totalTokens
|
|
45
|
-
}]
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const sentences = splitSentences(content);
|
|
49
|
-
if (sentences.length <= 1) {
|
|
50
|
-
return {
|
|
51
|
-
chunked: false,
|
|
52
|
-
chunks: [{
|
|
53
|
-
content,
|
|
54
|
-
index: 0,
|
|
55
|
-
tokenCount: totalTokens
|
|
56
|
-
}]
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const chunks = [];
|
|
60
|
-
let currentChunkSentences = [];
|
|
61
|
-
let currentTokens = 0;
|
|
62
|
-
let chunkIndex = 0;
|
|
63
|
-
for (let i = 0; i < sentences.length; i++) {
|
|
64
|
-
const sentence = sentences[i];
|
|
65
|
-
const sentenceTokens = estimateTokens(sentence);
|
|
66
|
-
currentChunkSentences.push(sentence);
|
|
67
|
-
currentTokens += sentenceTokens;
|
|
68
|
-
const atTarget = currentTokens >= config.targetTokens;
|
|
69
|
-
const isLastSentence = i === sentences.length - 1;
|
|
70
|
-
if (atTarget || isLastSentence) {
|
|
71
|
-
const chunkContent2 = currentChunkSentences.join(" ");
|
|
72
|
-
chunks.push({
|
|
73
|
-
content: chunkContent2,
|
|
74
|
-
index: chunkIndex,
|
|
75
|
-
tokenCount: estimateTokens(chunkContent2)
|
|
76
|
-
});
|
|
77
|
-
chunkIndex++;
|
|
78
|
-
if (!isLastSentence) {
|
|
79
|
-
const overlapCount = Math.min(config.overlapSentences, currentChunkSentences.length);
|
|
80
|
-
if (overlapCount <= 0) {
|
|
81
|
-
currentChunkSentences = [];
|
|
82
|
-
currentTokens = 0;
|
|
83
|
-
} else {
|
|
84
|
-
currentChunkSentences = currentChunkSentences.slice(-overlapCount);
|
|
85
|
-
currentTokens = currentChunkSentences.reduce((sum, s) => sum + estimateTokens(s), 0);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
chunked: chunks.length > 1,
|
|
92
|
-
chunks
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function reassembleChunks(chunks) {
|
|
96
|
-
if (chunks.length === 0) return "";
|
|
97
|
-
if (chunks.length === 1) return chunks[0];
|
|
98
|
-
const result = [chunks[0]];
|
|
99
|
-
for (let i = 1; i < chunks.length; i++) {
|
|
100
|
-
const prevChunk = chunks[i - 1];
|
|
101
|
-
const currChunk = chunks[i];
|
|
102
|
-
const prevSentences = splitSentences(prevChunk);
|
|
103
|
-
const currSentences = splitSentences(currChunk);
|
|
104
|
-
let overlapCount = 0;
|
|
105
|
-
for (let j = 0; j < Math.min(prevSentences.length, currSentences.length); j++) {
|
|
106
|
-
const prevEnd = prevSentences.slice(-(j + 1));
|
|
107
|
-
const currStart = currSentences.slice(0, j + 1);
|
|
108
|
-
if (prevEnd.join(" ") === currStart.join(" ")) {
|
|
109
|
-
overlapCount = j + 1;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (overlapCount > 0 && overlapCount < currSentences.length) {
|
|
113
|
-
result.push(currSentences.slice(overlapCount).join(" "));
|
|
114
|
-
} else if (overlapCount === 0) {
|
|
115
|
-
result.push(currChunk);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return result.join(" ");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export {
|
|
122
|
-
DEFAULT_CHUNKING_CONFIG,
|
|
123
|
-
chunkContent,
|
|
124
|
-
reassembleChunks
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=chunk-UQ7RN5HK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chunking.ts"],"sourcesContent":["/**\n * Automatic Chunking with Overlap (Phase 2A)\n *\n * Sentence-boundary chunking for long memories.\n * Preserves coherent thoughts by never splitting mid-sentence.\n */\n\nexport interface ChunkingConfig {\n /** Target tokens per chunk (default 200) */\n targetTokens: number;\n /** Minimum tokens to trigger chunking (default 150) */\n minTokens: number;\n /** Number of sentences to overlap between chunks (default 2) */\n overlapSentences: number;\n}\n\nexport interface Chunk {\n /** Chunk content */\n content: string;\n /** 0-based index */\n index: number;\n /** Approximate token count */\n tokenCount: number;\n}\n\nexport interface ChunkResult {\n /** Whether content was chunked */\n chunked: boolean;\n /** Array of chunks (length 1 if not chunked) */\n chunks: Chunk[];\n}\n\n/** Default chunking configuration */\nexport const DEFAULT_CHUNKING_CONFIG: ChunkingConfig = {\n targetTokens: 200,\n minTokens: 150,\n overlapSentences: 2,\n};\n\n/**\n * Estimate token count for text.\n * Rough approximation: ~4 characters per token for English.\n */\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Split text into sentences.\n * Handles common abbreviations and edge cases.\n */\nfunction splitSentences(text: string): string[] {\n // Split on sentence-ending punctuation (. ! ?) that is followed by whitespace\n // or end of string; the punctuation stays with the sentence.\n //\n // Implemented as a single linear scan rather than a regex. Every regex form of\n // this split is either polynomial (CodeQL js/polynomial-redos) or — once\n // bounded/anchored to satisfy CodeQL — mishandles long runs or non-boundary\n // punctuation (a global match silently drops a skipped prefix; a sticky match\n // stops at the first interior `.` that is not a real boundary, e.g. \"v1.2.3\"\n // or \"example.com\", emitting the whole document as one chunk). A character\n // scan is O(n), allocation-free, drops nothing, and treats interior\n // punctuation correctly. Normal prose splits identically to the previous\n // /[^.!?]*[.!?]+(?:\\s+|$)/g form.\n const sentences: string[] = [];\n let start = 0;\n for (let i = 0; i < text.length; i++) {\n const ch = text[i];\n if (ch !== \".\" && ch !== \"!\" && ch !== \"?\") continue;\n // Consume a run of terminators (e.g. \"?!\", \"...\").\n let end = i;\n while (end + 1 < text.length) {\n const n = text[end + 1];\n if (n !== \".\" && n !== \"!\" && n !== \"?\") break;\n end++;\n }\n const after = text[end + 1];\n // A real boundary only if the terminator run ends the string or is followed\n // by whitespace. Interior punctuation (no following whitespace) is left in\n // place and the scan continues.\n if (after === undefined || /\\s/.test(after)) {\n const sentence = text.slice(start, end + 1).trim();\n if (sentence.length > 0) sentences.push(sentence);\n start = end + 1;\n }\n i = end;\n }\n // Trailing text without a closing terminator.\n if (start < text.length) {\n const remaining = text.slice(start).trim();\n if (remaining.length > 0) sentences.push(remaining);\n }\n return sentences;\n}\n\n/**\n * Chunk content into overlapping segments at sentence boundaries.\n *\n * @param content - The text content to chunk\n * @param config - Chunking configuration\n * @returns ChunkResult with chunks array\n */\nexport function chunkContent(\n content: string,\n config: ChunkingConfig = DEFAULT_CHUNKING_CONFIG,\n): ChunkResult {\n const totalTokens = estimateTokens(content);\n\n // Don't chunk if below minimum threshold\n if (totalTokens < config.minTokens) {\n return {\n chunked: false,\n chunks: [{\n content,\n index: 0,\n tokenCount: totalTokens,\n }],\n };\n }\n\n const sentences = splitSentences(content);\n\n // If we couldn't split into multiple sentences, don't chunk\n if (sentences.length <= 1) {\n return {\n chunked: false,\n chunks: [{\n content,\n index: 0,\n tokenCount: totalTokens,\n }],\n };\n }\n\n const chunks: Chunk[] = [];\n let currentChunkSentences: string[] = [];\n let currentTokens = 0;\n let chunkIndex = 0;\n\n for (let i = 0; i < sentences.length; i++) {\n const sentence = sentences[i];\n const sentenceTokens = estimateTokens(sentence);\n\n // Add sentence to current chunk\n currentChunkSentences.push(sentence);\n currentTokens += sentenceTokens;\n\n // Check if we've reached target size (with some flexibility)\n // Allow going over by up to 50% to avoid tiny final chunks\n const atTarget = currentTokens >= config.targetTokens;\n const isLastSentence = i === sentences.length - 1;\n\n if (atTarget || isLastSentence) {\n // Create chunk from accumulated sentences\n const chunkContent = currentChunkSentences.join(\" \");\n chunks.push({\n content: chunkContent,\n index: chunkIndex,\n tokenCount: estimateTokens(chunkContent),\n });\n chunkIndex++;\n\n // Start new chunk with overlap (if not at end)\n if (!isLastSentence) {\n // Keep last N sentences for overlap.\n // Guard: slice(-0) === slice(0), which returns the ENTIRE array\n // (CLAUDE.md gotcha #27). When overlapSentences is 0, clear fully.\n const overlapCount = Math.min(config.overlapSentences, currentChunkSentences.length);\n if (overlapCount <= 0) {\n currentChunkSentences = [];\n currentTokens = 0;\n } else {\n currentChunkSentences = currentChunkSentences.slice(-overlapCount);\n currentTokens = currentChunkSentences.reduce((sum, s) => sum + estimateTokens(s), 0);\n }\n }\n }\n }\n\n // Only consider it \"chunked\" if we got multiple chunks\n return {\n chunked: chunks.length > 1,\n chunks,\n };\n}\n\n/**\n * Get parent content by reassembling chunks.\n * Useful for displaying full context when a chunk is retrieved.\n *\n * @param chunks - Array of chunk contents in order\n * @returns Reassembled parent content (with overlap removed)\n */\nexport function reassembleChunks(chunks: string[]): string {\n if (chunks.length === 0) return \"\";\n if (chunks.length === 1) return chunks[0];\n\n // For overlapping chunks, we need to deduplicate\n // Simple approach: use full first chunk, then non-overlapping parts of subsequent chunks\n // This is imperfect but handles most cases\n const result: string[] = [chunks[0]];\n\n for (let i = 1; i < chunks.length; i++) {\n const prevChunk = chunks[i - 1];\n const currChunk = chunks[i];\n\n // Find overlap by looking for common suffix/prefix\n // Try to find where the previous chunk ends in the current chunk\n const prevSentences = splitSentences(prevChunk);\n const currSentences = splitSentences(currChunk);\n\n // Find how many sentences from prev are at the start of curr\n let overlapCount = 0;\n for (let j = 0; j < Math.min(prevSentences.length, currSentences.length); j++) {\n // Check if last N sentences of prev match first N sentences of curr\n const prevEnd = prevSentences.slice(-(j + 1));\n const currStart = currSentences.slice(0, j + 1);\n\n if (prevEnd.join(\" \") === currStart.join(\" \")) {\n overlapCount = j + 1;\n }\n }\n\n // Add non-overlapping portion\n if (overlapCount > 0 && overlapCount < currSentences.length) {\n result.push(currSentences.slice(overlapCount).join(\" \"));\n } else if (overlapCount === 0) {\n // No detected overlap, add full chunk\n result.push(currChunk);\n }\n // If overlapCount === currSentences.length, skip (fully contained)\n }\n\n return result.join(\" \");\n}\n"],"mappings":";AAiCO,IAAM,0BAA0C;AAAA,EACrD,cAAc;AAAA,EACd,WAAW;AAAA,EACX,kBAAkB;AACpB;AAMA,SAAS,eAAe,MAAsB;AAC5C,SAAO,KAAK,KAAK,KAAK,SAAS,CAAC;AAClC;AAMA,SAAS,eAAe,MAAwB;AAa9C,QAAM,YAAsB,CAAC;AAC7B,MAAI,QAAQ;AACZ,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,KAAK,KAAK,CAAC;AACjB,QAAI,OAAO,OAAO,OAAO,OAAO,OAAO,IAAK;AAE5C,QAAI,MAAM;AACV,WAAO,MAAM,IAAI,KAAK,QAAQ;AAC5B,YAAM,IAAI,KAAK,MAAM,CAAC;AACtB,UAAI,MAAM,OAAO,MAAM,OAAO,MAAM,IAAK;AACzC;AAAA,IACF;AACA,UAAM,QAAQ,KAAK,MAAM,CAAC;AAI1B,QAAI,UAAU,UAAa,KAAK,KAAK,KAAK,GAAG;AAC3C,YAAM,WAAW,KAAK,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK;AACjD,UAAI,SAAS,SAAS,EAAG,WAAU,KAAK,QAAQ;AAChD,cAAQ,MAAM;AAAA,IAChB;AACA,QAAI;AAAA,EACN;AAEA,MAAI,QAAQ,KAAK,QAAQ;AACvB,UAAM,YAAY,KAAK,MAAM,KAAK,EAAE,KAAK;AACzC,QAAI,UAAU,SAAS,EAAG,WAAU,KAAK,SAAS;AAAA,EACpD;AACA,SAAO;AACT;AASO,SAAS,aACd,SACA,SAAyB,yBACZ;AACb,QAAM,cAAc,eAAe,OAAO;AAG1C,MAAI,cAAc,OAAO,WAAW;AAClC,WAAO;AAAA,MACL,SAAS;AAAA,MACT,QAAQ,CAAC;AAAA,QACP;AAAA,QACA,OAAO;AAAA,QACP,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EAC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