textchunk

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkByTokenCount

func ChunkByTokenCount(text string, maxTokens, overlap int, countTokens CountFunc) ([]string, error)

ChunkByTokenCount deterministically splits text into chunks that fit within maxTokens according to the supplied token counter.

Types

type CountFunc

type CountFunc func(text string) (int, error)

CountFunc returns the token count for the provided text.

type Span

type Span struct {
	Start, End int
}

Span is a chunk's [Start, End) byte offsets in the text it was cut from; -1, -1 for a chunk that could not be found there.

func Align

func Align(text string, chunks []string) []Span

Align finds where each chunk lies in text. Chunks come in text order and may overlap (a chunker's overlap), so each is looked for from just after the previous chunk's start, within a window a little longer than the chunk past where the previous one ended. A chunker moves forward, so a chunk ends past the previous one: an occurrence lying wholly inside the previous chunk (repetitive text repeated a few characters in) is skipped for the next one, and each chunk takes its own occurrence, in order. A chunker that returns the text verbatim (NornicDB's own; Voyage's contextualized auto-chunking, checked against its API) is matched exactly; one that trims or collapses whitespace is matched with whitespace ignored. A chunk found neither way is -1, -1, and the next is looked for from the same place.

func (Span) Found

func (s Span) Found() bool

Found reports whether the chunk was found in the text.

Jump to

Keyboard shortcuts

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