retrieval

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentDecision added in v0.6.0

type AgentDecision struct {
	Action     string  `json:"action"`     // "retrieve" or "finish"
	Query      string  `json:"query"`      // Search query if action is "retrieve"
	Reasoning  string  `json:"reasoning"`  // Agent's reasoning for this decision
	Confidence float64 `json:"confidence"` // Confidence score (0.0-1.0)
}

AgentDecision represents a structured decision from the agent

func ParseAgentDecision added in v0.6.0

func ParseAgentDecision(response string) (*AgentDecision, error)

ParseAgentDecision parses agent decision from LLM response It supports both JSON format and fallback text parsing

func (*AgentDecision) Validate added in v0.6.0

func (d *AgentDecision) Validate() error

Validate validates the agent decision

type AgentReflection added in v0.6.0

type AgentReflection struct {
	HasEnoughInfo     bool     `json:"has_enough_info"`    // Whether agent has enough information
	MissingInfo       []string `json:"missing_info"`       // List of missing information
	RecommendedQuery  string   `json:"recommended_query"`  // Recommended next query
	RecommendedAction string   `json:"recommended_action"` // Recommended action
	Confidence        float64  `json:"confidence"`         // Confidence in the reflection
}

AgentReflection represents agent's reflection on the retrieval process

func (*AgentReflection) Validate added in v0.6.0

func (r *AgentReflection) Validate() error

Validate validates the agent reflection

type AgentState added in v0.6.0

type AgentState struct {
	Task           string
	RetrievedInfo  []core.Result
	Reasoning      []string
	IterationCount int
	Completed      bool
	FinalAnswer    string
}

AgentState represents the current state of the agent

type AgenticRAG added in v0.6.0

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

AgenticRAG implements agentic retrieval with autonomous decision-making

Agentic RAG is the most advanced form of RAG where the retrieval process is embedded in an autonomous agent's reasoning loop. The agent can: 1. Decide if retrieval is needed based on the task 2. Generate appropriate search queries 3. Evaluate the quality of retrieval results 4. Decide if additional retrieval is needed 5. Iteratively refine the retrieval process

Example use case: "Write a report comparing the latest AI trends from 2024" The agent would: 1. Analyze the task and determine it needs current information 2. Generate a search query for "2024 AI trends" 3. Evaluate the results and identify gaps 4. Generate more specific queries for different AI domains 5. Continue until it has comprehensive information 6. Synthesize the information into a report

func NewAgenticRAG added in v0.6.0

func NewAgenticRAG(
	llm llm.Client,
	embedder embedding.Provider,
	vectorStore vectorstore.Store,
) *AgenticRAG

NewAgenticRAG creates a new agentic RAG instance

func (*AgenticRAG) Query added in v0.6.0

func (a *AgenticRAG) Query(ctx context.Context, task string, instructions string, promptTemplate string) (*Response, error)

Query performs an agentic RAG query

func (*AgenticRAG) Search added in v0.6.0

func (a *AgenticRAG) Search(ctx context.Context, task string, topK int) ([]core.Result, error)

Search performs agentic retrieval

func (*AgenticRAG) WithMaxIterations added in v0.6.0

func (a *AgenticRAG) WithMaxIterations(iterations int) *AgenticRAG

WithMaxIterations sets the maximum number of iterations

func (*AgenticRAG) WithReflectPrompt added in v0.6.0

func (a *AgenticRAG) WithReflectPrompt(prompt string) *AgenticRAG

WithReflectPrompt sets a custom reflection prompt

func (*AgenticRAG) WithTaskPrompt added in v0.6.0

func (a *AgenticRAG) WithTaskPrompt(prompt string) *AgenticRAG

WithTaskPrompt sets a custom task prompt

type AnalysisResult added in v0.6.0

type AnalysisResult struct {
	NeedsMoreInformation bool
	MissingInformation   string
	Confidence           float32
}

AnalysisResult represents the result of analyzing search results

type HybridRetriever

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

HybridRetriever implements hybrid search (vector + keyword)

func NewHybridRetriever

func NewHybridRetriever(vectorStore vectorstore.Store, keywordStore KeywordStore, alpha float32) *HybridRetriever

NewHybridRetriever creates a new hybrid retriever

func (*HybridRetriever) KeywordSearch

func (r *HybridRetriever) KeywordSearch(ctx context.Context, query string, topK int) ([]core.Result, error)

KeywordSearch performs keyword-only search

func (*HybridRetriever) Search

func (r *HybridRetriever) Search(ctx context.Context, query string, embedding []float32, topK int) ([]core.Result, error)

Search performs hybrid search

type KeywordStore

type KeywordStore interface {
	Search(ctx context.Context, query string, topK int) ([]core.Result, error)
}

KeywordStore defines the interface for keyword search

type MultiHopRAG added in v0.6.0

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

MultiHopRAG implements multi-hop retrieval for complex questions

Multi-hop RAG is designed to handle complex questions that require information from multiple sources. It performs an initial retrieval, analyzes the results, and generates follow-up queries to gather all necessary information.

Example use case: "Compare Apple and Microsoft's latest AI investments" The system would: 1. Initial retrieval about AI investments 2. Analyze results and identify that we need specific information about Apple 3. Generate a follow-up query for Apple's AI investments 4. Repeat for Microsoft 5. Combine all information to answer the original question

func NewMultiHopRAG added in v0.6.0

func NewMultiHopRAG(
	llm llm.Client,
	embedder embedding.Provider,
	vectorStore vectorstore.Store,
) *MultiHopRAG

NewMultiHopRAG creates a new multi-hop RAG instance

func (*MultiHopRAG) Query added in v0.6.0

func (m *MultiHopRAG) Query(ctx context.Context, question string, maxHops int, promptTemplate string) (*Response, error)

Query performs a multi-hop RAG query

func (*MultiHopRAG) Search added in v0.6.0

func (m *MultiHopRAG) Search(ctx context.Context, query string, topK int) ([]core.Result, error)

Search performs multi-hop retrieval

func (*MultiHopRAG) WithAnalysisPrompt added in v0.6.0

func (m *MultiHopRAG) WithAnalysisPrompt(prompt string) *MultiHopRAG

WithAnalysisPrompt sets a custom analysis prompt

func (*MultiHopRAG) WithMaxHops added in v0.6.0

func (m *MultiHopRAG) WithMaxHops(hops int) *MultiHopRAG

WithMaxHops sets the maximum number of hops

func (*MultiHopRAG) WithQueryPrompt added in v0.6.0

func (m *MultiHopRAG) WithQueryPrompt(prompt string) *MultiHopRAG

WithQueryPrompt sets a custom follow-up query prompt

type RAGFusion added in v0.6.0

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

RAGFusion implements the RAG-Fusion retrieval strategy https://arxiv.org/abs/2309.00812

func NewRAGFusion added in v0.6.0

func NewRAGFusion(
	llm llm.Client,
	embedder embedding.Provider,
	vectorStore vectorstore.Store,
	keywordStore KeywordStore,
) *RAGFusion

NewRAGFusion creates a new RAG-Fusion instance

func (*RAGFusion) Search added in v0.6.0

func (rf *RAGFusion) Search(ctx context.Context, originalQuery string, topK int) ([]core.Result, error)

Search performs RAG-Fusion search

func (*RAGFusion) WithFusionAlpha added in v0.6.0

func (rf *RAGFusion) WithFusionAlpha(alpha float32) *RAGFusion

WithFusionAlpha sets the alpha parameter for reciprocal rank fusion

func (*RAGFusion) WithNumQueries added in v0.6.0

func (rf *RAGFusion) WithNumQueries(num int) *RAGFusion

WithNumQueries sets the number of query variations to generate

func (*RAGFusion) WithQueryPrompt added in v0.6.0

func (rf *RAGFusion) WithQueryPrompt(prompt string) *RAGFusion

WithQueryPrompt sets a custom query generation prompt

type Reranker

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

Reranker implements result reranking using LLM

func NewReranker

func NewReranker(llm llm.Client, topK int) *Reranker

NewReranker creates a new reranker

func (*Reranker) Rerank

func (r *Reranker) Rerank(ctx context.Context, query string, results []core.Result) ([]core.Result, error)

Rerank reranks search results based on relevance to the query

func (*Reranker) WithPrompt

func (r *Reranker) WithPrompt(prompt string) *Reranker

WithPrompt sets the rerank prompt

type Response added in v0.6.0

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

Response represents a RAG query response

Jump to

Keyboard shortcuts

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