Kreuzberg.DocumentTextAnnotation (kreuzberg v4.4.2)

Copy Markdown View Source

Inline text annotation with byte-range formatting and links.

Annotations reference byte offsets into a node's text content, enabling precise identification of formatted regions.

Fields

  • :start - Start byte offset (inclusive)
  • :end - End byte offset (exclusive)
  • :kind - Annotation type (bold, italic, link, etc.)
  • :url - URL for link annotations (nil for other types)

Examples

iex> annotation = %Kreuzberg.DocumentTextAnnotation{
...>   start: 0,
...>   end: 5,
...>   kind: "bold"
...> }
iex> annotation.kind
"bold"

Summary

Functions

Creates a DocumentTextAnnotation struct from a map.

Check if this is a link annotation.

Get human-readable annotation kind name.

Converts a DocumentTextAnnotation struct to a map.

Types

annotation_kind()

@type annotation_kind() ::
  :bold
  | :italic
  | :underline
  | :strikethrough
  | :code
  | :subscript
  | :superscript
  | :link

t()

@type t() :: %Kreuzberg.DocumentTextAnnotation{
  end: non_neg_integer(),
  kind: String.t(),
  start: non_neg_integer(),
  url: String.t() | nil
}

Functions

from_map(data)

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

Creates a DocumentTextAnnotation struct from a map.

Converts a plain map (typically from NIF/Rust) into a proper struct.

Parameters

  • data - A map containing annotation fields

Returns

A DocumentTextAnnotation struct with properly typed fields.

Examples

iex> annotation_map = %{
...>   "start" => 0,
...>   "end" => 5,
...>   "kind" => "bold"
...> }
iex> annotation = Kreuzberg.DocumentTextAnnotation.from_map(annotation_map)
iex> annotation.kind
"bold"

is_link?(document_text_annotation)

@spec is_link?(t()) :: boolean()

Check if this is a link annotation.

Parameters

  • annotation - A DocumentTextAnnotation struct

Returns

Boolean indicating whether the annotation is a link.

Examples

iex> annotation = %Kreuzberg.DocumentTextAnnotation{kind: "link", url: "https://example.com"}
iex> Kreuzberg.DocumentTextAnnotation.is_link?(annotation)
true

readable_kind(document_text_annotation)

@spec readable_kind(t()) :: String.t()

Get human-readable annotation kind name.

Converts annotation kind to a display-friendly string.

Parameters

  • annotation - A DocumentTextAnnotation struct

Returns

A human-readable string representation of the annotation kind.

Examples

iex> annotation = %Kreuzberg.DocumentTextAnnotation{kind: "bold"}
iex> Kreuzberg.DocumentTextAnnotation.readable_kind(annotation)
"Bold"

to_map(annotation)

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

Converts a DocumentTextAnnotation struct to a map.

Useful for serialization and passing to external systems.

Parameters

  • annotation - A DocumentTextAnnotation struct

Returns

A map with string keys representing all fields.

Examples

iex> annotation = %Kreuzberg.DocumentTextAnnotation{
...>   start: 0,
...>   end: 5,
...>   kind: "bold"
...> }
iex> Kreuzberg.DocumentTextAnnotation.to_map(annotation)
%{"start" => 0, "end" => 5, "kind" => "bold", "url" => nil}