textsplitter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package textsplitter provides a simple text splitter that can be used to split text into words.

Index

Constants

View Source
const (
	// DefaultTokenChunkOverlap specifies the default number of overlapping tokens
	// between consecutive chunks.
	DefaultTokenChunkOverlap = 100

	// DefaultTokenChunkSize defines the default maximum number of tokens per
	// chunk.
	DefaultTokenChunkSize = 4096

	// DefaultTokenEncoding specifies the default encoding scheme for
	// tokenization.
	DefaultTokenEncoding = "cl100k_base"

	// DefaultTokenModelName defines the default model name used for
	// tokenization.
	DefaultTokenModelName = "gpt-3.5-turbo"
)

Default configuration values for token splitting.

Variables

This section is empty.

Functions

This section is empty.

Types

type TokenSplitter

type TokenSplitter struct {
	// AllowedSpecial defines the list of allowed special tokens.
	AllowedSpecial []string

	// ChunkOverlap specifies the number of tokens to overlap between
	// consecutive chunks.
	ChunkOverlap int

	// ChunkSize defines the maximum number of tokens per chunk.
	ChunkSize int

	// DisallowedSpecial defines the list of disallowed special tokens.
	DisallowedSpecial []string

	// EncodingName specifies the encoding scheme to use for tokenization.
	EncodingName string

	// ModelName defines the model to determine token encoding.
	ModelName string
}

TokenSplitter implements text splitting functionality based on token count. It provides configuration options for chunk size, overlap, model selection, and special token handling.

func NewTokenSplitter

func NewTokenSplitter(chunkThreshold int) TokenSplitter

NewTokenSplitter creates a new TokenSplitter with default configuration. It allows overriding the default chunk size through the chunkThreshold parameter.

func (TokenSplitter) SplitText

func (s TokenSplitter) SplitText(text string) ([]string, error)

SplitText divides the input text into chunks based on token count.

Jump to

Keyboard shortcuts

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