(text: string, fileName?: string)
| 508 | * @returns Array of text chunks |
| 509 | */ |
| 510 | export 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 |
no test coverage detected