LangExtract.Chunker (LangExtract v0.9.0)

Copy Markdown View Source

Splits text into sentence-level chunks using the Alignment.Tokenizer.

Sentence boundary rules (mirroring upstream's find_sentence_range):

  1. A :punctuation token ending in a sentence terminator (., !, ?, CJK equivalents — ... counts, since symbol runs are one token) ends a sentence, unless the previous token plus the terminator form a known abbreviation ("Dr" <> "." == "Dr.").
  2. After sentence-ending punctuation, trailing closing punctuation (", ', ), ], }, », , ) is consumed into the same sentence.
  3. A :whitespace token containing \n starts a new sentence unless the next token begins lowercase — lines opening with quotes, digits, or capitals all break (upstream: "assume break unless lowercase").

Summary

Functions

Splits text into chunks respecting sentence boundaries.

Functions

chunk(text, opts)

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

Splits text into chunks respecting sentence boundaries.

Options

  • :max_chunk_chars — maximum characters per chunk (required)