rag

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 10 Imported by: 0

README

togo

togo-framework/ai-rag

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/ai-rag

ai-rag

A full RAG (retrieval-augmented generation) capability for togo, built on the ai plugin.

togo install togo-framework/ai-rag

Ingest documents (chunk → embed via your configured AI_DRIVER → vector store), then answer questions with retrieved context.

rag, _ := rag.FromKernel(k)
rag.Ingest(ctx, "doc-1", longText)
answer, sources, _ := rag.Answer(ctx, "What is togo?", 4)

Vector store is pluggable via rag.RegisterStore (RAG_STORE, default memory with cosine similarity; add a pgvector store later). Requires the ai plugin + a provider (e.g. ai-openai).

MIT © ToGO


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

Documentation

Overview

Package rag is the togo RAG capability — built on the `ai` plugin. It ingests documents (chunk → embed via the configured AI provider → vector store) and answers questions by retrieving the most relevant chunks and generating with the LLM. The vector store is pluggable (RegisterStore); the default is in-memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterStore

func RegisterStore(name string, f StoreFactory)

RegisterStore registers a vector-store driver (e.g. a pgvector plugin's init()).

Types

type Chunk

type Chunk struct {
	ID     string    `json:"id"`
	DocID  string    `json:"doc_id"`
	Text   string    `json:"text"`
	Score  float32   `json:"score,omitempty"`
	Vector []float32 `json:"-"`
}

Chunk is a stored, embedded slice of a document.

type Service

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

Service is the kernel-bound RAG service.

func FromKernel

func FromKernel(k *togo.Kernel) (*Service, bool)

FromKernel returns the RAG service bound to the kernel.

func (*Service) Answer

func (s *Service) Answer(ctx context.Context, query string, topK int) (string, []Chunk, error)

Answer retrieves context and generates an answer with the LLM.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, docID string) error

Delete removes a document's chunks.

func (*Service) Ingest

func (s *Service) Ingest(ctx context.Context, docID, text string) (int, error)

Ingest chunks `text`, embeds each chunk, and upserts it under docID.

func (*Service) Retrieve

func (s *Service) Retrieve(ctx context.Context, query string, topK int) ([]Chunk, error)

Retrieve returns the topK chunks most relevant to the query.

type Store

type Store interface {
	Upsert(ctx context.Context, chunks []Chunk) error
	Search(ctx context.Context, vector []float32, topK int) ([]Chunk, error)
	Delete(ctx context.Context, docID string) error
}

Store is a pluggable vector store.

type StoreFactory

type StoreFactory func(k *togo.Kernel) (Store, error)

StoreFactory builds a Store from the kernel/env.

Jump to

Keyboard shortcuts

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