Chunx.Chunker behaviour (chunx v0.2.0)

Copy Markdown View Source

Defines the shared callback types for chunkers.

Summary

Types

chunk_result()

@type chunk_result() ::
  {:ok, [Chunx.Chunk.t()] | [Chunx.SentenceChunk.t()]} | {:error, term()}

embedding_fun()

@type embedding_fun() :: ([String.t()] -> [Nx.Tensor.t()])

Callbacks

chunk(text, tokenizer, opts_or_embedding_fun)

@callback chunk(
  text :: String.t(),
  tokenizer :: Chunx.Tokenizer.t(),
  opts_or_embedding_fun :: keyword() | embedding_fun()
) :: chunk_result()

Splits text using a tokenizer.

Semantic chunkers take an embedding function instead of options as the third argument and accept options as a fourth argument.

Parameters

  • text - The text to chunk
  • tokenizer - The tokenizer to use
  • opts_or_embedding_fun - Options specific to the chunking strategy, or the embedding function used by a semantic chunker

chunk(text, tokenizer, embedding_fun, opts)

(optional)
@callback chunk(
  text :: String.t(),
  tokenizer :: Chunx.Tokenizer.t(),
  embedding_fun(),
  opts :: keyword()
) :: chunk_result()