# chunker.BaseChunker


Abstract base class for chunkers.


Usage

``` python
chunker.BaseChunker()
```


Chunking is the step that splits a document into smaller, retrievable passages. Good chunks are large enough to stand on their own but small enough that a search can return just the relevant part of a document rather than the whole thing. A chunker turns a [Document](document.Document.md#raghilda.document.Document) into a [ChunkedDocument](document.ChunkedDocument.md#raghilda.document.ChunkedDocument) whose `chunks` are ready to embed, index, and retrieve.

[BaseChunker](chunker.BaseChunker.md#raghilda.chunker.BaseChunker) only defines the interface; it is not used directly. A concrete chunker implements a strategy by overriding [chunk()](types.ChunkerLike.md#raghilda.types.ChunkerLike.chunk) and [chunk_text()](types.ChunkerLike.md#raghilda.types.ChunkerLike.chunk_text). raghilda ships [`MarkdownChunker`](chunker.MarkdownChunker.md), which splits Markdown at semantic boundaries (headings, paragraphs, sentences). Any object implementing this interface (including third-party chunkers such as [chonkie](https://github.com/chonkie-inc/chonkie)'s) can be used wherever raghilda expects a chunker.


## Methods

| Name | Description |
|----|----|
| [chunk()](#chunk) | Split a document into a [ChunkedDocument](document.ChunkedDocument.md#raghilda.document.ChunkedDocument). |
| [chunk_text()](#chunk_text) | Split raw text into a sequence of [Chunk](chunk.Chunk.md#raghilda.chunk.Chunk) objects. |

------------------------------------------------------------------------


### chunk()


Split a document into a [ChunkedDocument](document.ChunkedDocument.md#raghilda.document.ChunkedDocument).


Usage

``` python
chunk(document)
```


#### Parameters


`document: Document`  
The document to chunk.


#### Returns


`ChunkedDocument`  
The same document with its `chunks` attached.


------------------------------------------------------------------------


### chunk_text()


Split raw text into a sequence of [Chunk](chunk.Chunk.md#raghilda.chunk.Chunk) objects.


Usage

``` python
chunk_text(text)
```


Use this when you have a bare string rather than a [Document](document.Document.md#raghilda.document.Document). Most callers use [chunk()](types.ChunkerLike.md#raghilda.types.ChunkerLike.chunk) instead, which preserves document metadata.


#### Parameters


`text: str`  
The text to chunk.


#### Returns


`Sequence[Chunk]`  
The resulting chunks, each with positional information.
