gorag

package module
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 28 Imported by: 0

README

🦖 GoRAG

The Expert-Grade, High-Performance Modular RAG Framework for Go

Go Report Card Go Reference Go Version Documentation

English | 中文文档


GoRAG is a production-ready Retrieval-Augmented Generation (RAG) framework built for high-scale AI engineering. It features a three-layer architecture that serves developers at all skill levels.

🏗️ Three-Layer Architecture

graph TB
    subgraph Pattern层["Pattern Layer (Application)"]
        P1["NativeRAG<br/>Vector Retrieval"]
        P2["GraphRAG<br/>Knowledge Graph"]
    end
    
    subgraph Pipeline层["Pipeline Layer (Assembly)"]
        I["Indexer"]
        R["Retriever"]
        D["Repository"]
    end
    
    subgraph Step层["Step Layer (Function)"]
        S1["Independent Modules<br/>Rewrite/Chunk/Embed..."]
    end
    
    Pattern层 --> Pipeline层
    Pipeline层 --> Step层
Layer Who Uses Responsibility
Pattern Application Developers Choose RAG mode, configure Options
Pipeline Advanced Developers Assemble Indexer/Retriever/Repository
Step Framework Developers Extend independent modules

✨ Key Features

  • 🚀 Performance First: Concurrent workers and streaming parsers with O(1) memory efficiency
  • 🏗️ Pipeline-Based Architecture: Every step is explicit, traceable, and pluggable
  • 🧠 Three-Phase Enhancement: Query enhancement → Retrieval → Result enhancement
  • 🕸️ Advanced GraphRAG: Native support for Neo4j, SQLite, and BoltDB
  • 🔭 Built-in Observability: Comprehensive distributed tracing
  • 📦 Zero Dependencies: Pure Go implementation with auto-download models

🚀 Quick Start

NativeRAG (Vector Retrieval)

Best for document QA and semantic search:

import "github.com/DotNetAge/gorag/pkg/pattern"

// Create a NativeRAG with auto-configuration
rag, _ := pattern.NativeRAG("my-app",
    pattern.WithBGE("bge-small-zh-v1.5"),
)

// Index documents
rag.IndexDirectory(ctx, "./docs", true)

// Retrieve
results, _ := rag.Retrieve(ctx, []string{"What is GoRAG?"}, 5)

GraphRAG (Knowledge Graph)

Best for complex relationship reasoning:

rag, _ := pattern.GraphRAG("knowledge-graph",
    pattern.WithBGE("bge-small-zh-v1.5"),
    pattern.WithNeoGraph("neo4j://localhost:7687", "neo4j", "password", "neo4j"),
)

// Add nodes and edges
rag.AddNode(ctx, &core.Node{ID: "person-1", Type: "Person", ...})
rag.AddEdge(ctx, &core.Edge{Source: "person-1", Target: "company-1", ...})

// Query neighbors
neighbors, edges, _ := rag.GetNeighbors(ctx, "person-1", 1, 10)

📚 Documentation

Getting Started

Advanced Topics

Step Layer


🔭 Built-in Observability

idx, _ := indexer.DefaultAdvancedIndexer(
    indexer.WithZapLogger("./logs/rag.log", 100, 30, 7, true),
    indexer.WithPrometheusMetrics(":8080"),
    indexer.WithOpenTelemetryTracer(ctx, "jaeger:4317", "RAG"),
)

⚡ Technical Standards

  • Go 1.24+: Latest language features
  • Zero-CGO SQLite: Painless cross-compilation
  • Clean Architecture: Strict separation of interfaces and implementations
  • Modular Steps: Reuse steps in any custom pipeline

🤝 Contributing

We aim to build the most robust AI infrastructure for the Go ecosystem.

📄 License

GoRAG is licensed under the MIT License.

Documentation

Index

Constants

View Source
const (
	GORAG_MODEL_PATH = "GORAG_MODEL_PATH"
	GORAG_BASE_URL   = "GORAG_BASE_URL"
	GORAG_API_KEY    = "GORAG_API_KEY"
	GORAG_AUTH_TOKEN = "GORAG_AUTH_TOKEN"
	GORAG_MODEL      = "GORAG_MODEL"
)

Variables

This section is empty.

Functions

func CheckModel added in v1.1.10

func CheckModel(modelId, modelFile string) (string, error)

CheckModel 检查模型文件是否存在,如果不存在则从 HuggingFace 下载 modelId: HuggingFace 模型 ID,如 "Xenova/chinese-clip-vit-base-patch16" modelFile: 模型文件路径,如 "onnx/model.onnx" 返回模型文件的完整路径

func New added in v1.1.10

func New(dataDir string, opts ...RAGOption) (core.Indexer, error)

New 创建新的 RAG 索引实例 如果数据目录不存在则创建,生成配置文件和子目录结构

func Open added in v1.1.10

func Open(dataDir string) (core.Indexer, error)

Open 打开已存在的 RAG 索引实例 从数据目录读取配置文件并恢复索引器

Types

type Config added in v1.1.10

type Config struct {
	Name      string `yaml:"name"`       // RAG 名称
	Type      string `yaml:"type"`       // 索引器类型:hybrid, semantic, graph
	ModelFile string `yaml:"model_file"` // 向量化模型
}

type HybridIndexer added in v1.1.10

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

HybridIndexer 混合索引器 将多个索引器(语义、BM25等)组合,实现查询结果融合与重排

func NewHybridIndexer added in v1.1.10

func NewHybridIndexer(
	logger logging.Logger,
	vectorStore core.VectorStore,
	graphStore core.GraphStore,
	docStore core.FullTextStore,
	client chat.Client,
	embedder core.Embedder,
	opts ...HybridOption) (*HybridIndexer, error)

NewHybridIndexer 创建混合索引器

func (*HybridIndexer) Add added in v1.1.10

func (h *HybridIndexer) Add(ctx context.Context, content string) ([]*core.Chunk, error)

Add 将内容添加到所有索引器

func (*HybridIndexer) AddFile added in v1.1.10

func (h *HybridIndexer) AddFile(ctx context.Context, filePath string) ([]*core.Chunk, error)

AddFile 将文件添加到所有索引器

func (*HybridIndexer) AddIndexer added in v1.1.10

func (h *HybridIndexer) AddIndexer(indexer core.Indexer, weight float32)

AddIndexer 向混合索引器添加索引器

func (*HybridIndexer) Close added in v1.1.10

func (h *HybridIndexer) Close(ctx context.Context) error

Close 关闭所有索引器持有的资源

func (*HybridIndexer) GetIndexer added in v1.1.10

func (h *HybridIndexer) GetIndexer(name string) (core.Indexer, bool)

GetIndexer 获取索引器

func (*HybridIndexer) GetWeights added in v1.1.10

func (h *HybridIndexer) GetWeights() map[string]float32

func (*HybridIndexer) IndexChunk added in v1.1.10

func (h *HybridIndexer) IndexChunk(ctx context.Context, chunk *core.Chunk) error

IndexChunk indexes a single pre-generated chunk across all indexers

func (*HybridIndexer) IndexChunks added in v1.1.10

func (h *HybridIndexer) IndexChunks(ctx context.Context, chunks []*core.Chunk) error

IndexChunks indexes multiple pre-generated chunks across all indexers

func (*HybridIndexer) ListIndexers added in v1.1.10

func (h *HybridIndexer) ListIndexers() []string

ListIndexers 列出所有索引器名称(按字母排序,保证确定性输出)

func (*HybridIndexer) Name added in v1.1.10

func (h *HybridIndexer) Name() string

Name 返回索引器名称

func (*HybridIndexer) NewQuery added in v1.1.10

func (h *HybridIndexer) NewQuery(terms string) core.Query

func (*HybridIndexer) Remove added in v1.1.10

func (h *HybridIndexer) Remove(ctx context.Context, chunkID string) error

Remove 从所有索引器移除

func (*HybridIndexer) RemoveIndexer added in v1.1.10

func (h *HybridIndexer) RemoveIndexer(name string)

RemoveIndexer 移除索引器

func (*HybridIndexer) Search added in v1.1.10

func (h *HybridIndexer) Search(ctx context.Context, query core.Query) ([]core.Hit, error)

Search 从所有索引器搜索并融合结果

func (*HybridIndexer) Type added in v1.1.10

func (h *HybridIndexer) Type() string

Type 返回索引器类型

type HybridOption added in v1.1.10

type HybridOption func(*HybridIndexer)

HybridOption HybridIndexer 的可选配置

func WithCacheStore added in v1.1.10

func WithCacheStore(cache core.CacheStore) HybridOption

WithCacheStore 设置图索引器的缓存(依赖注入 core.CacheStore 接口)

func WithCacheStoreOrNil added in v1.1.10

func WithCacheStoreOrNil(dataDir string) HybridOption

WithCacheStoreOrNil 创建缓存并返回 HybridOption; 缓存创建失败时返回 nil option,不阻断索引器创建

type IndexingService added in v1.1.10

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

IndexingService RAG 索引服务 支持批量索引和文件监控两种模式

func NewRAGService added in v1.1.10

func NewRAGService(dataDir string, opts ...ServiceOption) (*IndexingService, error)

NewRAGService 创建 RAG 索引服务 dataDir: RAG 数据目录(必须) opts: 可选配置项

func (*IndexingService) Index added in v1.1.10

func (s *IndexingService) Index() error

Index 执行批量索引 对监控目录下的全部文件进行全量索引

func (*IndexingService) Reindex added in v1.1.10

func (s *IndexingService) Reindex(ctx context.Context, file string) error

Reindex 重新索引指定文件(公开 API) 删除旧索引数据后重新分块并索引,适用于文件内容变更后的更新场景

func (*IndexingService) Stop added in v1.1.10

func (s *IndexingService) Stop() error

Stop 停止服务

func (*IndexingService) Watch added in v1.1.10

func (s *IndexingService) Watch() error

Watch 启动文件监控服务 当文件发生变更时自动进行索引 首次启动时会执行全量索引

type RAGOption

type RAGOption func(*Config)

func WithIndexType added in v1.1.10

func WithIndexType(indexType string) RAGOption

func WithModelFile added in v1.1.10

func WithModelFile(modelFile string) RAGOption

func WithName added in v1.1.4

func WithName(name string) RAGOption

type ServiceOption added in v1.1.10

type ServiceOption func(*IndexingService)

ServiceOption 服务配置选项

func WithLogger added in v1.1.10

func WithLogger(logger logging.Logger) ServiceOption

WithLogger 设置日志记录器

func WithWatchs added in v1.1.10

func WithWatchs(dirs ...string) ServiceOption

WithWatchs 设置监控目录

func WithWorkerCount added in v1.1.10

func WithWorkerCount(count int) ServiceOption

WithWorkerCount 设置 worker pool 大小

Directories

Path Synopsis
Package entity defines the core entities for the goRAG framework.
Package entity defines the core entities for the goRAG framework.
Package logging provides structured logging capabilities for the goRAG framework.
Package logging provides structured logging capabilities for the goRAG framework.
store

Jump to

Keyboard shortcuts

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