queryengine

package
v0.80.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(config *Config) error

ValidateConfig 验证配置有效性.

Types

type Config

type Config struct {
	// 时间范围配置
	TimeRange TimeRangeConfig `json:"timeRange" yaml:"timeRange"`

	// 查询限制配置
	QueryLimits QueryLimitsConfig `json:"queryLimits" yaml:"queryLimits"`

	// 检索配置
	Retrieval RetrievalConfig `json:"retrieval" yaml:"retrieval"`

	// 评分配置
	Scoring ScoringConfig `json:"scoring" yaml:"scoring"`
}

P2 改进:配置化,将硬编码提取为可配置项.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置.

type ErrInvalidConfig

type ErrInvalidConfig struct {
	Value interface{}
	Field string
}

ErrInvalidConfig 配置无效错误.

func (ErrInvalidConfig) Error

func (e ErrInvalidConfig) Error() string

type QueryLimitsConfig

type QueryLimitsConfig struct {
	// 最大查询长度(字符数)
	MaxQueryLength int `json:"maxQueryLength" yaml:"maxQueryLength"`
	// 最大结果数量
	MaxResults int `json:"maxResults" yaml:"maxResults"`
	// 最小分数阈值
	MinScore float32 `json:"minScore" yaml:"minScore"`
}

QueryLimitsConfig 查询限制配置.

type QueryRouter

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

P2 改进:添加配置支持和并发控制.

func NewQueryRouter

func NewQueryRouter() *QueryRouter

NewQueryRouter 创建新的查询路由器.

func NewQueryRouterWithConfig

func NewQueryRouterWithConfig(config *Config) *QueryRouter

P2 改进:支持自定义配置.

func (*QueryRouter) ApplyConfig

func (r *QueryRouter) ApplyConfig(config *Config)

P2 改进:支持运行时配置更新.

func (*QueryRouter) CheckMostlyProperNouns

func (r *QueryRouter) CheckMostlyProperNouns(query string) bool

CheckMostlyProperNouns 判断查询是否主要由专有名词组成.

func (*QueryRouter) GetConfig

func (r *QueryRouter) GetConfig() *Config

GetConfig 获取当前配置(线程安全).

func (*QueryRouter) GetStrategyDescription

func (r *QueryRouter) GetStrategyDescription(strategy string) string

GetStrategyDescription 获取策略描述.

func (*QueryRouter) Route

func (r *QueryRouter) Route(_ context.Context, query string, userTimezone *time.Location) *RouteDecision

Route executes routing decision with user timezone support. Fast rule matching (95% scenarios, <10ms). If userTimezone is nil, defaults to UTC.

type RetrievalConfig

type RetrievalConfig struct {
	// 向量检索限制
	VectorLimit int `json:"vectorLimit" yaml:"vectorLimit"`
	// 混合检索限制
	HybridLimit int `json:"hybridLimit" yaml:"hybridLimit"`
	// 扩展检索限制
	ExpandLimit int `json:"expandLimit" yaml:"expandLimit"`
	// 是否启用 Reranker
	EnableReranker bool `json:"enableReranker" yaml:"enableReranker"`
	// 最大文档长度(字符数)
	MaxDocLength int `json:"maxDocLength" yaml:"maxDocLength"`
}

RetrievalConfig 检索配置.

type RouteDecision

type RouteDecision struct {
	TimeRange         *TimeRange
	Strategy          string
	SemanticQuery     string
	Confidence        float32
	ScheduleQueryMode ScheduleQueryMode
	NeedsReranker     bool
}

RouteDecision 路由决策.

type ScheduleQueryMode

type ScheduleQueryMode int32

ScheduleQueryMode 日程查询模式.

const (
	AutoQueryMode     ScheduleQueryMode = 0 // 自动选择
	StandardQueryMode ScheduleQueryMode = 1 // 标准模式:返回范围内有任何部分的日程
	StrictQueryMode   ScheduleQueryMode = 2 // 严格模式:只返回完全在范围内的日程
)

type ScoringConfig

type ScoringConfig struct {
	// BM25 权重范围
	BM25WeightMin float32 `json:"bm25WeightMin" yaml:"bm25WeightMin"`
	BM25WeightMax float32 `json:"bm25WeightMax" yaml:"bm25WeightMax"`
	// 语义权重
	SemanticWeight float32 `json:"semanticWeight" yaml:"semanticWeight"`
	// 高质量阈值
	HighQualityThreshold float32 `json:"highQualityThreshold" yaml:"highQualityThreshold"`
	// 中等质量阈值
	MediumQualityThreshold float32 `json:"mediumQualityThreshold" yaml:"mediumQualityThreshold"`
	// 分数差距阈值(用于判断是否需要重排)
	ScoreGapThreshold float32 `json:"scoreGapThreshold" yaml:"scoreGapThreshold"`
	// 最小重排结果数
	MinRerankResults int `json:"minRerankResults" yaml:"minRerankResults"`
}

ScoringConfig 评分配置.

type TimeRange

type TimeRange struct {
	Start time.Time
	End   time.Time
	Label string
}

TimeRange 时间范围.

func (*TimeRange) Contains

func (tr *TimeRange) Contains(t time.Time) bool

Contains 检查给定时间是否在范围内.

func (*TimeRange) Duration

func (tr *TimeRange) Duration() time.Duration

Duration 获取时间范围持续时间.

func (*TimeRange) ValidateTimeRange

func (tr *TimeRange) ValidateTimeRange() bool

P2 改进:使用配置值.

type TimeRangeConfig

type TimeRangeConfig struct {
	Timezone      string `json:"timezone" yaml:"timezone"`
	MaxFutureDays int    `json:"maxFutureDays" yaml:"maxFutureDays"`
	MaxRangeDays  int    `json:"maxRangeDays" yaml:"maxRangeDays"`
}

TimeRangeConfig 时间范围配置.

Jump to

Keyboard shortcuts

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