(content: string)
| 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 | } |
nothing calls this directly
no test coverage detected