Documentation
¶
Overview ¶
Package loader 提供 RAG 文档加载功能
本文件实现数据连接器:
- GitHub: 加载 GitHub 仓库、Issues、PR
- Notion: 加载 Notion 页面和数据库
- Slack: 加载 Slack 消息和频道
- Database: 加载 SQL 数据库内容
设计借鉴:
- LlamaIndex: Data Connectors
- LangChain: Document Loaders
Package loader 提供 RAG 系统的文档加载器 ¶
csv.go 实现 CSV 文件加载器和 Excel/PPTX 加载器:
- CSVLoader: 标准 CSV 格式解析,支持自定义分隔符、内容列指定
- ExcelLoader: Excel (.xlsx) 文件加载
- PPTXLoader: PowerPoint (.pptx) 文件加载
使用示例:
loader := NewCSVLoader("data.csv",
WithCSVSeparator(';'),
WithCSVContentColumn("description"),
)
docs, err := loader.Load(ctx)
Package loader 提供 RAG 系统的文档加载器 ¶
Loader 用于从各种来源加载文档:
- TextLoader: 纯文本文件
- MarkdownLoader: Markdown 文件
- DirectoryLoader: 目录批量加载
- URLLoader: 从 URL 加载
Package loader 提供 RAG 系统的文档加载器 ¶
本文件实现额外的文档加载器:
- GitHubLoader: GitHub 仓库加载器
- YAMLLoader: YAML 文件加载器
- CompositeLoader: 组合加载器
- S3Loader: AWS S3 加载器
- DatabaseLoader: 数据库加载器
- NotionLoader: Notion 文档加载器
- SlackLoader: Slack 消息加载器
Package loader 提供 RAG 系统的文档加载器 ¶
ocr.go 实现高级文档解析 (OCR) 能力:
- OCRLoader: 通用 OCR 加载器,支持图片和扫描 PDF
- OCREngine: OCR 引擎接口,可对接 Tesseract、PaddleOCR 等
- TesseractEngine: Tesseract OCR 引擎实现
- VisionLLMEngine: 基于多模态 LLM 的 OCR(如 GPT-4V)
对标 LlamaIndex 的 LlamaParse 高级文档解析能力。
使用示例:
// 方式 1: 使用 Tesseract
engine := NewTesseractEngine(WithTesseractLang("chi_sim+eng"))
loader := NewOCRLoader("scan.pdf", engine)
docs, err := loader.Load(ctx)
// 方式 2: 使用多模态 LLM
engine := NewVisionLLMEngine(llmProvider, "gpt-4-vision-preview")
loader := NewOCRLoader("photo.png", engine)
docs, err := loader.Load(ctx)
Package loader 提供 Hexagon RAG 的文档加载与解析能力 ¶
本文件定义文档解析层抽象:把原始字节解析为结构化 Document。
解析层与加载层(Loader)正交:Loader 负责从来源取数据(文件/URL/数据库等), Parser 负责把取到的字节解析成结构化内容。解析引擎可插拔——既能注册本地解析器, 也能注册外部解析服务(如独立的多模态文档理解 gRPC 服务)的适配器,只要其实现 Parser 接口即可接入。多模态:图片经可注入的 VLM 描述后端转为文本描述 Document。
Index ¶
- Variables
- type CSVLoader
- type CSVOption
- func WithCSVContentColumn(column string) CSVOption
- func WithCSVContentColumns(cols ...string) CSVOption
- func WithCSVDelimiter(delim rune) CSVOption
- func WithCSVHeader(hasHeader bool) CSVOption
- func WithCSVMetadataColumns(columns []string) CSVOption
- func WithCSVNoHeader() CSVOption
- func WithCSVRowsPerDoc(rows int) CSVOption
- func WithCSVSeparator(sep rune) CSVOption
- type CompositeLoader
- type Connector
- type DOCXLoader
- type DOCXOption
- type DatabaseConfig
- type DatabaseConnector
- type DatabaseLoader
- type DatabaseOption
- type DirectoryLoader
- type DirectoryOption
- type Document
- type EnhancedPDFParser
- type ExcelLoader
- type ExcelOption
- type GitHubConfig
- type GitHubConnector
- type GitHubLoadType
- type GitHubLoader
- type GitHubOption
- type HTMLLoader
- type HTMLOption
- type ImageDescriber
- type ImageParser
- type JSONLoader
- type JSONOption
- type MarkdownLoader
- type MarkdownOption
- type NotionConfig
- type NotionConnector
- type NotionLoader
- type NotionOption
- type OCREngine
- type OCRLoader
- type OCRLoaderOption
- type OCRPage
- type OCRResult
- type PDFDocument
- type PDFLoader
- type PDFMetadata
- type PDFOption
- type PDFParser
- type PPTXLoader
- type PPTXOption
- type ParseEngine
- type ParseInput
- type Parser
- type ReaderLoader
- type S3Loader
- type S3Option
- type SimplePDFParser
- type SlackConfig
- type SlackConnector
- type SlackLoader
- type SlackOption
- type StringLoader
- type TesseractEngine
- type TesseractOption
- type TextLoader
- type TextParser
- type URLLoader
- type URLOption
- type VisionLLMEngine
- type VisionLLMOption
- type WebAPIConfig
- type WebAPIConnector
- type YAMLLoader
- type YAMLOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnectorFailed 连接器失败 ErrConnectorFailed = errors.New("connector failed") // ErrAuthFailed 认证失败 ErrAuthFailed = errors.New("authentication failed") // ErrRateLimited 被限流 ErrRateLimited = errors.New("rate limited") // ErrNotFound 未找到 ErrNotFound = errors.New("not found") )
var ErrNoImageDescriber = fmt.Errorf("rag/parser: 未注入 ImageDescriber(图片 VLM 描述后端)")
ErrNoImageDescriber 未注入图片描述后端时返回。
Functions ¶
This section is empty.
Types ¶
type CSVLoader ¶
type CSVLoader struct {
// contains filtered or unexported fields
}
CSVLoader CSV 文件加载器 将 CSV 文件中的每行数据转换为一个文档
func NewCSVLoader ¶
NewCSVLoader 创建 CSV 加载器
type CSVOption ¶
type CSVOption func(*CSVLoader)
CSVOption CSV 加载器选项
func WithCSVContentColumn ¶
WithCSVContentColumn 设置内容列名
func WithCSVContentColumns ¶
WithCSVContentColumns 设置多个内容列名
func WithCSVDelimiter ¶
WithCSVDelimiter 设置 CSV 分隔符(WithCSVSeparator 的别名)
func WithCSVMetadataColumns ¶
WithCSVMetadataColumns 设置元数据列
type CompositeLoader ¶
type CompositeLoader struct {
// contains filtered or unexported fields
}
CompositeLoader 组合加载器 可以组合多个加载器
func NewCompositeLoader ¶
func NewCompositeLoader(loaders ...rag.Loader) *CompositeLoader
NewCompositeLoader 创建组合加载器
func (*CompositeLoader) AddLoader ¶
func (l *CompositeLoader) AddLoader(loader rag.Loader)
AddLoader 添加加载器
type Connector ¶
type Connector interface {
// Name 连接器名称
Name() string
// Load 加载文档
Load(ctx context.Context) ([]*Document, error)
}
Connector 数据连接器接口
type DOCXLoader ¶
type DOCXLoader struct {
// contains filtered or unexported fields
}
DOCXLoader Word 文档加载器
支持从 DOCX 文件中提取文本内容。 DOCX 是基于 Open XML 格式的文档,本质是一个 ZIP 文件。
func NewDOCXLoader ¶
func NewDOCXLoader(path string, opts ...DOCXOption) *DOCXLoader
NewDOCXLoader 创建 DOCX 加载器
func NewDOCXLoaderFromReader ¶
func NewDOCXLoaderFromReader(r io.ReaderAt, size int64, opts ...DOCXOption) *DOCXLoader
NewDOCXLoaderFromReader 从 ReaderAt 创建 DOCX 加载器
type DOCXOption ¶
type DOCXOption func(*DOCXLoader)
DOCXOption DOCX 加载器选项
func WithDOCXExtractMetadata ¶
func WithDOCXExtractMetadata(extract bool) DOCXOption
WithDOCXExtractMetadata 提取元数据
func WithDOCXPreserveParagraphs ¶
func WithDOCXPreserveParagraphs(preserve bool) DOCXOption
WithDOCXPreserveParagraphs 保留段落结构
func WithDOCXSplitByHeading ¶
func WithDOCXSplitByHeading(split bool) DOCXOption
WithDOCXSplitByHeading 按标题分割
type DatabaseConfig ¶
type DatabaseConfig struct {
// DB 数据库连接
DB *sql.DB
// Query SQL 查询
Query string
// Columns 要提取的列
Columns []string
// Template 文档模板(使用 {{.ColumnName}} 语法)
Template string
}
DatabaseConfig 数据库连接器配置
type DatabaseConnector ¶
type DatabaseConnector struct {
// contains filtered or unexported fields
}
DatabaseConnector SQL 数据库连接器
func NewDatabaseConnector ¶
func NewDatabaseConnector(config *DatabaseConfig) *DatabaseConnector
NewDatabaseConnector 创建数据库连接器
type DatabaseLoader ¶
type DatabaseLoader struct {
// contains filtered or unexported fields
}
DatabaseLoader 数据库加载器
func NewDatabaseLoader ¶
func NewDatabaseLoader(driver, dsn string, opts ...DatabaseOption) *DatabaseLoader
NewDatabaseLoader 创建数据库加载器
type DatabaseOption ¶
type DatabaseOption func(*DatabaseLoader)
DatabaseOption 数据库加载器选项
func WithDBContentColumn ¶
func WithDBContentColumn(col string) DatabaseOption
WithDBContentColumn 设置内容列
func WithDBMetadataColumns ¶
func WithDBMetadataColumns(cols []string) DatabaseOption
WithDBMetadataColumns 设置元数据列
type DirectoryLoader ¶
type DirectoryLoader struct {
// contains filtered or unexported fields
}
DirectoryLoader 目录批量加载器
func NewDirectoryLoader ¶
func NewDirectoryLoader(path string, opts ...DirectoryOption) *DirectoryLoader
NewDirectoryLoader 创建目录加载器
type DirectoryOption ¶
type DirectoryOption func(*DirectoryLoader)
DirectoryOption 目录加载器选项
func WithLoaderFunc ¶
func WithLoaderFunc(fn func(path string) rag.Loader) DirectoryOption
WithLoaderFunc 设置自定义加载器工厂
type EnhancedPDFParser ¶
type EnhancedPDFParser struct{}
EnhancedPDFParser 增强型 PDF 解析器
支持现代 PDF 的核心特性:xref 表、压缩流、文本操作符解析、元数据提取。 适用于大部分标准 PDF 文件的文本提取场景。
限制:
- 不支持加密 PDF
- 不支持 CMap 字体映射(CID 字体可能输出为乱码)
- 不支持 XRef Stream(PDF 1.5+)的交叉引用流
- 不处理图片、表格等非文本内容
func (*EnhancedPDFParser) Parse ¶
func (p *EnhancedPDFParser) Parse(ctx context.Context, r io.Reader) (*PDFDocument, error)
Parse 解析 PDF 并返回结构化文档
解析流程:
- 读取全部数据并验证 PDF 签名
- 解析 xref 交叉引用表定位对象
- 提取 /Info 字典中的元数据
- 遍历页面树获取每页内容流
- 解压并解析内容流中的文本操作符
如果增强解析失败,自动降级到简单文本提取。
type ExcelLoader ¶
type ExcelLoader struct {
// contains filtered or unexported fields
}
ExcelLoader Excel 文件加载器(.xlsx 格式) 将 .xlsx 文件中的每行数据转换为一个文档
实现原理:.xlsx 文件本质是 ZIP 包,内含 XML 描述的工作表数据。 当前为基础实现,如需完整的 Excel 功能建议使用 excelize 等第三方库。
func NewExcelLoader ¶
func NewExcelLoader(path string, opts ...ExcelOption) *ExcelLoader
NewExcelLoader 创建 Excel 加载器
type ExcelOption ¶
type ExcelOption func(*ExcelLoader)
ExcelOption Excel 加载器配置选项
func WithExcelContentColumns ¶
func WithExcelContentColumns(cols ...string) ExcelOption
WithExcelContentColumns 设置用作内容的列名
func WithExcelMetadataColumns ¶
func WithExcelMetadataColumns(cols ...string) ExcelOption
WithExcelMetadataColumns 设置用作元数据的列名
func WithExcelSheet ¶
func WithExcelSheet(name string) ExcelOption
WithExcelSheet 设置工作表名称(空表示第一个工作表)
type GitHubConfig ¶
type GitHubConfig struct {
// Token GitHub 访问令牌
Token string
// Owner 仓库所有者
Owner string
// Repo 仓库名称
Repo string
// Branch 分支名称
Branch string
// Path 文件路径(可选)
Path string
// LoadType 加载类型
LoadType GitHubLoadType
// FileExtensions 文件扩展名过滤(仅 LoadFiles)
FileExtensions []string
// IssueState Issue 状态过滤
IssueState string // "open", "closed", "all"
// MaxItems 最大项数
MaxItems int
}
GitHubConfig GitHub 连接器配置
type GitHubConnector ¶
type GitHubConnector struct {
// contains filtered or unexported fields
}
GitHubConnector GitHub 数据连接器
func NewGitHubConnector ¶
func NewGitHubConnector(config *GitHubConfig) *GitHubConnector
NewGitHubConnector 创建 GitHub 连接器
type GitHubLoadType ¶
type GitHubLoadType int
GitHubLoadType GitHub 加载类型
const ( // GitHubLoadFiles 加载文件 GitHubLoadFiles GitHubLoadType = iota // GitHubLoadIssues 加载 Issues GitHubLoadIssues // GitHubLoadPRs 加载 Pull Requests GitHubLoadPRs // GitHubLoadDiscussions 加载 Discussions GitHubLoadDiscussions )
type GitHubLoader ¶
type GitHubLoader struct {
// contains filtered or unexported fields
}
GitHubLoader GitHub 仓库加载器
func NewGitHubLoader ¶
func NewGitHubLoader(owner, repo string, opts ...GitHubOption) *GitHubLoader
NewGitHubLoader 创建 GitHub 加载器
type GitHubOption ¶
type GitHubOption func(*GitHubLoader)
GitHubOption GitHub 加载器选项
func WithGitHubExtensions ¶
func WithGitHubExtensions(exts []string) GitHubOption
WithGitHubExtensions 设置文件扩展名过滤
func WithGitHubToken ¶
func WithGitHubToken(token string) GitHubOption
WithGitHubToken 设置 GitHub token
type HTMLLoader ¶
type HTMLLoader struct {
// contains filtered or unexported fields
}
HTMLLoader HTML 文档加载器
func NewHTMLLoader ¶
func NewHTMLLoader(path string, opts ...HTMLOption) *HTMLLoader
NewHTMLLoader 创建 HTML 加载器
func NewHTMLLoaderFromReader ¶
func NewHTMLLoaderFromReader(r io.Reader, url string, opts ...HTMLOption) *HTMLLoader
NewHTMLLoaderFromReader 从 Reader 创建 HTML 加载器
type HTMLOption ¶
type HTMLOption func(*HTMLLoader)
HTMLOption HTML 加载器选项
func WithHTMLExtractTitle ¶
func WithHTMLExtractTitle(extract bool) HTMLOption
WithHTMLExtractTitle 提取标题
func WithHTMLRemoveScripts ¶
func WithHTMLRemoveScripts(remove bool) HTMLOption
WithHTMLRemoveScripts 移除脚本
func WithHTMLRemoveStyles ¶
func WithHTMLRemoveStyles(remove bool) HTMLOption
WithHTMLRemoveStyles 移除样式
type ImageDescriber ¶
type ImageDescriber interface {
// Describe 返回图片的文本描述。
Describe(ctx context.Context, image []byte, mime string) (string, error)
}
ImageDescriber 是图片描述后端(VLM)的接口约定(seam)。
框架定义接口,具体后端(多模态 LLM 客户端)由调用方注入,不内置/不伪造, 避免在解析层硬依赖某家 VLM。
type ImageParser ¶
type ImageParser struct {
// contains filtered or unexported fields
}
ImageParser 把图片解析为其文本描述 Document(多模态文档理解)。
func NewImageParser ¶
func NewImageParser(describer ImageDescriber) *ImageParser
NewImageParser 创建图片解析器;describer 为图片描述后端(nil 时 Parse 返回错误)。
func (*ImageParser) CanParse ¶
func (p *ImageParser) CanParse(mime string) bool
CanParse 支持 image/* 类型。
func (*ImageParser) Parse ¶
func (p *ImageParser) Parse(ctx context.Context, in ParseInput) ([]Document, error)
Parse 调用 VLM 描述后端把图片转为文本描述 Document;未注入后端则返回 ErrNoImageDescriber。
type JSONLoader ¶
type JSONLoader struct {
// contains filtered or unexported fields
}
JSONLoader JSON 文件加载器
func NewJSONLoader ¶
func NewJSONLoader(path string, opts ...JSONOption) *JSONLoader
NewJSONLoader 创建 JSON 加载器
type JSONOption ¶
type JSONOption func(*JSONLoader)
JSONOption JSON 加载器选项
func WithJSONMetadataKeys ¶
func WithJSONMetadataKeys(keys []string) JSONOption
WithJSONMetadataKeys 设置元数据键
type MarkdownLoader ¶
type MarkdownLoader struct {
// contains filtered or unexported fields
}
MarkdownLoader Markdown 文件加载器
func NewMarkdownLoader ¶
func NewMarkdownLoader(path string, opts ...MarkdownOption) *MarkdownLoader
NewMarkdownLoader 创建 Markdown 加载器
type MarkdownOption ¶
type MarkdownOption func(*MarkdownLoader)
MarkdownOption Markdown 加载器选项
func WithExtractMetadata ¶
func WithExtractMetadata(extract bool) MarkdownOption
WithExtractMetadata 提取 front matter 元数据
type NotionConfig ¶
type NotionConfig struct {
// Token Notion 集成令牌
Token string
// PageID 页面 ID(可选)
PageID string
// DatabaseID 数据库 ID(可选)
DatabaseID string
}
NotionConfig Notion 连接器配置
type NotionConnector ¶
type NotionConnector struct {
// contains filtered or unexported fields
}
NotionConnector Notion 数据连接器
func NewNotionConnector ¶
func NewNotionConnector(config *NotionConfig) *NotionConnector
NewNotionConnector 创建 Notion 连接器
type NotionLoader ¶
type NotionLoader struct {
// contains filtered or unexported fields
}
NotionLoader Notion 文档加载器
func NewNotionLoader ¶
func NewNotionLoader(apiKey string, opts ...NotionOption) *NotionLoader
NewNotionLoader 创建 Notion 加载器
type NotionOption ¶
type NotionOption func(*NotionLoader)
NotionOption Notion 加载器选项
func WithNotionDatabaseID ¶
func WithNotionDatabaseID(id string) NotionOption
WithNotionDatabaseID 设置 Notion 数据库 ID
func WithNotionPageID ¶
func WithNotionPageID(id string) NotionOption
WithNotionPageID 设置 Notion 页面 ID
type OCREngine ¶
type OCREngine interface {
// ExtractText 从文件中提取文字
// filePath: 图片或 PDF 文件路径
// 返回提取的文字内容和可能的元数据
ExtractText(ctx context.Context, filePath string) (*OCRResult, error)
// Name 返回引擎名称
Name() string
// SupportedFormats 返回支持的文件格式
SupportedFormats() []string
}
OCREngine OCR 引擎接口 实现此接口以对接不同的 OCR 后端
type OCRLoader ¶
type OCRLoader struct {
// contains filtered or unexported fields
}
OCRLoader OCR 文档加载器 使用 OCR 引擎从图片或扫描文档中提取文字
func NewOCRLoader ¶
func NewOCRLoader(filePath string, engine OCREngine, opts ...OCRLoaderOption) *OCRLoader
NewOCRLoader 创建 OCR 加载器
type OCRLoaderOption ¶
type OCRLoaderOption func(*OCRLoader)
OCRLoaderOption OCR 加载器选项
func WithOCRMetadata ¶
func WithOCRMetadata(key string, value any) OCRLoaderOption
WithOCRMetadata 设置加载元数据
type OCRPage ¶
type OCRPage struct {
// PageNum 页码(从 1 开始)
PageNum int
// Text 该页文本
Text string
// Confidence 该页置信度
Confidence float64
}
OCRPage 单页 OCR 结果
type OCRResult ¶
type OCRResult struct {
// Text 提取的完整文本
Text string
// Pages 分页结果(PDF 场景)
Pages []OCRPage
// Language 检测到的语言
Language string
// Confidence 整体置信度 (0-1)
Confidence float64
// Metadata 额外元数据
Metadata map[string]any
}
OCRResult OCR 提取结果
type PDFDocument ¶
type PDFDocument struct {
// Pages 页面内容列表
Pages []string
// Metadata PDF 元数据
Metadata PDFMetadata
}
PDFDocument 解析后的 PDF 文档
type PDFLoader ¶
type PDFLoader struct {
// contains filtered or unexported fields
}
PDFLoader PDF 文档加载器
支持从 PDF 文件中提取文本内容。 注意:此实现为基础版本,使用简单的文本提取。 对于复杂的 PDF(包含图片、表格等),建议使用专业的 PDF 库。
func NewPDFLoader ¶
NewPDFLoader 创建 PDF 加载器
默认使用 EnhancedPDFParser 进行解析,支持压缩流、xref 表、 hex 字符串等现代 PDF 特性。如需降级到简单解析器,可使用 WithPDFParser(&SimplePDFParser{}) 选项。
func NewPDFLoaderFromReader ¶
NewPDFLoaderFromReader 从 Reader 创建 PDF 加载器
默认使用 EnhancedPDFParser 进行解析。
type PDFMetadata ¶
type PDFMetadata struct {
// Title 标题
Title string `json:"title,omitempty"`
// Author 作者
Author string `json:"author,omitempty"`
// Subject 主题
Subject string `json:"subject,omitempty"`
// Creator 创建者
Creator string `json:"creator,omitempty"`
// Producer 生产者
Producer string `json:"producer,omitempty"`
// CreationDate 创建日期
CreationDate time.Time `json:"creation_date,omitempty"`
// ModDate 修改日期
ModDate time.Time `json:"mod_date,omitempty"`
// PageCount 页数
PageCount int `json:"page_count"`
}
PDFMetadata PDF 元数据
type PDFOption ¶
type PDFOption func(*PDFLoader)
PDFOption PDF 加载器选项
func WithPDFExtractMetadata ¶
WithPDFExtractMetadata 设置是否提取元数据
type PDFParser ¶
type PDFParser interface {
// Parse 解析 PDF 并返回页面内容
Parse(ctx context.Context, r io.Reader) (*PDFDocument, error)
}
PDFParser PDF 解析器接口
定义 PDF 解析的抽象接口,允许使用不同的 PDF 库实现。 默认提供基础的文本提取实现。
type PPTXLoader ¶
type PPTXLoader struct {
// contains filtered or unexported fields
}
PPTXLoader PowerPoint 文件加载器(.pptx 格式) 提取每张幻灯片的文本内容,每张幻灯片生成一个文档
func NewPPTXLoader ¶
func NewPPTXLoader(path string, opts ...PPTXOption) *PPTXLoader
NewPPTXLoader 创建 PPTX 加载器
type ParseEngine ¶
type ParseEngine struct {
// contains filtered or unexported fields
}
ParseEngine 是可插拔的解析引擎:按 MIME 把输入路由到匹配的 Parser。
未匹配到任何解析器时使用 fallback(若设置),否则返回错误。线程安全。
func NewParseEngine ¶
func NewParseEngine(parsers ...Parser) *ParseEngine
NewParseEngine 创建解析引擎并注册初始解析器。
func (*ParseEngine) Parse ¶
func (e *ParseEngine) Parse(ctx context.Context, in ParseInput) ([]Document, error)
Parse 按 MIME 选择支持的解析器解析输入。
func (*ParseEngine) SetFallback ¶
func (e *ParseEngine) SetFallback(p Parser)
SetFallback 设置兜底解析器(所有已注册解析器都不支持该 MIME 时使用)。
type ParseInput ¶
type ParseInput struct {
// Content 待解析的原始字节
Content []byte
// MIME 内容类型(如 "application/pdf" / "image/png" / "text/markdown")
MIME string
// Filename 可选来源文件名,用于按扩展名辅助推断格式
Filename string
// Metadata 透传到产出 Document 的元数据
Metadata map[string]any
}
ParseInput 解析输入:原始字节 + 内容类型/来源提示。
type Parser ¶
type Parser interface {
// Parse 解析输入为结构化文档。
Parse(ctx context.Context, in ParseInput) ([]Document, error)
// CanParse 报告本解析器是否支持给定 MIME 类型。
CanParse(mime string) bool
}
Parser 是文档解析层抽象:把原始字节解析为一个或多个结构化 Document。
type ReaderLoader ¶
type ReaderLoader struct {
// contains filtered or unexported fields
}
ReaderLoader 从 io.Reader 加载
func NewReaderLoader ¶
func NewReaderLoader(r io.Reader, source string) *ReaderLoader
NewReaderLoader 创建 Reader 加载器
type S3Loader ¶
type S3Loader struct {
// contains filtered or unexported fields
}
S3Loader AWS S3 加载器
func NewS3Loader ¶
NewS3Loader 创建 S3 加载器
type SimplePDFParser ¶
type SimplePDFParser struct{}
SimplePDFParser 简单的 PDF 解析器
这是一个基础实现,从 PDF 二进制流中提取文本。 对于复杂的 PDF 文档,建议使用专业的 PDF 库(如 pdfcpu、unidoc 等)。
func (*SimplePDFParser) Parse ¶
func (p *SimplePDFParser) Parse(ctx context.Context, r io.Reader) (*PDFDocument, error)
Parse 解析 PDF
注意:这是一个简化的实现,主要用于演示。 实际使用中建议集成专业的 PDF 解析库。
type SlackConfig ¶
type SlackConfig struct {
// Token Slack Bot Token
Token string
// ChannelID 频道 ID
ChannelID string
// Limit 消息数量限制
Limit int
}
SlackConfig Slack 连接器配置
type SlackConnector ¶
type SlackConnector struct {
// contains filtered or unexported fields
}
SlackConnector Slack 数据连接器
func NewSlackConnector ¶
func NewSlackConnector(config *SlackConfig) *SlackConnector
NewSlackConnector 创建 Slack 连接器
type SlackLoader ¶
type SlackLoader struct {
// contains filtered or unexported fields
}
SlackLoader Slack 消息加载器
func NewSlackLoader ¶
func NewSlackLoader(token string, opts ...SlackOption) *SlackLoader
NewSlackLoader 创建 Slack 加载器
type StringLoader ¶
type StringLoader struct {
// contains filtered or unexported fields
}
StringLoader 从字符串加载
func NewStringLoader ¶
func NewStringLoader(content, source string) *StringLoader
NewStringLoader 创建字符串加载器
type TesseractEngine ¶
type TesseractEngine struct {
// contains filtered or unexported fields
}
TesseractEngine Tesseract OCR 引擎 需要系统安装 tesseract 命令行工具
func NewTesseractEngine ¶
func NewTesseractEngine(opts ...TesseractOption) *TesseractEngine
NewTesseractEngine 创建 Tesseract OCR 引擎
func (*TesseractEngine) ExtractText ¶
ExtractText 使用 Tesseract 提取文字
func (*TesseractEngine) Name ¶
func (e *TesseractEngine) Name() string
func (*TesseractEngine) SupportedFormats ¶
func (e *TesseractEngine) SupportedFormats() []string
type TesseractOption ¶
type TesseractOption func(*TesseractEngine)
TesseractOption Tesseract 选项
func WithTesseractLang ¶
func WithTesseractLang(lang string) TesseractOption
WithTesseractLang 设置识别语言
func WithTesseractPath ¶
func WithTesseractPath(path string) TesseractOption
WithTesseractPath 设置 tesseract 路径
type TextLoader ¶
type TextLoader struct {
// contains filtered or unexported fields
}
TextLoader 纯文本文件加载器
type TextParser ¶
type TextParser struct{}
TextParser 解析纯文本/Markdown 等文本类内容,直接把字节作为文档内容。
func (*TextParser) CanParse ¶
func (p *TextParser) CanParse(mime string) bool
CanParse 支持 text/* 与常见结构化文本类型。
func (*TextParser) Parse ¶
func (p *TextParser) Parse(_ context.Context, in ParseInput) ([]Document, error)
Parse 把字节包装为单个 Document。
type URLLoader ¶
type URLLoader struct {
// contains filtered or unexported fields
}
URLLoader URL 加载器
func NewURLLoader ¶
NewURLLoader 创建 URL 加载器
type VisionLLMEngine ¶
type VisionLLMEngine struct {
// contains filtered or unexported fields
}
VisionLLMEngine 基于多模态 LLM 的 OCR 引擎 使用 GPT-4V、Gemini Vision 等多模态模型提取文字
func NewVisionLLMEngine ¶
func NewVisionLLMEngine(provider llm.Provider, opts ...VisionLLMOption) *VisionLLMEngine
NewVisionLLMEngine 创建 Vision LLM OCR 引擎
func (*VisionLLMEngine) ExtractText ¶
ExtractText 使用多模态 LLM 提取文字 将图片文件读取后 base64 编码,通过 MultiContent 消息发送给 LLM
func (*VisionLLMEngine) Name ¶
func (e *VisionLLMEngine) Name() string
func (*VisionLLMEngine) SupportedFormats ¶
func (e *VisionLLMEngine) SupportedFormats() []string
type VisionLLMOption ¶
type VisionLLMOption func(*VisionLLMEngine)
VisionLLMOption Vision LLM 选项
func WithVisionSystemPrompt ¶
func WithVisionSystemPrompt(prompt string) VisionLLMOption
WithVisionSystemPrompt 设置系统提示词
type WebAPIConfig ¶
type WebAPIConfig struct {
// URL API 端点
URL string
// Method HTTP 方法
Method string
// Headers 请求头
Headers map[string]string
// Body 请求体
Body string
// JSONPath JSON 路径(提取数组)
JSONPath string
}
WebAPIConfig Web API 连接器配置
type WebAPIConnector ¶
type WebAPIConnector struct {
// contains filtered or unexported fields
}
WebAPIConnector Web API 连接器
func NewWebAPIConnector ¶
func NewWebAPIConnector(config *WebAPIConfig) *WebAPIConnector
NewWebAPIConnector 创建 Web API 连接器
type YAMLLoader ¶
type YAMLLoader struct {
// contains filtered or unexported fields
}
YAMLLoader YAML 文件加载器
func NewYAMLLoader ¶
func NewYAMLLoader(path string, opts ...YAMLOption) *YAMLLoader
NewYAMLLoader 创建 YAML 加载器