knowledge

package
v0.0.0-...-4c54577 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalKnowledgeBus = &EventBus{}

GlobalKnowledgeBus is the default event bus for knowledge events.

Functions

This section is empty.

Types

type CSVSource

type CSVSource struct {
	FilePaths []string
}

CSVSource provides knowledge from .csv files.

func (*CSVSource) Identifier

func (s *CSVSource) Identifier() string

func (*CSVSource) Load

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

func (*CSVSource) Type

func (s *CSVSource) Type() string

type Config

type Config struct {
	ResultsLimit   int     `yaml:"results_limit" json:"results_limit"`     // Default: 3
	ScoreThreshold float64 `yaml:"score_threshold" json:"score_threshold"` // Default: 0.35
	CollectionName string  `yaml:"collection_name" json:"collection_name"` // Default: "knowledge"
}

Config controls knowledge retrieval behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default knowledge configuration.

type Event

type Event struct {
	Type      EventType              `json:"type"`
	Timestamp time.Time              `json:"timestamp"`
	Query     string                 `json:"query,omitempty"`
	Source    string                 `json:"source,omitempty"`
	Results   int                    `json:"results,omitempty"`
	Error     string                 `json:"error,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

Event represents a knowledge lifecycle event.

type EventBus

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

EventBus distributes knowledge events to registered handlers.

func (*EventBus) Publish

func (b *EventBus) Publish(event Event)

Publish sends an event to all registered handlers.

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(handler EventHandler)

Subscribe registers a handler to receive knowledge events.

type EventHandler

type EventHandler func(Event)

EventHandler is a callback function for knowledge events.

type EventType

type EventType string

EventType identifies the kind of knowledge event.

const (
	EventRetrievalStarted   EventType = "knowledge.retrieval.started"
	EventRetrievalCompleted EventType = "knowledge.retrieval.completed"
	EventQueryStarted       EventType = "knowledge.query.started"
	EventQueryCompleted     EventType = "knowledge.query.completed"
	EventQueryFailed        EventType = "knowledge.query.failed"
	EventSearchFailed       EventType = "knowledge.search.failed"
	EventIngestionStarted   EventType = "knowledge.ingestion.started"
	EventIngestionCompleted EventType = "knowledge.ingestion.completed"
)

type IngestionEngine

type IngestionEngine struct {
	Store           memory.Store
	LLM             llm.Client // Used purely for the vector Translation
	Splitter        *TokenSplitter
	ThroughputDelay time.Duration // Mandatory delay between chunks
}

IngestionEngine takes physical files, chunks them, and saves them into the Agent's Vector Memory.

func (*IngestionEngine) IngestCSV

func (ie *IngestionEngine) IngestCSV(ctx context.Context, filePath string) error

IngestCSV reads a CSV file and converts each row to a text chunk. First row is treated as headers; each subsequent row becomes "header1: value1, header2: value2, ..." for semantic embedding.

func (*IngestionEngine) IngestDirectory

func (ie *IngestionEngine) IngestDirectory(ctx context.Context, dirPath string) error

IngestDirectory reads all supported files in a directory and loads them. Supported: .md, .txt, .csv, .json, .jsonl

func (*IngestionEngine) IngestDocx

func (ie *IngestionEngine) IngestDocx(ctx context.Context, filePath string) error

IngestDocx extracts plain text natively from a Word Document's zipped XML structure.

func (*IngestionEngine) IngestFile

func (ie *IngestionEngine) IngestFile(ctx context.Context, filePath string) error

IngestFile detects format by extension and ingests accordingly.

func (*IngestionEngine) IngestJSON

func (ie *IngestionEngine) IngestJSON(ctx context.Context, filePath string) error

IngestJSON reads a JSON file. If the root is an array, each element becomes a chunk. If it's an object, the entire document is chunked as text.

func (*IngestionEngine) IngestJSONL

func (ie *IngestionEngine) IngestJSONL(ctx context.Context, filePath string) error

IngestJSONL reads a JSON Lines file (one JSON object per line).

func (*IngestionEngine) IngestPDF

func (ie *IngestionEngine) IngestPDF(ctx context.Context, filePath string) error

IngestPDF extracts plain text from a PDF document using ledongthuc/pdf.

func (*IngestionEngine) IngestRawText

func (ie *IngestionEngine) IngestRawText(ctx context.Context, source, text string) error

IngestRawText ingests a raw text string directly (no file needed). Useful for programmatic ingestion of API responses, database dumps, etc.

func (*IngestionEngine) IngestText

func (ie *IngestionEngine) IngestText(ctx context.Context, filePath string) error

IngestText reads a plain text file, chunks it, embeds, and stores.

func (*IngestionEngine) IngestURL

func (ie *IngestionEngine) IngestURL(ctx context.Context, url string) error

IngestURL fetches content from a URL, extracts text, and ingests it. For HTML pages, basic tag stripping is applied. For JSON endpoints, the response is parsed as JSON.

type JSONSource

type JSONSource struct {
	FilePaths []string
}

JSONSource provides knowledge from .json files.

func (*JSONSource) Identifier

func (s *JSONSource) Identifier() string

func (*JSONSource) Load

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

func (*JSONSource) Type

func (s *JSONSource) Type() string

type KnowledgeSearchTool

type KnowledgeSearchTool struct {
	Store memory.Store
	LLM   llm.Client
}

KnowledgeSearchTool allows agents to search specifically within the ingested knowledge base.

func NewKnowledgeSearchTool

func NewKnowledgeSearchTool(store memory.Store, llm llm.Client) *KnowledgeSearchTool

func (*KnowledgeSearchTool) Description

func (t *KnowledgeSearchTool) Description() string

func (*KnowledgeSearchTool) Execute

func (t *KnowledgeSearchTool) Execute(ctx context.Context, input map[string]interface{}) (string, error)

func (*KnowledgeSearchTool) Name

func (t *KnowledgeSearchTool) Name() string

func (*KnowledgeSearchTool) RequiresReview

func (t *KnowledgeSearchTool) RequiresReview() bool

type PDFSource

type PDFSource struct {
	FilePaths []string
}

PDFSource provides knowledge from .pdf files.

func (*PDFSource) Identifier

func (s *PDFSource) Identifier() string

func (*PDFSource) Load

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

func (*PDFSource) Type

func (s *PDFSource) Type() string

type Source

type Source interface {
	// Type returns the source type identifier.
	Type() string
	// Load returns the raw content to be ingested.
	Load(ctx context.Context) (string, error)
	// Identifier returns a unique key for this source (for dedup).
	Identifier() string
}

Source is the interface that all knowledge sources must implement.

type StringSource

type StringSource struct {
	Content string
	Label   string
}

StringSource provides knowledge from raw string content.

func (*StringSource) Identifier

func (s *StringSource) Identifier() string

func (*StringSource) Load

func (s *StringSource) Load(ctx context.Context) (string, error)

func (*StringSource) Type

func (s *StringSource) Type() string

type TextFileSource

type TextFileSource struct {
	FilePaths []string
}

TextFileSource provides knowledge from .txt files.

func (*TextFileSource) Identifier

func (s *TextFileSource) Identifier() string

func (*TextFileSource) Load

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

func (*TextFileSource) Type

func (s *TextFileSource) Type() string

type TokenSplitter

type TokenSplitter struct {
	ChunkSize    int
	ChunkOverlap int
}

TokenSplitter breaks massive document strings into manageable chunks so they can be securely embedded and loaded into Vector context windows.

func NewTokenSplitter

func NewTokenSplitter(chunkSize, chunkOverlap int) *TokenSplitter

func (*TokenSplitter) SplitText

func (ts *TokenSplitter) SplitText(text string) []string

SplitText assumes 1 word ≈ 1 token for basic Go architectural extraction.

type URLSource

type URLSource struct {
	URLs []string
}

URLSource provides knowledge from web pages.

func (*URLSource) Identifier

func (s *URLSource) Identifier() string

func (*URLSource) Load

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

func (*URLSource) Type

func (s *URLSource) Type() string

Jump to

Keyboard shortcuts

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