rag

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 13 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 retrieves a cached response for the given key
	Get(ctx context.Context, key string) (*Response, bool)
	// Set stores a response in the cache with the given key and expiration
	Set(ctx context.Context, key string, value *Response, expiration time.Duration)
	// Delete removes a cached response for the given key
	Delete(ctx context.Context, key string)
	// Clear removes all cached responses
	Clear(ctx context.Context)
}

Cache defines the interface for query caching

type DefaultRouter

type DefaultRouter struct{}

DefaultRouter implements a simple default router

func NewDefaultRouter

func NewDefaultRouter() *DefaultRouter

NewDefaultRouter creates a new default router

func (*DefaultRouter) Route

func (r *DefaultRouter) Route(ctx context.Context, query string) (RouteResult, error)

Route determines the appropriate routing for a given query

type Engine

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

Engine represents the RAG engine

func New

func New(opts ...Option) (*Engine, error)

New creates a new RAG engine

func (*Engine) AsyncBatchIndex

func (e *Engine) AsyncBatchIndex(ctx context.Context, sources []Source) error

AsyncBatchIndex adds multiple documents to the RAG engine asynchronously

func (*Engine) AsyncIndex

func (e *Engine) AsyncIndex(ctx context.Context, source Source) error

AsyncIndex adds documents to the RAG engine asynchronously

func (*Engine) BatchIndex

func (e *Engine) BatchIndex(ctx context.Context, sources []Source) error

BatchIndex adds multiple documents to the RAG engine in batch

func (*Engine) BatchQuery

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

BatchQuery performs multiple RAG queries in batch

func (*Engine) Index

func (e *Engine) Index(ctx context.Context, source Source) error

Index adds documents to the RAG engine

func (*Engine) Query

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

Query performs a RAG query

func (*Engine) QueryStream

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

QueryStream performs a streaming RAG query

type MemoryCache

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

MemoryCache implements a simple in-memory cache

func NewMemoryCache

func NewMemoryCache(expiry time.Duration) *MemoryCache

NewMemoryCache creates a new in-memory cache

func (*MemoryCache) Clear

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

Clear removes all cached responses

func (*MemoryCache) Delete

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

Delete removes a cached response for the given key

func (*MemoryCache) Get

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

Get retrieves a cached response for the given key

func (*MemoryCache) Set

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

Set stores a response in the cache with the given key and expiration

type Option

type Option func(*Engine)

Option configures the Engine

func WithCache

func WithCache(c Cache) Option

WithCache sets the query cache

func WithEmbedder

func WithEmbedder(e embedding.Provider) Option

WithEmbedder sets the embedding provider

func WithLLM

func WithLLM(l llm.Client) Option

WithLLM sets the LLM client

func WithLogger

func WithLogger(l observability.Logger) Option

WithLogger sets the logger

func WithMetrics

func WithMetrics(m observability.Metrics) Option

WithMetrics sets the metrics collector

func WithParser

func WithParser(p parser.Parser) Option

WithParser sets the document parser

func WithReranker

func WithReranker(r *retrieval.Reranker) Option

WithReranker sets the reranker

func WithRetriever

func WithRetriever(r *retrieval.HybridRetriever) Option

WithRetriever sets the hybrid retriever

func WithRouter

func WithRouter(r Router) Option

WithRouter sets the query router

func WithTracer

func WithTracer(t observability.Tracer) Option

WithTracer sets the tracer

func WithVectorStore

func WithVectorStore(s vectorstore.Store) Option

WithVectorStore sets the vector store

type QueryOptions

type QueryOptions struct {
	TopK           int
	PromptTemplate string
	Stream         bool
}

QueryOptions configures query behavior

type Response

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

Response represents the RAG query response

type RouteResult

type RouteResult struct {
	// Type indicates the type of route (e.g., "vector", "keyword", "hybrid")
	Type string
	// Params contains additional parameters for the route
	Params map[string]interface{}
}

RouteResult represents the result of routing a query

type Router

type Router interface {
	// Route determines the appropriate routing for a given query
	Route(ctx context.Context, query string) (RouteResult, error)
}

Router defines the interface for query routing

type Source

type Source struct {
	Type    string
	Path    string
	Content string
	Reader  interface{}
}

Source represents a document source

type StreamResponse

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

StreamResponse represents a streaming RAG query response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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