query

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCacheKey added in v1.0.1

func GenerateCacheKey(question string, opts QueryOptions) string

GenerateCacheKey generates a cache key from a question and options

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 CacheStats added in v1.0.1

type CacheStats struct {
	Size          int
	MaxSize       int
	Expired       int
	TotalAccesses int
}

CacheStats represents cache statistics

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 MemoryCache added in v1.0.1

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

MemoryCache implements the Cache interface for query results

func NewMemoryCache added in v1.0.1

func NewMemoryCache(defaultTTL time.Duration) *MemoryCache

NewMemoryCache creates a new in-memory cache

func NewMemoryCacheWithSize added in v1.0.1

func NewMemoryCacheWithSize(defaultTTL time.Duration, maxSize int) *MemoryCache

NewMemoryCacheWithSize creates a new in-memory cache with size limit

func (*MemoryCache) Clear added in v1.0.1

func (c *MemoryCache) Clear(ctx context.Context)

Clear clears all entries from the cache

func (*MemoryCache) Delete added in v1.0.1

func (c *MemoryCache) Delete(ctx context.Context, key string)

Delete removes a value from the cache

func (*MemoryCache) Get added in v1.0.1

func (c *MemoryCache) Get(ctx context.Context, key string) (*Response, bool)

Get retrieves a value from the cache Implements the Cache interface

func (*MemoryCache) Set added in v1.0.1

func (c *MemoryCache) Set(ctx context.Context, key string, value *Response, ttl time.Duration)

Set stores a value in the cache

func (*MemoryCache) Size added in v1.0.1

func (c *MemoryCache) Size() int

Size returns the number of entries in the cache

func (*MemoryCache) Stats added in v1.0.1

func (c *MemoryCache) Stats() CacheStats

Stats returns cache statistics

type Metrics

type Metrics interface {
	RecordErrorCount(ctx context.Context, errorType string)
	RecordQueryLatency(ctx context.Context, duration time.Duration)
	RecordQueryCount(ctx context.Context, status string)
	RecordIndexedDocuments(ctx context.Context, count int)
	RecordIndexingDocuments(ctx context.Context, count int)
	RecordMonitoredDocuments(ctx context.Context, count int)
	RecordSystemMetrics(ctx context.Context, cpuUsage float64, memoryUsage float64)
}

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