tokenwindow

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package tokenwindow preserves source text when vocabulary tokens split UTF-8.

Index

Constants

This section is empty.

Variables

View Source
var ErrSearchBudgetExceeded = errors.New("tokenwindow: search budget exceeded")

ErrSearchBudgetExceeded means the search stopped without proving absence.

Functions

func Prefix

func Prefix(ctx context.Context, codec tokenizer.Tokenizer, source string, limit, maxWork int, render func(string) string) (string, error)

Prefix returns a lossless source prefix whose rendered text fits the budget. Probe and final rendering are encoded independently because vocabulary boundaries can change after trimming or adding structural context. Chunk boundaries are selected from the probe, not a whole-document tokenization. Token-prefix decoding is only a candidate selector: if it finds no admissible prefix, every source rune boundary is checked by independent encoding. Token counts need not be monotonic. An empty result proves that no nonempty rendered source prefix fits. maxWork bounds input bytes passed to render and Encode, plus tokens passed to Decode; each operation costs at least one unit.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL