extractor

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package extractor 提供 RAG 系统的文档元数据提取器

MetadataExtractor 从文档中自动提取结构化元数据,如:

  • 标题、摘要
  • 关键词、主题
  • 日期、作者
  • 实体信息

参考 LlamaIndex 的 MetadataExtractor 设计

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompositeExtractor

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

CompositeExtractor 复合提取器 组合多个提取器

func NewCompositeExtractor

func NewCompositeExtractor(extractors ...MetadataExtractor) *CompositeExtractor

NewCompositeExtractor 创建复合提取器

func (*CompositeExtractor) AddExtractor

func (e *CompositeExtractor) AddExtractor(extractor MetadataExtractor)

AddExtractor 添加提取器

func (*CompositeExtractor) Extract

func (e *CompositeExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 使用所有提取器提取元数据

func (*CompositeExtractor) Name

func (e *CompositeExtractor) Name() string

Name 返回提取器名称

type EntityExtractor

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

EntityExtractor 实体提取器

func NewEntityExtractor

func NewEntityExtractor(llmComplete func(ctx context.Context, prompt string) (string, error), opts ...EntityExtractorOption) *EntityExtractor

NewEntityExtractor 创建实体提取器

func (*EntityExtractor) Extract

func (e *EntityExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 提取实体

func (*EntityExtractor) Name

func (e *EntityExtractor) Name() string

Name 返回提取器名称

type EntityExtractorOption

type EntityExtractorOption func(*EntityExtractor)

EntityExtractorOption 配置选项

func WithEntityTypes

func WithEntityTypes(types ...string) EntityExtractorOption

WithEntityTypes 设置要提取的实体类型

type KeywordExtractor

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

KeywordExtractor 关键词提取器

func NewKeywordExtractor

func NewKeywordExtractor(opts ...KeywordExtractorOption) *KeywordExtractor

NewKeywordExtractor 创建关键词提取器

func (*KeywordExtractor) Extract

func (e *KeywordExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 提取关键词

func (*KeywordExtractor) Name

func (e *KeywordExtractor) Name() string

Name 返回提取器名称

type KeywordExtractorOption

type KeywordExtractorOption func(*KeywordExtractor)

KeywordExtractorOption 配置选项

func WithKeywordLLM

func WithKeywordLLM(fn func(ctx context.Context, prompt string) (string, error)) KeywordExtractorOption

WithKeywordLLM 设置 LLM

func WithMaxKeywords

func WithMaxKeywords(n int) KeywordExtractorOption

WithMaxKeywords 设置最大关键词数量

func WithSimpleExtraction

func WithSimpleExtraction(enabled bool) KeywordExtractorOption

WithSimpleExtraction 使用简单提取(基于词频)

type MetadataExtractor

type MetadataExtractor interface {
	// Extract 从文档中提取元数据
	Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

	// Name 返回提取器名称
	Name() string
}

MetadataExtractor 元数据提取器接口

type QuestionsExtractor

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

QuestionsExtractor 问题生成器 生成可以由文档回答的问题,用于提高检索质量

func NewQuestionsExtractor

func NewQuestionsExtractor(llmComplete func(ctx context.Context, prompt string) (string, error), opts ...QuestionsExtractorOption) *QuestionsExtractor

NewQuestionsExtractor 创建问题生成器

func (*QuestionsExtractor) Extract

func (e *QuestionsExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 生成问题

func (*QuestionsExtractor) Name

func (e *QuestionsExtractor) Name() string

Name 返回提取器名称

type QuestionsExtractorOption

type QuestionsExtractorOption func(*QuestionsExtractor)

QuestionsExtractorOption 配置选项

func WithNumQuestions

func WithNumQuestions(n int) QuestionsExtractorOption

WithNumQuestions 设置问题数量

type SimpleExtractor

type SimpleExtractor struct{}

SimpleExtractor 简单元数据提取器 不依赖 LLM,从文档中提取基本信息

func NewSimpleExtractor

func NewSimpleExtractor() *SimpleExtractor

NewSimpleExtractor 创建简单提取器

func (*SimpleExtractor) Extract

func (e *SimpleExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 提取基本元数据

func (*SimpleExtractor) Name

func (e *SimpleExtractor) Name() string

Name 返回提取器名称

type SummaryExtractor

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

SummaryExtractor 摘要提取器 使用 LLM 生成文档摘要

func NewSummaryExtractor

func NewSummaryExtractor(llmComplete func(ctx context.Context, prompt string) (string, error), opts ...SummaryExtractorOption) *SummaryExtractor

NewSummaryExtractor 创建摘要提取器

参数:

  • llmComplete: LLM 完成函数
  • opts: 配置选项

func (*SummaryExtractor) Extract

func (e *SummaryExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 提取摘要

func (*SummaryExtractor) Name

func (e *SummaryExtractor) Name() string

Name 返回提取器名称

type SummaryExtractorOption

type SummaryExtractorOption func(*SummaryExtractor)

SummaryExtractorOption 配置选项

func WithSummaryMaxLen

func WithSummaryMaxLen(length int) SummaryExtractorOption

WithSummaryMaxLen 设置最大摘要长度

func WithSummaryPrompt

func WithSummaryPrompt(prompt string) SummaryExtractorOption

WithSummaryPrompt 设置自定义提示词

type TitleExtractor

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

TitleExtractor 标题提取器 从文档内容中提取或生成标题

func NewTitleExtractor

func NewTitleExtractor(opts ...TitleExtractorOption) *TitleExtractor

NewTitleExtractor 创建标题提取器

func (*TitleExtractor) Extract

func (e *TitleExtractor) Extract(ctx context.Context, doc rag.Document) (map[string]any, error)

Extract 提取标题

func (*TitleExtractor) Name

func (e *TitleExtractor) Name() string

Name 返回提取器名称

type TitleExtractorOption

type TitleExtractorOption func(*TitleExtractor)

TitleExtractorOption 配置选项

func WithMaxTitleLen

func WithMaxTitleLen(length int) TitleExtractorOption

WithMaxTitleLen 设置最大标题长度

func WithTitleFromFirstLine

func WithTitleFromFirstLine(enabled bool) TitleExtractorOption

WithTitleFromFirstLine 设置从首行提取标题

func WithTitleLLM

func WithTitleLLM(fn func(ctx context.Context, prompt string) (string, error)) TitleExtractorOption

WithTitleLLM 设置 LLM 用于生成标题

Jump to

Keyboard shortcuts

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