MCPcopy Create free account
hub / github.com/idosal/git-mcp / chunkDocumentation

Function chunkDocumentation

src/api/utils/vectorStore.ts:510–551  ·  view source on GitHub ↗
(text: string, fileName?: string)

Source from the content-addressed store, hash-verified

508 * @returns Array of text chunks
509 */
510export function chunkDocumentation(text: string, fileName?: string): string[] {
511 // First check if this is a structured document with list items (like llms.txt)
512 if (fileName?.toLowerCase().includes("llms.txt")) {
513 try {
514 // For llms.txt files, each list item should be treated as its own chunk
515 // with section header context
516 const structuredChunks = chunkStructuredDocs(text);
517 if (structuredChunks.length > 0) {
518 return structuredChunks;
519 }
520 } catch (error) {
521 console.warn(
522 "Structured documentation chunking failed for llms.txt, trying README chunker",
523 );
524 }
525 }
526
527 // Then try README-specific chunking
528 try {
529 const readmeChunks = chunkReadme(text, fileName);
530 if (readmeChunks.length > 0) {
531 return readmeChunks;
532 }
533 } catch (error) {
534 console.warn("README chunking failed, trying next chunker");
535 }
536
537 // Then try structured documentation chunking as fallback
538 try {
539 const structuredChunks = chunkStructuredDocs(text);
540 if (structuredChunks.length > 0) {
541 return structuredChunks;
542 }
543 } catch (error) {
544 console.warn(
545 "Structured documentation chunking failed, falling back to default chunker",
546 );
547 }
548
549 // Fall back to the regular chunking algorithm
550 return chunkText(text);
551}
552
553/**
554 * Process documentation text into chunks for vector storage with improved boundaries

Callers 1

Calls 4

chunkStructuredDocsFunction · 0.85
chunkReadmeFunction · 0.85
chunkTextFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected