query

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (*Response, bool)
	Set(ctx context.Context, key string, value *Response, expiration time.Duration)
}

Cache defines the interface for query result caching

type ContextCompressor

type ContextCompressor interface {
	Compress(ctx context.Context, question string, results []core.Result) ([]core.Result, error)
}

ContextCompressor defines the interface for context compression

type Embedder

type Embedder interface {
	Embed(ctx context.Context, texts []string) ([][]float32, error)
}

Embedder defines the interface for embedding providers

type HyDE

type HyDE interface {
	EnhanceQuery(ctx context.Context, question string) (string, error)
}

HyDE defines the interface for Hypothetical Document Embeddings

type Logger

type Logger interface {
	Info(ctx context.Context, message string, fields map[string]interface{})
	Debug(ctx context.Context, message string, fields map[string]interface{})
	Error(ctx context.Context, message string, err error, fields map[string]interface{})
	Warn(ctx context.Context, message string, fields map[string]interface{})
}

Logger defines the interface for logging

type Metrics

type Metrics interface {
	RecordErrorCount(ctx context.Context, errorType string)
	RecordQueryLatency(ctx context.Context, duration time.Duration)
	RecordQueryCount(ctx context.Context, status string)
}

Metrics defines the interface for metrics collection

type QueryHandler

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

QueryHandler handles RAG query operations

func NewQueryHandler

func NewQueryHandler(
	embedder Embedder,
	store vectorstore.Store,
	llm llm.Client,
	retriever *retrieval.HybridRetriever,
	reranker *retrieval.Reranker,
	hydration HyDE,
	compressor ContextCompressor,
	multiHopRAG *retrieval.MultiHopRAG,
	agenticRAG *retrieval.AgenticRAG,
	cache Cache,
	router Router,
	metrics Metrics,
	logger Logger,
	tracer Tracer,
) *QueryHandler

NewQueryHandler creates a new query handler

func (*QueryHandler) BatchQuery

func (q *QueryHandler) BatchQuery(ctx context.Context, questions []string, opts QueryOptions) ([]*Response, error)

BatchQuery performs multiple RAG queries in batch

func (*QueryHandler) Query

func (q *QueryHandler) Query(ctx context.Context, question string, opts QueryOptions) (*Response, error)

Query performs a RAG query

func (*QueryHandler) QueryStream

func (q *QueryHandler) QueryStream(ctx context.Context, question string, opts QueryOptions) (<-chan StreamResponse, error)

QueryStream performs a streaming RAG query

type QueryOptions

type QueryOptions struct {
	TopK              int
	PromptTemplate    string
	Stream            bool
	UseMultiHopRAG    bool   // Use multi-hop RAG for complex questions
	UseAgenticRAG     bool   // Use agentic RAG with autonomous retrieval
	MaxHops           int    // Maximum number of hops for multi-hop RAG
	AgentInstructions string // Instructions for agentic RAG
	RerankMultiplier  int    // Multiplier for topK when fetching candidates for reranking (default: 2)
}

QueryOptions configures query behavior

type Response

type Response struct {
	Answer  string
	Sources []core.Result
}

Response represents the RAG query response

type RouteResult

type RouteResult struct {
	Type   string
	Params map[string]interface{}
}

RouteResult represents the result of query routing

type Router

type Router interface {
	Route(ctx context.Context, question string) (RouteResult, error)
}

Router defines the interface for query routing

type StreamResponse

type StreamResponse struct {
	Chunk   string
	Sources []core.Result
	Done    bool
	Error   error
}

StreamResponse represents a streaming RAG query response

type Tracer

type Tracer interface {
	StartSpan(ctx context.Context, name string) (context.Context, observability.Span)
	Extract(ctx context.Context) (observability.Span, bool)
}

Tracer defines the interface for tracing

Jump to

Keyboard shortcuts

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