rag

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: 42 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)
	// Close stops the cache and releases resources
	Close() error
}

Cache defines the interface for query caching

type ComponentHealth added in v0.6.0

type ComponentHealth struct {
	Name    string            `json:"name"`
	Status  HealthStatus      `json:"status"`
	Latency time.Duration     `json:"latency"`
	Error   string            `json:"error,omitempty"`
	Details map[string]string `json:"details,omitempty"`
}

ComponentHealth represents the health of a single component

type ContextCompressor added in v0.6.0

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

ContextCompressor compresses and optimizes context for LLM input

func NewContextCompressor added in v0.6.0

func NewContextCompressor(llm llm.Client) *ContextCompressor

NewContextCompressor creates a new context compressor

func (*ContextCompressor) Compress added in v0.6.0

func (c *ContextCompressor) Compress(ctx context.Context, query string, results []core.Result) ([]core.Result, error)

Compress compresses and optimizes context

func (*ContextCompressor) WithMaxContextSize added in v0.6.0

func (c *ContextCompressor) WithMaxContextSize(size int) *ContextCompressor

WithMaxContextSize sets the maximum context size

func (*ContextCompressor) WithMinRelevanceScore added in v1.0.2

func (c *ContextCompressor) WithMinRelevanceScore(score float32) *ContextCompressor

WithMinRelevanceScore sets the minimum relevance score for filtering

func (*ContextCompressor) WithSimilarityThreshold added in v0.6.0

func (c *ContextCompressor) WithSimilarityThreshold(threshold float32) *ContextCompressor

WithSimilarityThreshold sets the similarity threshold for redundancy removal

func (*ContextCompressor) WithSummaryPrompt added in v0.6.0

func (c *ContextCompressor) WithSummaryPrompt(prompt string) *ContextCompressor

WithSummaryPrompt sets a custom summary prompt

type Conversation added in v0.6.0

type Conversation struct {
	ID        string
	Messages  []Message
	CreatedAt time.Time
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

Conversation represents a multi-turn conversation

func NewConversation added in v0.6.0

func NewConversation() *Conversation

NewConversation creates a new conversation

func (*Conversation) AddMessage added in v0.6.0

func (c *Conversation) AddMessage(role, content string)

AddMessage adds a message to the conversation

func (*Conversation) GetContext added in v0.6.0

func (c *Conversation) GetContext(maxMessages int) string

GetContext returns the conversation context as a string

func (*Conversation) GetRecentMessages added in v0.6.0

func (c *Conversation) GetRecentMessages(max int) []Message

GetRecentMessages gets the most recent messages

type ConversationManager added in v0.6.0

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

ConversationManager manages multiple conversations

func NewConversationManager added in v0.6.0

func NewConversationManager() *ConversationManager

NewConversationManager creates a new conversation manager

func (*ConversationManager) CreateConversation added in v0.6.0

func (cm *ConversationManager) CreateConversation() *Conversation

CreateConversation creates a new conversation

func (*ConversationManager) DeleteConversation added in v0.6.0

func (cm *ConversationManager) DeleteConversation(id string)

DeleteConversation deletes a conversation

func (*ConversationManager) GetConversation added in v0.6.0

func (cm *ConversationManager) GetConversation(id string) *Conversation

GetConversation gets a conversation by ID

func (*ConversationManager) ListConversations added in v0.6.0

func (cm *ConversationManager) ListConversations() []*Conversation

ListConversations lists all conversations

func (*ConversationManager) UpdateConversation added in v0.6.0

func (cm *ConversationManager) UpdateConversation(conv *Conversation)

UpdateConversation updates a conversation

type ConversationOptions added in v0.6.0

type ConversationOptions struct {
	ConversationID string
	MaxHistory     int
	PromptTemplate string
}

ConversationOptions configures conversation behavior

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 (Retrieval-Augmented Generation) engine

Engine is the central component of the GoRAG framework that orchestrates the entire RAG process: document parsing, embedding generation, vector storage, retrieval, and LLM interaction.

Key features: - Concurrent directory indexing with 10 workers - Automatic parser selection by file extension - Streaming large file support (100M+) - Hybrid retrieval (vector + keyword search) - LLM-based reranking - Custom prompt templates - Multi-hop RAG for complex questions - Agentic RAG with autonomous retrieval

Example:

engine, err := rag.New(
    rag.WithVectorStore(memory.NewStore()),
    rag.WithEmbedder(embedderInstance),
    rag.WithLLM(llmInstance),
)

// Index entire directory with 10 concurrent workers
err = engine.IndexDirectory(ctx, "./documents")

// Query with custom prompt
resp, err := engine.Query(ctx, "What is Go?", rag.QueryOptions{
    TopK: 5,
    PromptTemplate: "Answer based on context: {context}\nQuestion: {question}",
})

func New

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

New creates a new RAG engine with the provided options

This function creates a new Engine instance and applies the provided options. It automatically loads all built-in parsers for 9 file formats: - Text (.txt, .md) - PDF (.pdf) - DOCX (.docx) - HTML (.html) - JSON (.json) - YAML (.yaml, .yml) - Excel (.xlsx) - PPT (.pptx) - Image (.jpg, .jpeg, .png)

Required options: - WithVectorStore: Vector storage backend - WithEmbedder: Embedding model provider - WithLLM: LLM client for generation

Optional options: - WithParser: Default parser for unknown file types - WithParsers: Custom parsers for specific file formats - WithRetriever: Custom hybrid retriever - WithReranker: Custom LLM reranker - WithLogger: Custom logger - WithMetrics: Custom metrics collector - WithTracer: Custom tracer - WithPluginDirectory: Directory to load plugins from

Returns: - *Engine: Newly created RAG engine - error: Error if required components are missing

Example:

// Create embedding provider
embedderInstance, err := embedder.New(embedder.Config{APIKey: apiKey})
if err != nil {
	log.Fatal(err)
}

// Create LLM client
llmInstance, err := llm.New(llm.Config{APIKey: apiKey})
if err != nil {
	log.Fatal(err)
}

// Create RAG engine
engine, err := rag.New(
	rag.WithVectorStore(memory.NewStore()),
	rag.WithEmbedder(embedderInstance),
	rag.WithLLM(llmInstance),
	rag.WithPluginDirectory("./plugins"),
)
if err != nil {
	log.Fatal(err)
}

// Engine is ready with all 9 built-in parsers loaded and plugins from directory

func (*Engine) AddParser added in v0.6.0

func (e *Engine) AddParser(format string, p parser.Parser)

AddParser adds a parser for a specific format

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) AsyncIndexDirectory added in v0.6.0

func (e *Engine) AsyncIndexDirectory(ctx context.Context, directoryPath string) error

AsyncIndexDirectory indexes all files in a directory recursively 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) Debug added in v0.6.0

func (e *Engine) Debug(ctx context.Context, message string, fields map[string]interface{})

Debug logs debug level message

func (*Engine) Error added in v0.6.0

func (e *Engine) Error(ctx context.Context, message string, err error, fields map[string]interface{})

Error logs error level message

func (*Engine) Extract added in v0.6.0

func (e *Engine) Extract(ctx context.Context) (observability.Span, bool)

Extract extracts span from context

func (*Engine) Get added in v0.6.0

func (e *Engine) Get(ctx context.Context, key string) (*query.Response, bool)

Get retrieves a cached response

func (*Engine) Index

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

Index adds documents to the RAG engine

func (*Engine) IndexDirectory added in v0.6.0

func (e *Engine) IndexDirectory(ctx context.Context, directoryPath string) error

IndexDirectory indexes all files in a directory recursively with concurrent workers

func (*Engine) Info added in v0.6.0

func (e *Engine) Info(ctx context.Context, message string, fields map[string]interface{})

Info logs info level message

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

func (*Engine) QueryWithConversation added in v0.6.0

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

QueryWithConversation performs a RAG query with conversation history

func (*Engine) RecordErrorCount added in v0.6.0

func (e *Engine) RecordErrorCount(ctx context.Context, errorType string)

RecordErrorCount records error metrics

func (*Engine) RecordIndexCount added in v0.6.0

func (e *Engine) RecordIndexCount(ctx context.Context, status string)

RecordIndexCount records index count metrics

func (*Engine) RecordIndexLatency added in v0.6.0

func (e *Engine) RecordIndexLatency(ctx context.Context, duration time.Duration)

RecordIndexLatency records index latency metrics

func (*Engine) RecordIndexedDocuments added in v1.0.1

func (e *Engine) RecordIndexedDocuments(ctx context.Context, count int)

RecordIndexedDocuments records the number of indexed documents

func (*Engine) RecordIndexingDocuments added in v1.0.1

func (e *Engine) RecordIndexingDocuments(ctx context.Context, count int)

RecordIndexingDocuments records the number of documents being indexed

func (*Engine) RecordMonitoredDocuments added in v1.0.1

func (e *Engine) RecordMonitoredDocuments(ctx context.Context, count int)

RecordMonitoredDocuments records the number of monitored documents

func (*Engine) RecordQueryCount added in v0.6.0

func (e *Engine) RecordQueryCount(ctx context.Context, status string)

RecordQueryCount records query count metrics

func (*Engine) RecordQueryLatency added in v0.6.0

func (e *Engine) RecordQueryLatency(ctx context.Context, duration time.Duration)

RecordQueryLatency records query latency metrics

func (*Engine) RecordSystemMetrics added in v1.0.1

func (e *Engine) RecordSystemMetrics(ctx context.Context, cpuUsage float64, memoryUsage float64)

RecordSystemMetrics records system metrics (CPU, memory)

func (*Engine) ReindexFile added in v1.0.1

func (e *Engine) ReindexFile(ctx context.Context, filePath string, sourceType string) error

ReindexFile reindexes a file by first deleting existing chunks and then reindexing

func (*Engine) Set added in v0.6.0

func (e *Engine) Set(ctx context.Context, key string, value *query.Response, expiration time.Duration)

Set stores a response in cache

func (*Engine) SetDefaultParser added in v0.6.0

func (e *Engine) SetDefaultParser(p parser.Parser)

SetDefaultParser sets the default parser for unknown formats

func (*Engine) StartSpan added in v0.6.0

func (e *Engine) StartSpan(ctx context.Context, name string) (context.Context, observability.Span)

StartSpan starts a new trace span

func (*Engine) StartWatch added in v1.0.1

func (e *Engine) StartWatch(targetIndexDir string) error

StartWatch starts watching a directory for changes and automatically indexes files

Parameters: - targetIndexDir: Directory to watch for changes

Returns: - error: Error if watching fails

This method will: 1. First perform an initial indexing of the directory 2. Then start watching for file changes 3. Automatically reindex files when they change 4. Use asynchronous indexing to avoid blocking

func (*Engine) StartWatchAsync added in v1.0.1

func (e *Engine) StartWatchAsync(targetIndexDir string) (context.CancelFunc, error)

StartWatchAsync starts watching a directory for changes asynchronously Returns a cancel function to stop watching.

Parameters: - targetIndexDir: Directory to watch for changes

Returns: - context.CancelFunc: Call this to stop watching - error: Error if starting the watch fails

func (*Engine) StartWatchWithContext added in v1.0.2

func (e *Engine) StartWatchWithContext(ctx context.Context, targetIndexDir string) error

StartWatchWithContext watches a directory for changes with context cancellation support

func (*Engine) Warn added in v0.6.0

func (e *Engine) Warn(ctx context.Context, message string, fields map[string]interface{})

Warn logs warn level message

type HealthChecker added in v0.6.0

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

HealthChecker performs health checks on engine components

func NewHealthChecker added in v0.6.0

func NewHealthChecker(engine *Engine) *HealthChecker

NewHealthChecker creates a new health checker

func (*HealthChecker) Check added in v0.6.0

func (h *HealthChecker) Check(ctx context.Context) *HealthReport

Check performs a full health check

func (*HealthChecker) WithTimeout added in v0.6.0

func (h *HealthChecker) WithTimeout(timeout time.Duration) *HealthChecker

WithTimeout sets the health check timeout

func (*HealthChecker) WithVersion added in v0.6.0

func (h *HealthChecker) WithVersion(version string) *HealthChecker

WithVersion sets the version string

type HealthReport added in v0.6.0

type HealthReport struct {
	Status     HealthStatus      `json:"status"`
	Components []ComponentHealth `json:"components"`
	Timestamp  time.Time         `json:"timestamp"`
	Uptime     time.Duration     `json:"uptime"`
	Version    string            `json:"version"`
}

HealthReport represents the overall health of the RAG engine

type HealthStatus added in v0.6.0

type HealthStatus string

HealthStatus represents the health status of a component

const (
	// HealthStatusUp indicates the component is healthy
	HealthStatusUp HealthStatus = "up"
	// HealthStatusDown indicates the component is unhealthy
	HealthStatusDown HealthStatus = "down"
	// HealthStatusDegraded indicates the component is partially healthy
	HealthStatusDegraded HealthStatus = "degraded"
)

type HyDE added in v0.6.0

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

HyDE (Hypothetical Document Embeddings) enhances query embeddings by generating a hypothetical document https://arxiv.org/abs/2212.10496

func NewHyDE added in v0.6.0

func NewHyDE(llm llm.Client) *HyDE

NewHyDE creates a new HyDE instance

func (*HyDE) EnhanceQuery added in v0.6.0

func (h *HyDE) EnhanceQuery(ctx context.Context, query string) (string, error)

EnhanceQuery enhances the query using HyDE

func (*HyDE) WithPromptTemplate added in v0.6.0

func (h *HyDE) WithPromptTemplate(template string) *HyDE

WithPromptTemplate sets a custom prompt template for HyDE

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) Close added in v1.0.2

func (c *MemoryCache) Close() error

Close stops the cache cleanup goroutine and releases resources

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 Message added in v0.6.0

type Message struct {
	ID        string
	Role      string // "user" or "assistant"
	Content   string
	Timestamp time.Time
}

Message represents a message in a conversation

type Option

type Option func(*Engine)

Option configures the Engine

func WithAgenticRAG added in v0.6.0

func WithAgenticRAG(agentic *retrieval.AgenticRAG) Option

WithAgenticRAG sets the agentic RAG component

func WithBatchProcessor added in v1.0.1

func WithBatchProcessor(batchSize, maxWorkers int, rateLimit time.Duration) Option

WithBatchProcessor optimizes embedding batch processing

Parameters: - batchSize: Size of each batch - maxWorkers: Maximum number of concurrent workers - rateLimit: Minimum time between requests

Returns: - Option: Engine option

func WithCache

func WithCache(c Cache) Option

WithCache sets the query cache

func WithCircuitBreaker added in v1.0.1

func WithCircuitBreaker(maxFailures int, timeout time.Duration, halfOpenMax int) Option

WithCircuitBreaker adds circuit breaker protection to the LLM client

Parameters: - maxFailures: Maximum number of failures before opening the circuit - timeout: Time to wait before attempting to close the circuit - halfOpenMax: Maximum number of requests in half-open state

Returns: - Option: Engine option

func WithConnectionPool added in v1.0.1

func WithConnectionPool(maxConns, idleConns int, idleTimeout time.Duration) Option

WithConnectionPool wraps the vector store with a connection pool

Parameters: - maxConns: Maximum number of connections - idleConns: Maximum number of idle connections - idleTimeout: Idle connection timeout

Returns: - Option: Engine option

func WithContextCompressor added in v0.6.0

func WithContextCompressor(c *ContextCompressor) Option

WithContextCompressor sets the context compressor for optimizing context

func WithConversationManager added in v0.6.0

func WithConversationManager(cm *ConversationManager) Option

WithConversationManager sets the conversation manager

func WithEmbedder

func WithEmbedder(e embedding.Provider) Option

WithEmbedder sets the embedding provider

func WithHyDE added in v0.6.0

func WithHyDE(h *HyDE) Option

WithHyDE sets the HyDE instance for query enhancement

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 WithMultiHopRAG added in v0.6.0

func WithMultiHopRAG(multiHop *retrieval.MultiHopRAG) Option

WithMultiHopRAG sets the multi-hop RAG component

func WithParser

func WithParser(p parser.Parser) Option

WithParser sets the default document parser

func WithParsers added in v0.6.0

func WithParsers(parsers map[string]parser.Parser) Option

WithParsers sets multiple parsers for different formats

func WithPluginConfig added in v1.0.1

func WithPluginConfig(config map[string]interface{}) Option

WithPluginConfig sets the plugin configuration for the engine

func WithPluginDirectory added in v1.0.1

func WithPluginDirectory(directory string) Option

WithPluginDirectory sets the plugin directory for the engine

func WithQueryCache added in v1.0.1

func WithQueryCache(ttl time.Duration, maxSize int) Option

WithQueryCache enables query result caching

Parameters: - ttl: Cache time-to-live

Returns: - Option: Engine option

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

type PluginOptions struct {
	// PluginDirectory is the directory to load plugins from
	PluginDirectory string
	// PluginConfig is the configuration for plugins
	PluginConfig map[string]interface{}
}

PluginOptions holds plugin-related configuration

This struct defines options for plugin loading and management.

type Progress added in v0.6.0

type Progress struct {
	ID             string         `json:"id"`
	Status         ProgressStatus `json:"status"`
	TotalFiles     int            `json:"total_files"`
	ProcessedFiles int            `json:"processed_files"`
	FailedFiles    []string       `json:"failed_files"`
	CurrentFile    string         `json:"current_file"`
	StartTime      time.Time      `json:"start_time"`
	EndTime        *time.Time     `json:"end_time,omitempty"`
	Error          string         `json:"error,omitempty"`
	// contains filtered or unexported fields
}

Progress represents the progress of an indexing operation

func NewProgress added in v0.6.0

func NewProgress(id string, totalFiles int) *Progress

NewProgress creates a new progress tracker

func (*Progress) AddFailedFile added in v0.6.0

func (p *Progress) AddFailedFile(file string)

AddFailedFile adds a failed file to the list

func (*Progress) Cancel added in v0.6.0

func (p *Progress) Cancel()

Cancel marks the progress as cancelled

func (*Progress) Complete added in v0.6.0

func (p *Progress) Complete()

Complete marks the progress as completed

func (*Progress) Duration added in v0.6.0

func (p *Progress) Duration() time.Duration

Duration returns the elapsed time

func (*Progress) Fail added in v0.6.0

func (p *Progress) Fail(err error)

Fail marks the progress as failed

func (*Progress) IncrementProcessed added in v0.6.0

func (p *Progress) IncrementProcessed()

IncrementProcessed increments the processed files count

func (*Progress) IsComplete added in v0.6.0

func (p *Progress) IsComplete() bool

IsComplete returns true if the operation is complete

func (*Progress) Percentage added in v0.6.0

func (p *Progress) Percentage() float64

Percentage returns the completion percentage

func (*Progress) SetCurrentFile added in v0.6.0

func (p *Progress) SetCurrentFile(file string)

SetCurrentFile sets the current file being processed

func (*Progress) Snapshot added in v0.6.0

func (p *Progress) Snapshot() ProgressSnapshot

Snapshot returns a copy of the current progress state

func (*Progress) Start added in v0.6.0

func (p *Progress) Start()

Start marks the progress as running

type ProgressChannel added in v0.6.0

type ProgressChannel struct {
	Progress *Progress
	Updates  chan ProgressSnapshot
	// contains filtered or unexported fields
}

ProgressChannel wraps a progress instance with a channel for updates

func NewProgressChannel added in v0.6.0

func NewProgressChannel(ctx context.Context, progress *Progress) *ProgressChannel

NewProgressChannel creates a new progress channel

func (*ProgressChannel) Close added in v0.6.0

func (pc *ProgressChannel) Close()

Close closes the progress channel

func (*ProgressChannel) Send added in v0.6.0

func (pc *ProgressChannel) Send()

Send sends a progress update

func (*ProgressChannel) Watch added in v0.6.0

func (pc *ProgressChannel) Watch() <-chan ProgressSnapshot

Watch returns a channel that receives progress updates

type ProgressSnapshot added in v0.6.0

type ProgressSnapshot struct {
	ID             string         `json:"id"`
	Status         ProgressStatus `json:"status"`
	TotalFiles     int            `json:"total_files"`
	ProcessedFiles int            `json:"processed_files"`
	FailedFiles    []string       `json:"failed_files"`
	CurrentFile    string         `json:"current_file"`
	StartTime      time.Time      `json:"start_time"`
	EndTime        *time.Time     `json:"end_time,omitempty"`
	Error          string         `json:"error,omitempty"`
}

ProgressSnapshot is a read-only copy of Progress state (safe to copy by value)

type ProgressStatus added in v0.6.0

type ProgressStatus string

ProgressStatus represents the status of an operation

const (
	// ProgressStatusPending indicates the operation is pending
	ProgressStatusPending ProgressStatus = "pending"
	// ProgressStatusRunning indicates the operation is running
	ProgressStatusRunning ProgressStatus = "running"
	// ProgressStatusCompleted indicates the operation completed successfully
	ProgressStatusCompleted ProgressStatus = "completed"
	// ProgressStatusFailed indicates the operation failed
	ProgressStatusFailed ProgressStatus = "failed"
	// ProgressStatusCancelled indicates the operation was cancelled
	ProgressStatusCancelled ProgressStatus = "cancelled"
)

type ProgressTracker added in v0.6.0

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

ProgressTracker manages multiple progress instances

func NewProgressTracker added in v0.6.0

func NewProgressTracker() *ProgressTracker

NewProgressTracker creates a new progress tracker

func (*ProgressTracker) Cleanup added in v0.6.0

func (t *ProgressTracker) Cleanup(maxAge time.Duration) int

Cleanup removes completed progress instances older than the specified duration

func (*ProgressTracker) Create added in v0.6.0

func (t *ProgressTracker) Create(id string, totalFiles int) *Progress

Create creates a new progress instance

func (*ProgressTracker) Delete added in v0.6.0

func (t *ProgressTracker) Delete(id string)

Delete removes a progress instance

func (*ProgressTracker) Get added in v0.6.0

func (t *ProgressTracker) Get(id string) (*Progress, bool)

Get retrieves a progress instance by ID

func (*ProgressTracker) List added in v0.6.0

func (t *ProgressTracker) List() []ProgressSnapshot

List returns all progress instances

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
}

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 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 = core.Source

Source represents a document source for indexing

Source defines the input for the indexing process. It can represent: 1. A text string (Content field) 2. A file path (Path field) 3. A reader interface (Reader field)

The Type field specifies the document format (e.g., ".txt", ".pdf", ".docx") and is used to select the appropriate parser.

Example:

// Index a text string
source1 := core.Source{
    Type:    "text",
    Content: "Go is an open source programming language...",
}

// Index a file
source2 := core.Source{
    Type: ".pdf",
    Path: "/path/to/document.pdf",
}

type StreamResponse

type StreamResponse struct {
	Chunk   string
	Sources []core.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