agentic

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package agentic 提供代理式检索增强生成 (Agentic RAG) 实现

Agentic RAG 通过智能代理进行多步推理和检索:

  • 分析查询,生成检索计划
  • 执行多步检索和推理
  • 动态调整计划
  • 支持多个检索源

使用示例:

arag := agentic.New(
    llmProvider,
    agentic.WithRetriever("knowledge", knowledgeRetriever),
    agentic.WithRetriever("web", webRetriever),
    agentic.WithMaxSteps(5),
)
response, err := arag.Query(ctx, "复杂问题")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgenticRAG

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

AgenticRAG 代理式检索增强生成

工作流程:

  1. 分析查询,生成检索计划
  2. 执行计划中的每个步骤
  3. 根据步骤结果动态调整
  4. 综合所有结果生成回答

func New

func New(provider llm.Provider, opts ...Option) *AgenticRAG

New 创建 AgenticRAG 实例

func (*AgenticRAG) Query

func (a *AgenticRAG) Query(ctx context.Context, query string) (*Response, error)

Query 执行 Agentic RAG 查询

type Option

type Option func(*AgenticRAG)

Option AgenticRAG 配置选项

func WithMaxSteps

func WithMaxSteps(n int) Option

WithMaxSteps 设置最大步骤数 默认值: 5

func WithRetriever

func WithRetriever(name string, retriever rag.Retriever) Option

WithRetriever 添加检索器

func WithTopK

func WithTopK(k int) Option

WithTopK 设置每次检索的文档数 默认值: 3

type Plan

type Plan struct {
	// Query 原始查询
	Query string `json:"query"`

	// Steps 计划步骤
	Steps []Step `json:"steps"`

	// Analysis 查询分析
	Analysis string `json:"analysis,omitempty"`
}

Plan 执行计划

type Response

type Response struct {
	// Content 生成的回答
	Content string `json:"content"`

	// Sources 使用的来源文档
	Sources []rag.Document `json:"sources,omitempty"`

	// ExecutedSteps 执行的步骤
	ExecutedSteps []Step `json:"executed_steps"`

	// TotalSteps 总步骤数
	TotalSteps int `json:"total_steps"`
}

Response Agentic RAG 的响应

type Step

type Step struct {
	// Type 步骤类型
	Type StepType `json:"type"`

	// Query 检索查询(对于检索步骤)
	Query string `json:"query,omitempty"`

	// Source 检索源(对于检索步骤)
	Source string `json:"source,omitempty"`

	// Reasoning 推理内容(对于推理步骤)
	Reasoning string `json:"reasoning,omitempty"`

	// Results 步骤结果
	Results []rag.Document `json:"results,omitempty"`

	// Conclusion 步骤结论
	Conclusion string `json:"conclusion,omitempty"`
}

Step 执行步骤

type StepType

type StepType string

StepType 步骤类型

const (
	// StepTypeRetrieve 检索步骤
	StepTypeRetrieve StepType = "retrieve"
	// StepTypeReason 推理步骤
	StepTypeReason StepType = "reason"
	// StepTypeSynthesize 综合步骤
	StepTypeSynthesize StepType = "synthesize"
)

Jump to

Keyboard shortcuts

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