Kreuzberg.ChunkMetadata (kreuzberg v4.9.5)

Copy Markdown View Source

Metadata for a text chunk, tracking byte positions, indices, and page range.

Fields

  • :byte_start - Start byte offset in the original content
  • :byte_end - End byte offset in the original content
  • :token_count - Optional number of tokens in the chunk
  • :chunk_index - Zero-indexed position of this chunk
  • :total_chunks - Total number of chunks
  • :first_page - Optional first page number covered by this chunk
  • :last_page - Optional last page number covered by this chunk
  • :heading_context - Optional heading hierarchy for this chunk's section

Summary

Functions

Creates a ChunkMetadata struct from a map.

Converts a ChunkMetadata struct to a map.

Types

heading_context()

@type heading_context() :: %{headings: [heading_level()]}

heading_level()

@type heading_level() :: %{level: non_neg_integer(), text: String.t()}

t()

@type t() :: %Kreuzberg.ChunkMetadata{
  byte_end: non_neg_integer(),
  byte_start: non_neg_integer(),
  chunk_index: non_neg_integer(),
  first_page: non_neg_integer() | nil,
  heading_context: heading_context() | nil,
  last_page: non_neg_integer() | nil,
  token_count: non_neg_integer() | nil,
  total_chunks: non_neg_integer()
}

Functions

from_map(data)

@spec from_map(map()) :: t()

Creates a ChunkMetadata struct from a map.

Examples

iex> Kreuzberg.ChunkMetadata.from_map(%{"byte_start" => 0, "byte_end" => 100, "chunk_index" => 0, "total_chunks" => 5})
%Kreuzberg.ChunkMetadata{byte_start: 0, byte_end: 100, chunk_index: 0, total_chunks: 5}

to_map(map)

@spec to_map(t()) :: map()

Converts a ChunkMetadata struct to a map.