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

Function applyStrategy

apps/sim/lib/knowledge/documents/document-processor.ts:121–168  ·  view source on GitHub ↗
(
  strategy: ChunkingStrategy,
  content: string,
  chunkSize: number,
  chunkOverlap: number,
  minCharactersPerChunk: number,
  strategyOptions?: StrategyOptions
)

Source from the content-addressed store, hash-verified

119}
120
121async function applyStrategy(
122 strategy: ChunkingStrategy,
123 content: string,
124 chunkSize: number,
125 chunkOverlap: number,
126 minCharactersPerChunk: number,
127 strategyOptions?: StrategyOptions
128): Promise<Chunk[]> {
129 const baseOptions = { chunkSize, chunkOverlap, minCharactersPerChunk }
130
131 switch (strategy) {
132 case 'token': {
133 const chunker = new TokenChunker(baseOptions)
134 return chunker.chunk(content)
135 }
136 case 'sentence': {
137 const chunker = new SentenceChunker(baseOptions)
138 return chunker.chunk(content)
139 }
140 case 'recursive': {
141 const chunker = new RecursiveChunker({
142 ...baseOptions,
143 separators: strategyOptions?.separators,
144 recipe: strategyOptions?.recipe,
145 })
146 return chunker.chunk(content)
147 }
148 case 'regex': {
149 if (!strategyOptions?.pattern) {
150 logger.warn(
151 'Regex strategy requested but no pattern provided, falling back to text chunker'
152 )
153 const chunker = new TextChunker(baseOptions)
154 return chunker.chunk(content)
155 }
156 const chunker = new RegexChunker({
157 ...baseOptions,
158 pattern: strategyOptions.pattern,
159 strictBoundaries: strategyOptions.strictBoundaries,
160 })
161 return chunker.chunk(content)
162 }
163 default: {
164 const chunker = new TextChunker(baseOptions)
165 return chunker.chunk(content)
166 }
167 }
168}
169
170export async function processDocument(
171 fileUrl: string,

Callers 1

processDocumentFunction · 0.85

Calls 2

chunkMethod · 0.95
warnMethod · 0.65

Tested by

no test coverage detected