chunk.Chunk

A segment of text extracted from a document.

Usage

Source

chunk.Chunk()

Chunks are the fundamental unit for retrieval in RAG applications. Each chunk contains the text content along with positional information that allows mapping back to the original document.

Parameter Attributes

text: str
start_index: int
end_index: int
char_count: int
context: Optional[str] = None
origin: Optional[str] = None
attributes: Optional[dict[str, Any]] = None

Attributes

text: str

The actual text content of the chunk.

start_index: int

Character position where this chunk begins in the source document.

end_index: int

Character position where this chunk ends in the source document.

char_count: int

Number of characters in this chunk.

context: Optional[str]

Optional heading context showing the document hierarchy at this chunk’s position (e.g., the Markdown headings that apply).

origin: Optional[str]

Origin of the parent document this chunk belongs to.

attributes: Optional[dict[str, Any]]
Optional user-defined attributes associated with the chunk. These attributes can be used for retrieval filtering/scoping and downstream prompt/context construction.

Methods

Name Description
from_any() Convert any chunk-like or IntoChunk object to a raghilda Chunk.

from_any()

Convert any chunk-like or IntoChunk object to a raghilda Chunk.

Usage

Source

from_any(chunk)
Parameters
chunk: Union[ChunkLike, IntoChunk]
An object that implements the ChunkLike protocol or has a to_chunk() method.
Returns
Chunk
A raghilda Chunk instance.