MCPcopy Index your code
hub / github.com/simstudioai/sim / chunk

Method chunk

apps/sim/lib/chunkers/token-chunker.ts:26–53  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

24 }
25
26 async chunk(content: string): Promise<Chunk[]> {
27 if (!content?.trim()) {
28 return []
29 }
30
31 const cleaned = cleanText(content)
32
33 if (estimateTokens(cleaned) <= this.chunkSize) {
34 logger.info('Content fits in single chunk')
35 return buildChunks([cleaned], 0)
36 }
37
38 const chunkSizeChars = tokensToChars(this.chunkSize)
39 const overlapChars = tokensToChars(this.chunkOverlap)
40 const stepChars = this.chunkOverlap > 0 ? chunkSizeChars - overlapChars : undefined
41
42 const rawChunks = splitAtWordBoundaries(cleaned, chunkSizeChars, stepChars)
43
44 const filtered =
45 rawChunks.length > 1
46 ? rawChunks.filter((c) => c.length >= this.minCharactersPerChunk)
47 : rawChunks
48
49 const chunks = filtered.length > 0 ? filtered : rawChunks
50
51 logger.info(`Chunked into ${chunks.length} token-based chunks`)
52 return buildChunks(chunks, this.chunkOverlap)
53 }
54}

Callers

nothing calls this directly

Calls 6

cleanTextFunction · 0.90
estimateTokensFunction · 0.90
buildChunksFunction · 0.90
tokensToCharsFunction · 0.90
splitAtWordBoundariesFunction · 0.90
infoMethod · 0.80

Tested by

no test coverage detected