Kreuzberg.Chunk (kreuzberg v4.4.1)

Copy Markdown View Source

Structure representing a text chunk with embedding for semantic search.

Matches the Rust Chunk struct.

Fields

  • :content - The text content of this chunk
  • :embedding - Vector embedding (list of floats) for semantic search
  • :metadata - ChunkMetadata struct with position and token info

Summary

Functions

Creates a Chunk struct from a map.

Creates a new Chunk struct.

Converts a Chunk struct to a map.

Types

t()

@type t() :: %Kreuzberg.Chunk{
  content: String.t(),
  embedding: [float()] | nil,
  metadata: Kreuzberg.ChunkMetadata.t()
}

Functions

from_map(data)

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

Creates a Chunk struct from a map.

Examples

iex> Kreuzberg.Chunk.from_map(%{"content" => "chunk text", "embedding" => [0.1, 0.2]})
%Kreuzberg.Chunk{content: "chunk text", embedding: [0.1, 0.2]}

new(content, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: t()

Creates a new Chunk struct.

Parameters

  • content - The text content of the chunk
  • opts - Optional keyword list with :embedding and :metadata

to_map(chunk)

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

Converts a Chunk struct to a map.