{"record":{"id":"118adf5bbb8cd570","repo":"mastra-ai/mastra","slug":"sentence-chunking-requires-maxsize-to-be-specified","errorCode":null,"errorMessage":"Sentence chunking requires maxSize to be specified","messagePattern":"Sentence chunking requires maxSize to be specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/document/document.ts","lineNumber":314,"sourceCode":"    this.chunks = textSplit;\n  }\n\n  async chunkMarkdown(options?: MarkdownChunkOptions): Promise<void> {\n    if (options?.headers) {\n      const rt = new MarkdownHeaderTransformer(options.headers, options?.returnEachLine, options?.stripHeaders);\n      const textSplit = rt.transformDocuments(this.chunks);\n      this.chunks = textSplit;\n      return;\n    }\n\n    const rt = new MarkdownTransformer(options);\n    const textSplit = rt.transformDocuments(this.chunks);\n    this.chunks = textSplit;\n  }\n\n  async chunkSentence(options?: SentenceChunkOptions): Promise<void> {\n    if (!options?.maxSize) {\n      throw new Error('Sentence chunking requires maxSize to be specified');\n    }\n\n    const rt = new SentenceTransformer({\n      minSize: options?.minSize,\n      maxSize: options?.maxSize,\n      targetSize: options?.targetSize,\n      overlap: options?.overlap,\n      sentenceEnders: options?.sentenceEnders,\n      fallbackToWords: options?.fallbackToWords,\n      fallbackToCharacters: options?.fallbackToCharacters,\n      separatorPosition: options?.separatorPosition,\n      lengthFunction: options?.lengthFunction,\n      addStartIndex: options?.addStartIndex,\n      stripWhitespace: options?.stripWhitespace,\n    });\n\n    const textSplit = rt.transformDocuments(this.chunks);\n    this.chunks = textSplit;","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/document/document.ts#L296-L332","documentation":"chunkSentence uses SentenceTransformer, which requires maxSize to define the upper bound on sentence-chunk size (alongside optional minSize and targetSize). Without it the transformer cannot bound chunk sizes, so the library throws this validation error up front.","triggerScenarios":"Calling doc.chunkSentence() with no options, or with options lacking maxSize (e.g. chunkSentence({ targetSize: 200 })).","commonSituations":"Assuming sentence chunking works with defaults like other strategies, passing only minSize/targetSize, or constructing options dynamically where maxSize is optional in your config and undefined at runtime.","solutions":["Pass maxSize: doc.chunkSentence({ maxSize: 512 }).","Add sensible defaults when building options, e.g. { minSize: 50, maxSize: maxSize ?? 512, targetSize: targetSize ?? 256 }.","Validate the options object before calling the method.","Check the SentenceChunkOptions type for required vs optional fields."],"exampleFix":"// before\nawait doc.chunkSentence({ targetSize: 200 }); // maxSize missing\n\n// after\nawait doc.chunkSentence({ minSize: 50, maxSize: 512, targetSize: 200 });","handlingStrategy":"validation","validationCode":"if (typeof options?.maxSize !== 'number' || options.maxSize <= 0) {\n  throw new Error('chunkSentence requires a positive maxSize');\n}","typeGuard":"function hasSentenceMaxSize(o: unknown): o is { maxSize: number } {\n  return typeof (o as any)?.maxSize === 'number' && (o as any).maxSize > 0;\n}","tryCatchPattern":"try {\n  await doc.chunkSentence(options);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('maxSize')) {\n    await doc.chunkSentence({ ...options, maxSize: 512 });\n  } else throw e;\n}","preventionTips":["Always include maxSize (e.g. 512) in sentence chunk options.","Centralize default chunk options (minSize/maxSize/targetSize) in one config module.","Validate options objects once at pipeline start, not per call."],"tags":["rag","chunking","validation","configuration"],"backgroundTag":"missing-required-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}