knowledge

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultEmbedderFromEnv

func DefaultEmbedderFromEnv() draftrag.Embedder

DefaultEmbedderFromEnv creates an OpenAI-compatible embedder from environment variables:

  • LLM_BASE_URL — base URL (default: http://localhost:11434/v1)
  • LLM_API_KEY — API key (default: ollama)
  • LLM_EMBED_MODEL — embedding model (default: nomic-embed-text)

Returns nil if LLM_BASE_URL is explicitly set to empty.

Types

type CSVSource

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

CSVSource reads a CSV file and indexes each row as a text document via a Pipeline.

func NewCSVSource

func NewCSVSource(path string) *CSVSource

NewCSVSource creates a CSVSource for the given file path.

func (*CSVSource) Load

func (s *CSVSource) Load(ctx context.Context, pipeline *Pipeline) error

Load parses the CSV and indexes each row through the pipeline.

func (*CSVSource) Query

func (s *CSVSource) Query(ctx context.Context, query string, limit int) ([]Chunk, error)

Query searches the pipeline for content relevant to the query.

type Chunk

type Chunk struct {
	Content  string
	Metadata map[string]any
}

Chunk represents a single piece of content returned by a KnowledgeSource query.

type JSONSource

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

JSONSource reads a JSON file and indexes its flattened content via a Pipeline.

func NewJSONSource

func NewJSONSource(path string) *JSONSource

NewJSONSource creates a JSONSource for the given file path.

func (*JSONSource) Load

func (s *JSONSource) Load(ctx context.Context, pipeline *Pipeline) error

Load parses the JSON and indexes its flattened content through the pipeline.

func (*JSONSource) Query

func (s *JSONSource) Query(ctx context.Context, query string, limit int) ([]Chunk, error)

Query searches the pipeline for content relevant to the query.

type KnowledgeSource

type KnowledgeSource interface {
	Load(ctx context.Context, pipeline *Pipeline) error
	Query(ctx context.Context, query string, limit int) ([]Chunk, error)
}

KnowledgeSource is the interface for document sources that can load content into a pipeline and answer queries against the indexed data.

type PDFSource

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

PDFSource reads a PDF file and indexes its text content via a Pipeline.

func NewPDFSource

func NewPDFSource(path string) *PDFSource

NewPDFSource creates a PDFSource for the given file path.

func (*PDFSource) Load

func (s *PDFSource) Load(ctx context.Context, pipeline *Pipeline) error

Load extracts text from the PDF and indexes it through the pipeline.

func (*PDFSource) Query

func (s *PDFSource) Query(ctx context.Context, query string, limit int) ([]Chunk, error)

Query searches the pipeline for content relevant to the query.

type Pipeline

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

Pipeline wraps a draftRAG pipeline with an in-memory store. Each agent should create one shared pipeline for all its knowledge sources.

func NewPipeline

func NewPipeline(embedder draftrag.Embedder) (*Pipeline, error)

NewPipeline creates a new Pipeline wrapper with an in-memory vector store.

func (*Pipeline) Close

func (p *Pipeline) Close() error

Close releases pipeline resources.

func (*Pipeline) Index

func (p *Pipeline) Index(ctx context.Context, docs []draftrag.Document) error

Index stores documents in the pipeline's vector store.

func (*Pipeline) Retrieve

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

Retrieve searches for documents similar to the query.

type TextFileSource

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

TextFileSource reads a .txt file and indexes its content via a Pipeline.

func NewTextFileSource

func NewTextFileSource(path string) *TextFileSource

NewTextFileSource creates a TextFileSource for the given file path.

func (*TextFileSource) Load

func (s *TextFileSource) Load(ctx context.Context, pipeline *Pipeline) error

Load reads the file and indexes its content through the pipeline.

func (*TextFileSource) Query

func (s *TextFileSource) Query(ctx context.Context, query string, limit int) ([]Chunk, error)

Query searches the pipeline for content relevant to the query.

type URLSource

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

URLSource fetches a web page and indexes its text content via a Pipeline.

func NewURLSource

func NewURLSource(url string) *URLSource

NewURLSource creates a URLSource for the given URL with a default 10s timeout.

func (*URLSource) Load

func (s *URLSource) Load(ctx context.Context, pipeline *Pipeline) error

Load fetches the URL and indexes the extracted text through the pipeline.

func (*URLSource) Query

func (s *URLSource) Query(ctx context.Context, query string, limit int) ([]Chunk, error)

Query searches the pipeline for content relevant to the query.

Jump to

Keyboard shortcuts

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