ragChunk( )
Chunks documents into smaller pieces for embedding.
function ragChunk(params): Promise<RagDoc[]>;
Part of the segregated flow: ragChunk() → embed() → ragSaveEmbeddings()
| Name | Type | Required? | Description |
|---|
| params | object | ✓ | The chunking parameters |
| params.documents | string | string[] | ✓ | Documents to chunk |
| params.chunkOpts | ChunkOptions | ✗ | Chunking options |
| Field | Type | Required? | Description |
|---|
| chunkSize | number | ✗ | Maximum chunk size |
| chunkOverlap | number | ✗ | Overlap between chunks |
| chunkStrategy | "character" | "paragraph" | ✗ | Chunking strategy |
| splitStrategy | "character" | "word" | "token" | "sentence" | "line" | ✗ | Text splitting strategy |
Promise<RagDoc[]> — Array of chunk results.
| Field | Type | Description |
|---|
| id | string | Chunk identifier |
| content | string | Chunk text content |
| Error | When |
|---|
RAG_CHUNK_FAILED | The chunking operation fails |
const chunks = await ragChunk({
documents: ["Long document text here..."],
chunkOpts: {
chunkSize: 256,
chunkOverlap: 50,
chunkStrategy: "paragraph",
},
});