Documentation
¶
Index ¶
- Constants
- func EffectiveChunkSizeAfterMetadata(chunkSize, metadataTokenCount int) (int, error)
- func EffectiveChunkSizeForMetadataAwareSplit(chunkSize int, tokenizer Tokenizer, metadata string) (int, error)
- func GetEncodingForModel(model string) string
- func MetadataTokenCount(tokenizer Tokenizer, metadata string) int
- func SplitByChar() func(string) []string
- func SplitByRegex(regexStr string) func(string) []string
- func SplitBySep(sep string) func(string) []string
- func SplitTextKeepSeparator(text string, separator string) []string
- func ValidateLanguageConfig(c LanguageConfig) error
- type CodeSplitter
- type LanguageConfig
- type MarkdownHeaderType
- type MarkdownSplitter
- func (s *MarkdownSplitter) SplitText(text string) []string
- func (s *MarkdownSplitter) SplitTextMetadataAware(text string, metadata string) ([]string, error)
- func (s *MarkdownSplitter) WithHeadersToSplitOn(headers []string) *MarkdownSplitter
- func (s *MarkdownSplitter) WithStripHeaders(strip bool) *MarkdownSplitter
- func (s *MarkdownSplitter) WithTokenizer(tokenizer Tokenizer) *MarkdownSplitter
- type MetadataAwareTextSplitter
- type NeurosnapSplitterStrategy
- type RegexSplitterStrategy
- type SemanticDoubleMergingSplitter
- type SemanticSplitterNodeParser
- type SentenceSplitter
- func (s *SentenceSplitter) SplitText(text string) []string
- func (s *SentenceSplitter) SplitTextMetadataAware(text string, metadata string) ([]string, error)
- func (s *SentenceSplitter) Validate() error
- func (s *SentenceSplitter) WithOnChunkingEnd(fn func(chunks []string)) *SentenceSplitter
- func (s *SentenceSplitter) WithOnChunkingStart(fn func(text []string)) *SentenceSplitter
- type SentenceSplitterStrategy
- type SentenceWindow
- type SentenceWindowNodeData
- type SentenceWindowSplitter
- func (s *SentenceWindowSplitter) GetWindowsText(text string) []string
- func (s *SentenceWindowSplitter) SplitText(text string) []string
- func (s *SentenceWindowSplitter) SplitTextForNodes(text string) []SentenceWindowNodeData
- func (s *SentenceWindowSplitter) SplitTextWithWindows(text string) []SentenceWindow
- func (s *SentenceWindowSplitter) WithMetadataKeys(originalKey, windowKey string) *SentenceWindowSplitter
- func (s *SentenceWindowSplitter) WithSentenceSplitter(splitter SentenceSplitterStrategy) *SentenceWindowSplitter
- func (s *SentenceWindowSplitter) WithTokenizer(tokenizer Tokenizer) *SentenceWindowSplitter
- type SimpleTokenizer
- type TextSplitter
- type TikTokenTokenizer
- type TikTokenTokenizerByEncoding
- func (t *TikTokenTokenizerByEncoding) CountTokens(text string) int
- func (t *TikTokenTokenizerByEncoding) Decode(tokenIDs []int) string
- func (t *TikTokenTokenizerByEncoding) Encode(text string) []string
- func (t *TikTokenTokenizerByEncoding) EncodeToIDs(text string) []int
- func (t *TikTokenTokenizerByEncoding) EncodingName() string
- type TokenCounter
- type TokenTextSplitter
- func (s *TokenTextSplitter) SplitText(text string) []string
- func (s *TokenTextSplitter) SplitTextMetadataAware(text string, metadata string) ([]string, error)
- func (s *TokenTextSplitter) Validate() error
- func (s *TokenTextSplitter) WithKeepSeparator(keep bool) *TokenTextSplitter
- func (s *TokenTextSplitter) WithSeparator(sep string) *TokenTextSplitter
- type Tokenizer
Constants ¶
const ( DefaultChunkSize = 1024 DefaultChunkOverlap = 200 DefaultParagraphSep = "\n\n\n" DefaultSeparator = " " DefaultChunkingRegex = `[^,.;。?!]+[,.;。?!]?|[,.;。?!]` )
const ( EncodingCL100kBase = "cl100k_base" // GPT-4, GPT-3.5-turbo, text-embedding-ada-002 EncodingP50kBase = "p50k_base" // Codex models, text-davinci-002/003 EncodingR50kBase = "r50k_base" // GPT-3 models like davinci EncodingO200kBase = "o200k_base" // GPT-4o models )
Common encoding names
const MinEffectiveContentChunkTokens = 50
MinEffectiveContentChunkTokens is the minimum usable chunk size (in tokenizer units) after reserving space for metadata.
Variables ¶
This section is empty.
Functions ¶
func EffectiveChunkSizeAfterMetadata ¶ added in v0.0.3
EffectiveChunkSizeAfterMetadata returns chunkSize minus metadataTokenCount, or an error if the remainder is below MinEffectiveContentChunkTokens.
func EffectiveChunkSizeForMetadataAwareSplit ¶ added in v0.0.3
func EffectiveChunkSizeForMetadataAwareSplit(chunkSize int, tokenizer Tokenizer, metadata string) (int, error)
EffectiveChunkSizeForMetadataAwareSplit returns the content chunk size (in tokenizer units) after reserving space for metadata. It is shared by splitters that clone themselves with a reduced ChunkSize for metadata-aware splitting.
func GetEncodingForModel ¶
GetEncodingForModel returns the encoding name for a given model. Returns cl100k_base as default if model is not found.
func MetadataTokenCount ¶ added in v0.0.3
MetadataTokenCount returns the tokenizer token count for metadata.
func SplitByChar ¶
SplitByChar returns a function that splits text into characters.
func SplitByRegex ¶
SplitByRegex returns a function that splits text using a regex.
func SplitBySep ¶
SplitBySep returns a function that splits text by a separator.
func SplitTextKeepSeparator ¶
SplitTextKeepSeparator splits text with separator and keeps the separator at the start of each split (except the first).
func ValidateLanguageConfig ¶ added in v0.0.3
func ValidateLanguageConfig(c LanguageConfig) error
ValidateLanguageConfig returns an error if the language or spaCy model is not supported.
Types ¶
type CodeSplitter ¶ added in v0.0.3
CodeSplitter splits code using language-specific rules: Go uses the Go parser (top-level declaration boundaries); Python uses top-level def/class/async def line detection; other languages use line windows with overlap and max size.
func NewCodeSplitter ¶ added in v0.0.3
func NewCodeSplitter(language string, chunkLines int, chunkLinesOverlap int, maxChars int) *CodeSplitter
NewCodeSplitter creates a new CodeSplitter.
Args:
language: The programming language of the code being split. chunkLines: The number of lines to include in each chunk. chunkLinesOverlap: How many lines of code each chunk overlaps with. maxChars: Maximum number of characters (Unicode code points) per chunk.
Returns:
A pointer to the newly created CodeSplitter.
Non-positive chunkLines or maxChars are replaced with defaults (40 lines, 1500 code points). Negative chunkLinesOverlap is replaced with the default (15). Zero overlap means no overlap. Positive overlap is clamped to be less than the effective chunk line count.
func (*CodeSplitter) SplitText ¶ added in v0.0.3
func (s *CodeSplitter) SplitText(text string) []string
SplitText splits the provided code string into chunks.
Args:
text: The code string to split.
Returns:
A slice of code chunks.
type LanguageConfig ¶ added in v0.0.3
LanguageConfig configures the language and model name for SemanticDoubleMergingSplitter (aligned with LlamaIndex Python). The Go implementation does not load spaCy; the model field is validated for API compatibility.
type MarkdownHeaderType ¶
MarkdownHeaderType represents a markdown header.
type MarkdownSplitter ¶
type MarkdownSplitter struct {
// ChunkSize is the maximum size of each chunk in tokens.
ChunkSize int
// ChunkOverlap is the number of overlapping tokens between chunks.
ChunkOverlap int
// Tokenizer is used to count tokens.
Tokenizer Tokenizer
// HeadersToSplitOn defines which header levels trigger splits.
// Default: ["#", "##", "###", "####", "#####", "######"]
HeadersToSplitOn []string
// ReturnEachLine if true, returns each line as a separate chunk.
ReturnEachLine bool
// StripHeaders if true, removes headers from the output.
StripHeaders bool
}
MarkdownSplitter splits markdown text while preserving structure. It respects headers, code blocks, and other markdown elements.
func NewMarkdownSplitter ¶
func NewMarkdownSplitter(chunkSize, chunkOverlap int) *MarkdownSplitter
NewMarkdownSplitter creates a new MarkdownSplitter with default settings.
func (*MarkdownSplitter) SplitText ¶
func (s *MarkdownSplitter) SplitText(text string) []string
SplitText splits markdown text into chunks.
func (*MarkdownSplitter) SplitTextMetadataAware ¶
func (s *MarkdownSplitter) SplitTextMetadataAware(text string, metadata string) ([]string, error)
SplitTextMetadataAware splits text accounting for metadata token usage.
func (*MarkdownSplitter) WithHeadersToSplitOn ¶
func (s *MarkdownSplitter) WithHeadersToSplitOn(headers []string) *MarkdownSplitter
WithHeadersToSplitOn sets which headers to split on.
func (*MarkdownSplitter) WithStripHeaders ¶
func (s *MarkdownSplitter) WithStripHeaders(strip bool) *MarkdownSplitter
WithStripHeaders sets whether to strip headers from output.
func (*MarkdownSplitter) WithTokenizer ¶
func (s *MarkdownSplitter) WithTokenizer(tokenizer Tokenizer) *MarkdownSplitter
WithTokenizer sets a custom tokenizer.
type MetadataAwareTextSplitter ¶ added in v0.0.3
type MetadataAwareTextSplitter interface {
TextSplitter
// SplitTextMetadataAware splits text into chunks, accounting for metadata length.
SplitTextMetadataAware(text string, metadata string) ([]string, error)
}
MetadataAwareTextSplitter splits text while accounting for metadata length (e.g. reserved context window for metadata in RAG).
type NeurosnapSplitterStrategy ¶
type NeurosnapSplitterStrategy struct {
// contains filtered or unexported fields
}
NeurosnapSplitterStrategy uses neurosnap/sentences for sentence splitting.
func NewNeurosnapSplitterStrategy ¶
func NewNeurosnapSplitterStrategy(trainingData []byte) (*NeurosnapSplitterStrategy, error)
NewNeurosnapSplitterStrategy creates a new strategy using the provided JSON training data. If trainingData is nil or empty, it defaults to the embedded english.json training data.
func NewNeurosnapSplitterStrategyFromFile ¶
func NewNeurosnapSplitterStrategyFromFile(path string) (*NeurosnapSplitterStrategy, error)
NewNeurosnapSplitterStrategyFromFile creates a new strategy by reading training data from a file.
func (*NeurosnapSplitterStrategy) Split ¶
func (s *NeurosnapSplitterStrategy) Split(text string) []string
type RegexSplitterStrategy ¶
type RegexSplitterStrategy struct {
// contains filtered or unexported fields
}
RegexSplitterStrategy uses regex for sentence splitting.
func NewRegexSplitterStrategy ¶
func NewRegexSplitterStrategy(regexStr string) *RegexSplitterStrategy
func (*RegexSplitterStrategy) Split ¶
func (s *RegexSplitterStrategy) Split(text string) []string
type SemanticDoubleMergingSplitter ¶ added in v0.0.3
type SemanticDoubleMergingSplitter struct {
LanguageConfig LanguageConfig
InitialThreshold float64
AppendingThreshold float64
MergingThreshold float64
MaxChunkSize int
MergingRange int
MergingSeparator string
SentenceSplitter SentenceSplitterStrategy
}
SemanticDoubleMergingSplitter splits text using a double merging semantic algorithm.
func NewSemanticDoubleMergingSplitter ¶ added in v0.0.3
func NewSemanticDoubleMergingSplitter( languageConfig LanguageConfig, initialThreshold float64, appendingThreshold float64, mergingThreshold float64, maxChunkSize int, mergingRange int, mergingSeparator string, sentenceSplitter SentenceSplitterStrategy, ) *SemanticDoubleMergingSplitter
NewSemanticDoubleMergingSplitter creates a new SemanticDoubleMergingSplitter.
Args:
languageConfig: Configuration for the language and model. initialThreshold: Sets threshold for initializing new chunk. appendingThreshold: Sets threshold for appending new sentences to chunk. mergingThreshold: Sets threshold for merging whole chunks. maxChunkSize: Maximum size of chunk (in characters). mergingRange: How many chunks ahead beyond the nearest neighbor to merge if similar (1 or 2). mergingSeparator: The separator to use when merging chunks. sentenceSplitter: Strategy to split text into sentences; if nil, RegexSplitterStrategy with DefaultChunkingRegex is used.
Returns:
A pointer to the newly created SemanticDoubleMergingSplitter. mergingRange is clamped to [1, 2].
func (*SemanticDoubleMergingSplitter) SplitText ¶ added in v0.0.3
func (s *SemanticDoubleMergingSplitter) SplitText(text string) []string
SplitText splits the text into chunks using the double merging algorithm.
Args:
text: The text string to split.
Returns:
Semantically grouped chunks. Empty input, no sentences after trimming, or invalid LanguageConfig yields a non-nil empty slice.
type SemanticSplitterNodeParser ¶ added in v0.0.3
type SemanticSplitterNodeParser struct {
EmbedModel embedding.EmbeddingModel
BufferSize int
BreakpointPercentileThreshold int
SentenceSplitter SentenceSplitterStrategy
}
SemanticSplitterNodeParser groups semantically related sentences using embedding similarity and a percentile-based breakpoint rule (aligned with LlamaIndex Python).
func NewSemanticSplitterNodeParser ¶ added in v0.0.3
func NewSemanticSplitterNodeParser( embedModel embedding.EmbeddingModel, bufferSize int, breakpointPercentileThreshold int, sentenceSplitter SentenceSplitterStrategy, ) *SemanticSplitterNodeParser
NewSemanticSplitterNodeParser creates a new SemanticSplitterNodeParser.
Args:
embedModel: The embedding model to use for similarity checks. bufferSize: Number of sentences to include before/after when forming combined text per index. breakpointPercentileThreshold: Percentile of pairwise dissimilarities used as the split threshold (0–100). sentenceSplitter: Strategy to split text into sentences; if nil, RegexSplitterStrategy with DefaultChunkingRegex is used.
Returns:
A configured SemanticSplitterNodeParser. Non-positive bufferSize defaults to 1. Threshold is clamped to [0, 100].
func (*SemanticSplitterNodeParser) SplitText ¶ added in v0.0.3
func (s *SemanticSplitterNodeParser) SplitText(text string) []string
SplitText splits the text into semantically grouped chunks.
Args:
text: The text string to split.
Returns:
A slice of chunks joined from original sentences (no added spaces between sentences). On embedding failure, invalid embeddings for similarity, or pairwise similarity failure, returns nil. Empty input, no embed model, or no sentences after trimming yields a non-nil empty slice.
type SentenceSplitter ¶
type SentenceSplitter struct {
ChunkSize int
ChunkOverlap int
Separator string
ParagraphSeparator string
SecondaryChunkingRegex string
Tokenizer Tokenizer
SplitterStrategy SentenceSplitterStrategy
// contains filtered or unexported fields
}
SentenceSplitter splits text with a preference for complete sentences.
func NewSentenceSplitter ¶
func NewSentenceSplitter( chunkSize int, chunkOverlap int, tokenizer Tokenizer, splitterStrategy SentenceSplitterStrategy, ) *SentenceSplitter
NewSentenceSplitter creates a new SentenceSplitter. Pass 0 or empty strings to use defaults. If tokenizer is nil, defaults to SimpleTokenizer. If splitterStrategy is nil, defaults to RegexSplitterStrategy with DefaultChunkingRegex.
func NewSentenceSplitterWithValidation ¶
func NewSentenceSplitterWithValidation( chunkSize int, chunkOverlap int, tokenizer Tokenizer, splitterStrategy SentenceSplitterStrategy, ) (*SentenceSplitter, error)
NewSentenceSplitterWithValidation creates a new SentenceSplitter with input validation. Returns an error if parameters are invalid.
func (*SentenceSplitter) SplitText ¶
func (s *SentenceSplitter) SplitText(text string) []string
SplitText splits the text into chunks.
func (*SentenceSplitter) SplitTextMetadataAware ¶
func (s *SentenceSplitter) SplitTextMetadataAware(text string, metadata string) ([]string, error)
SplitTextMetadataAware splits text into chunks, accounting for metadata length. This is useful for RAG applications where metadata consumes context window.
func (*SentenceSplitter) Validate ¶
func (s *SentenceSplitter) Validate() error
Validate validates the current splitter configuration.
func (*SentenceSplitter) WithOnChunkingEnd ¶
func (s *SentenceSplitter) WithOnChunkingEnd(fn func(chunks []string)) *SentenceSplitter
WithOnChunkingEnd sets the callback for when chunking ends.
func (*SentenceSplitter) WithOnChunkingStart ¶
func (s *SentenceSplitter) WithOnChunkingStart(fn func(text []string)) *SentenceSplitter
WithOnChunkingStart sets the callback for when chunking starts.
type SentenceSplitterStrategy ¶
SentenceSplitterStrategy is the interface for primary sentence splitting.
type SentenceWindow ¶
type SentenceWindow struct {
// Sentence is the original sentence.
Sentence string
// Window is the sentence with surrounding context.
Window string
// Index is the sentence index in the original text.
Index int
// StartSentence is the index of the first sentence in the window.
StartSentence int
// EndSentence is the index of the last sentence in the window.
EndSentence int
}
SentenceWindow represents a sentence with its surrounding context.
type SentenceWindowNodeData ¶
type SentenceWindowNodeData struct {
// Text is the sentence text (for embedding/matching).
Text string
// Window is the surrounding context.
Window string
// Metadata contains additional metadata.
Metadata map[string]interface{}
}
SentenceWindowNodeData contains data for creating nodes with window metadata.
type SentenceWindowSplitter ¶
type SentenceWindowSplitter struct {
// WindowSize is the number of sentences to include on each side.
WindowSize int
// Tokenizer is used to count tokens.
Tokenizer Tokenizer
// SentenceSplitter is used to split text into sentences.
SentenceSplitter SentenceSplitterStrategy
// OriginalTextMetadataKey is the metadata key for storing the original sentence.
OriginalTextMetadataKey string
// WindowMetadataKey is the metadata key for storing the window text.
WindowMetadataKey string
}
SentenceWindowSplitter splits text into sentences and includes surrounding context (window) for each sentence. This is useful for retrieval where you want to match on a specific sentence but return more context.
func NewSentenceWindowSplitter ¶
func NewSentenceWindowSplitter(windowSize int) *SentenceWindowSplitter
NewSentenceWindowSplitter creates a new SentenceWindowSplitter.
func (*SentenceWindowSplitter) GetWindowsText ¶
func (s *SentenceWindowSplitter) GetWindowsText(text string) []string
GetWindowsText returns just the window texts (for embedding the context).
func (*SentenceWindowSplitter) SplitText ¶
func (s *SentenceWindowSplitter) SplitText(text string) []string
SplitText splits text into sentences (returns just the sentences). Use SplitTextWithWindows for full window information.
func (*SentenceWindowSplitter) SplitTextForNodes ¶
func (s *SentenceWindowSplitter) SplitTextForNodes(text string) []SentenceWindowNodeData
SplitTextForNodes returns data suitable for creating nodes with window metadata.
func (*SentenceWindowSplitter) SplitTextWithWindows ¶
func (s *SentenceWindowSplitter) SplitTextWithWindows(text string) []SentenceWindow
SplitTextWithWindows splits text and returns sentences with their windows.
func (*SentenceWindowSplitter) WithMetadataKeys ¶
func (s *SentenceWindowSplitter) WithMetadataKeys(originalKey, windowKey string) *SentenceWindowSplitter
WithMetadataKeys sets custom metadata keys.
func (*SentenceWindowSplitter) WithSentenceSplitter ¶
func (s *SentenceWindowSplitter) WithSentenceSplitter(splitter SentenceSplitterStrategy) *SentenceWindowSplitter
WithSentenceSplitter sets a custom sentence splitter.
func (*SentenceWindowSplitter) WithTokenizer ¶
func (s *SentenceWindowSplitter) WithTokenizer(tokenizer Tokenizer) *SentenceWindowSplitter
WithTokenizer sets a custom tokenizer.
type SimpleTokenizer ¶
type SimpleTokenizer struct{}
SimpleTokenizer tokenizes text by splitting on whitespace.
func NewSimpleTokenizer ¶
func NewSimpleTokenizer() *SimpleTokenizer
func (*SimpleTokenizer) Encode ¶
func (t *SimpleTokenizer) Encode(text string) []string
type TextSplitter ¶
TextSplitter is the interface for splitting text.
type TikTokenTokenizer ¶
type TikTokenTokenizer struct {
// contains filtered or unexported fields
}
TikTokenTokenizer tokenizes text using OpenAI's tiktoken.
func NewTikTokenTokenizer ¶
func NewTikTokenTokenizer(model string) (*TikTokenTokenizer, error)
func (*TikTokenTokenizer) CountTokens ¶
func (t *TikTokenTokenizer) CountTokens(text string) int
CountTokens counts tokens using the TikTokenTokenizer.
func (*TikTokenTokenizer) Encode ¶
func (t *TikTokenTokenizer) Encode(text string) []string
type TikTokenTokenizerByEncoding ¶
type TikTokenTokenizerByEncoding struct {
// contains filtered or unexported fields
}
TikTokenTokenizerByEncoding creates a tokenizer using a specific encoding name.
func NewTikTokenTokenizerByEncoding ¶
func NewTikTokenTokenizerByEncoding(encodingName string) (*TikTokenTokenizerByEncoding, error)
NewTikTokenTokenizerByEncoding creates a tokenizer using a specific encoding.
func (*TikTokenTokenizerByEncoding) CountTokens ¶
func (t *TikTokenTokenizerByEncoding) CountTokens(text string) int
CountTokens returns the number of tokens in the text.
func (*TikTokenTokenizerByEncoding) Decode ¶
func (t *TikTokenTokenizerByEncoding) Decode(tokenIDs []int) string
Decode converts token IDs back to text.
func (*TikTokenTokenizerByEncoding) Encode ¶
func (t *TikTokenTokenizerByEncoding) Encode(text string) []string
Encode tokenizes text and returns token strings.
func (*TikTokenTokenizerByEncoding) EncodeToIDs ¶
func (t *TikTokenTokenizerByEncoding) EncodeToIDs(text string) []int
EncodeToIDs returns the raw token IDs.
func (*TikTokenTokenizerByEncoding) EncodingName ¶
func (t *TikTokenTokenizerByEncoding) EncodingName() string
EncodingName returns the encoding name.
type TokenCounter ¶
TokenCounter is an interface for counting tokens.
type TokenTextSplitter ¶
type TokenTextSplitter struct {
// ChunkSize is the maximum number of tokens per chunk.
ChunkSize int
// ChunkOverlap is the number of overlapping tokens between chunks.
ChunkOverlap int
// Tokenizer is used to count tokens. Defaults to SimpleTokenizer.
Tokenizer Tokenizer
// Separator is used to split text into initial segments. Defaults to " ".
Separator string
// KeepSeparator determines if separators are kept in the output.
KeepSeparator bool
}
TokenTextSplitter splits text based on token count rather than character count. This is useful when working with LLMs that have token limits.
func NewTokenTextSplitter ¶
func NewTokenTextSplitter(chunkSize, chunkOverlap int) *TokenTextSplitter
NewTokenTextSplitter creates a new TokenTextSplitter with default settings.
func NewTokenTextSplitterWithTokenizer ¶
func NewTokenTextSplitterWithTokenizer(chunkSize, chunkOverlap int, tokenizer Tokenizer) *TokenTextSplitter
NewTokenTextSplitterWithTokenizer creates a TokenTextSplitter with a custom tokenizer.
func NewTokenTextSplitterWithValidation ¶
func NewTokenTextSplitterWithValidation(chunkSize, chunkOverlap int, tokenizer Tokenizer) (*TokenTextSplitter, error)
NewTokenTextSplitterWithValidation creates a TokenTextSplitter with input validation. Returns an error if parameters are invalid.
func (*TokenTextSplitter) SplitText ¶
func (s *TokenTextSplitter) SplitText(text string) []string
SplitText splits text into chunks based on token count.
func (*TokenTextSplitter) SplitTextMetadataAware ¶
func (s *TokenTextSplitter) SplitTextMetadataAware(text string, metadata string) ([]string, error)
SplitTextMetadataAware splits text accounting for metadata token usage.
func (*TokenTextSplitter) Validate ¶
func (s *TokenTextSplitter) Validate() error
Validate validates the current splitter configuration.
func (*TokenTextSplitter) WithKeepSeparator ¶
func (s *TokenTextSplitter) WithKeepSeparator(keep bool) *TokenTextSplitter
WithKeepSeparator sets whether to keep separators.
func (*TokenTextSplitter) WithSeparator ¶
func (s *TokenTextSplitter) WithSeparator(sep string) *TokenTextSplitter
WithSeparator sets a custom separator.
type Tokenizer ¶
Tokenizer is the interface for tokenizing text. It encodes text into a list of string tokens.
func DefaultTokenizer ¶
DefaultTokenizer returns a shared default TikToken tokenizer using cl100k_base encoding. This is safe for concurrent use.
func MustDefaultTokenizer ¶
func MustDefaultTokenizer() Tokenizer
MustDefaultTokenizer returns the default tokenizer or panics on error.