Documentation
¶
Overview ¶
Package knowledgebase is a managed knowledge base for togo: ingest documents, chunk + embed them, and run hybrid (keyword + vector) search for RAG. It can also crawl sources on a schedule with content-hash change detection.
kb, _ := knowledgebase.FromKernel(k)
kb.Ingest(ctx, knowledgebase.Document{URL: "/docs/intro", Title: "Intro", Text: "..."})
hits := kb.Search(knowledgebase.Query{Text: "how do I install", TopK: 5})
Index ¶
- type Document
- type Embedder
- type Fetcher
- type Query
- type Result
- type Service
- func (s *Service) AddSource(src Source, fetch Fetcher)
- func (s *Service) Crawl(ctx context.Context, name string) (bool, error)
- func (s *Service) Documents(collection string) []*Document
- func (s *Service) Ingest(ctx context.Context, d Document) (*Document, bool)
- func (s *Service) Search(q Query) []Result
- func (s *Service) Sources() []*Source
- func (s *Service) WithEmbedder(e Embedder) *Service
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
ID string `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
Text string `json:"text"`
Source string `json:"source,omitempty"`
Collection string `json:"collection,omitempty"`
Hash string `json:"hash"`
UpdatedAt time.Time `json:"updated_at"`
}
Document is a unit of source content.
type Embedder ¶
Embedder turns text into a vector. The default is a deterministic local hashing embedder (works offline / in tests); wire a real one (e.g. via the ai plugin) with Service.WithEmbedder for semantic quality.
type Result ¶
type Result struct {
DocID string `json:"doc_id"`
URL string `json:"url"`
Title string `json:"title"`
Snippet string `json:"snippet"`
Score float64 `json:"score"`
}
Result is a ranked search hit.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the knowledge-base runtime (k.Get("knowledge-base")).
func FromKernel ¶
FromKernel returns the knowledge-base Service.
func (*Service) Ingest ¶
Ingest stores/updates a document: it chunks + embeds the text. It returns (doc, true) when content changed and was (re)ingested, or (doc, false) when the content hash is unchanged (change detection / dedupe).
func (*Service) Search ¶
Search runs hybrid keyword + vector retrieval merged by reciprocal-rank fusion.
func (*Service) WithEmbedder ¶
WithEmbedder swaps the embedder (e.g. an ai-backed one).