loaders

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package loaders provides document loaders for different file formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVLoader

type CSVLoader struct {
	// contains filtered or unexported fields
}

CSVLoader loads CSV files as knowledge documents (one document per row).

func NewCSVLoader

func NewCSVLoader(paths []string, hasHeader bool) *CSVLoader

NewCSVLoader creates a loader for CSV files. If hasHeader is true, the first row is treated as column names and used to label fields.

func (*CSVLoader) Load

func (l *CSVLoader) Load() ([]knowledge.Document, error)

Load reads all CSV files and returns one document per row.

type ChunkStrategy

type ChunkStrategy int

ChunkStrategy defines how text is split into chunks.

const (
	ChunkByCharacters ChunkStrategy = iota
	ChunkBySentences
	ChunkByParagraphs
)

type Chunker

type Chunker struct {
	Strategy  ChunkStrategy
	ChunkSize int
	Overlap   int
}

Chunker splits text into chunks using configurable strategies.

func NewChunker

func NewChunker(strategy ChunkStrategy, chunkSize, overlap int) *Chunker

NewChunker creates a chunker with the given strategy.

func (*Chunker) Split

func (c *Chunker) Split(text string) []string

Split divides text into chunks according to the configured strategy.

type JSONLoader

type JSONLoader struct {
	// contains filtered or unexported fields
}

JSONLoader loads JSON files as knowledge documents. Supports both JSON arrays (one document per element) and single objects (one document).

func NewJSONLoader

func NewJSONLoader(paths []string) *JSONLoader

NewJSONLoader creates a loader for JSON files.

func (*JSONLoader) Load

func (l *JSONLoader) Load() ([]knowledge.Document, error)

Load reads all JSON files and returns documents.

type PDFLoader

type PDFLoader struct {
	// contains filtered or unexported fields
}

PDFLoader loads PDF files as knowledge documents by extracting text content. It uses a lightweight pure-Go text extraction approach that handles common PDF text streams without requiring external dependencies like poppler.

func NewPDFLoader

func NewPDFLoader(paths []string, chunkSize, overlap int) *PDFLoader

NewPDFLoader creates a loader for PDF files. chunkSize controls the maximum characters per document chunk (0 = no chunking). overlap controls how many characters overlap between consecutive chunks.

func (*PDFLoader) Load

func (l *PDFLoader) Load() ([]knowledge.Document, error)

Load reads all PDF files and returns documents, optionally chunked.

type TextLoader

type TextLoader struct {
	// contains filtered or unexported fields
}

TextLoader loads plain text files as knowledge documents.

func NewTextLoader

func NewTextLoader(paths []string, chunkSize, overlap int) *TextLoader

NewTextLoader creates a loader for plain text files. chunkSize controls the maximum characters per document chunk (0 = no chunking). overlap controls how many characters overlap between consecutive chunks.

func (*TextLoader) Load

func (l *TextLoader) Load() ([]knowledge.Document, error)

Load reads all files and returns documents, optionally chunked.

type WebLoader

type WebLoader struct {
	// contains filtered or unexported fields
}

WebLoader loads web pages as knowledge documents by scraping URL content and extracting readable text. It strips HTML tags and normalizes whitespace.

func NewWebLoader

func NewWebLoader(urls []string, chunkSize, overlap int) *WebLoader

NewWebLoader creates a loader for web pages. chunkSize controls the maximum characters per document chunk (0 = no chunking). overlap controls how many characters overlap between consecutive chunks.

func (*WebLoader) Load

func (l *WebLoader) Load() ([]knowledge.Document, error)

Load fetches all URLs and returns documents, optionally chunked.

func (*WebLoader) WithTimeout

func (l *WebLoader) WithTimeout(timeout time.Duration) *WebLoader

WithTimeout sets a custom HTTP timeout for the loader.

Jump to

Keyboard shortcuts

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