Documentation
¶
Overview ¶
Package query 提供 RAG 系统的查询增强功能
Query Enhancement 用于提升检索质量:
- QueryExpander: 查询扩展,添加相关术语
- QueryRewriter: 查询重写,改进查询表达
- MultiQueryGenerator: 多查询生成,从不同角度检索
- HyDEGenerator: 假设文档生成,基于假设答案检索
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpanderOption ¶
type ExpanderOption func(*QueryExpander)
ExpanderOption QueryExpander 选项
func WithExpanderMaxExpansions ¶
func WithExpanderMaxExpansions(max int) ExpanderOption
WithExpanderMaxExpansions 设置最大扩展数量
func WithExpanderStrategy ¶
func WithExpanderStrategy(strategy string) ExpanderOption
WithExpanderStrategy 设置扩展策略
type HyDEGenerator ¶
type HyDEGenerator struct {
// contains filtered or unexported fields
}
HyDEGenerator 假设文档嵌入生成器
HyDE (Hypothetical Document Embeddings) 是一种创新的检索策略: 1. 根据查询生成一个假设的答案文档 2. 使用假设文档的嵌入进行检索,而不是查询的嵌入 3. 因为文档-文档相似度通常高于查询-文档相似度,可以提高检索质量
func NewHyDEGenerator ¶
func NewHyDEGenerator(llm LLMProvider, opts ...HyDEOption) *HyDEGenerator
NewHyDEGenerator 创建 HyDE 生成器
func (*HyDEGenerator) GenerateMultiple ¶
func (g *HyDEGenerator) GenerateMultiple(ctx context.Context, query string, count int) ([]string, error)
GenerateMultiple 生成多个假设文档
通过生成多个假设文档并检索,可以进一步提高覆盖率
type HyDEOption ¶
type HyDEOption func(*HyDEGenerator)
HyDEOption HyDEGenerator 选项
func WithHyDETemperature ¶
func WithHyDETemperature(temp float32) HyDEOption
WithHyDETemperature 设置 LLM 温度
type LLMProvider ¶
LLMProvider 是 LLM 提供者接口(简化版)
type MultiQueryGenerator ¶
type MultiQueryGenerator struct {
// contains filtered or unexported fields
}
MultiQueryGenerator 多查询生成器
从不同角度生成多个查询,提高检索覆盖率。 这对于复杂问题特别有用,可以从多个侧面检索相关信息。
func NewMultiQueryGenerator ¶
func NewMultiQueryGenerator(llm LLMProvider, opts ...MultiQueryOption) *MultiQueryGenerator
NewMultiQueryGenerator 创建多查询生成器
type MultiQueryOption ¶
type MultiQueryOption func(*MultiQueryGenerator)
MultiQueryOption MultiQueryGenerator 选项
func WithDiversityBoost ¶
func WithDiversityBoost(boost bool) MultiQueryOption
WithDiversityBoost 设置是否增强多样性
func WithIncludeSelf ¶
func WithIncludeSelf(include bool) MultiQueryOption
WithIncludeSelf 设置是否包含原始查询
type ProcessResult ¶
type ProcessResult struct {
Original string // 原始查询
Rewritten string // 重写后的查询
Expanded []string // 扩展查询列表
MultiQueries []string // 多角度查询列表
HypotheticalDoc string // 假设文档
}
ProcessResult 查询处理结果
func (*ProcessResult) GetAllQueries ¶
func (p *ProcessResult) GetAllQueries() []string
GetAllQueries 获取所有生成的查询
返回所有查询的去重列表,用于多路检索
type ProcessorOption ¶
type ProcessorOption func(*QueryProcessor)
ProcessorOption QueryProcessor 选项
func WithMultiGen ¶
func WithMultiGen(multiGen *MultiQueryGenerator) ProcessorOption
WithMultiGen 设置多查询生成器
type QueryExpander ¶
type QueryExpander struct {
// contains filtered or unexported fields
}
QueryExpander 查询扩展器
通过添加同义词、相关术语等方式扩展查询,提高召回率。 可以使用 LLM 或词典方式进行扩展。
func NewQueryExpander ¶
func NewQueryExpander(llm LLMProvider, opts ...ExpanderOption) *QueryExpander
NewQueryExpander 创建查询扩展器
type QueryProcessor ¶
type QueryProcessor struct {
// contains filtered or unexported fields
}
QueryProcessor 查询处理器
组合多种查询增强技术,提供统一的查询处理接口
func NewQueryProcessor ¶
func NewQueryProcessor(opts ...ProcessorOption) *QueryProcessor
NewQueryProcessor 创建查询处理器
func (*QueryProcessor) Process ¶
func (p *QueryProcessor) Process(ctx context.Context, query string) (*ProcessResult, error)
Process 处理查询
根据配置应用各种查询增强技术
type QueryRewriter ¶
type QueryRewriter struct {
// contains filtered or unexported fields
}
QueryRewriter 查询重写器
使用 LLM 重写查询,使其更清晰、更具体、更易检索。
func NewQueryRewriter ¶
func NewQueryRewriter(llm LLMProvider, opts ...RewriterOption) *QueryRewriter
NewQueryRewriter 创建查询重写器