Rag.Chunker behaviour (rag v0.3.4)

View Source

Behaviour for text chunking strategies.

Chunkers split text into smaller pieces suitable for embedding and retrieval. Each chunk includes byte positions for source reconstruction.

Summary

Callbacks

Split text into chunks.

Returns default options for this chunker.

Functions

Dispatch to the chunker implementation.

Chunk an ingestion map, adding chunks to the result.

Types

t()

@type t() :: struct()

Callbacks

chunk(chunker, text, opts)

@callback chunk(chunker :: t(), text :: String.t(), opts :: keyword()) :: [
  Rag.Chunker.Chunk.t()
]

Split text into chunks.

Returns a list of Rag.Chunker.Chunk structs.

default_opts()

(optional)
@callback default_opts() :: keyword()

Returns default options for this chunker.

Functions

chunk(chunker, text, opts \\ [])

@spec chunk(t(), String.t(), keyword()) :: [Rag.Chunker.Chunk.t()]

Dispatch to the chunker implementation.

chunk_ingestion(chunker, ingestion, opts \\ [])

@spec chunk_ingestion(t(), map(), keyword()) :: map()

Chunk an ingestion map, adding chunks to the result.

Expects input map with a :document key containing text. Returns a map with :chunks added.