Help us shape the future of Go! Take the 2026 Go Developer Survey

wiki

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(content string) string

func IsStale

func IsStale(doc Doc, storedHash string) bool

IsStale reports whether doc's current content hash differs from a previously stored hash — the trigger for rebuilding the dedup index (spec: Error Handling — wiki/index staleness).

func SaveToFile

func SaveToFile(idx *Index, path string) error

Types

type Doc

type Doc struct {
	Path    string
	Content string
	Hash    string
}

func LoadAll

func LoadAll(wikiDir string) ([]Doc, error)

LoadAll reads every .md file under wikiDir, recursively.

type Index

type Index struct {
	Docs    []Doc
	Vocab   map[string]int      // term -> index into each vector
	Vectors [][]float64         // one vector per Doc, same order as Docs
	Links   map[string][]string // extracted co-mention edges: path -> paths mentioned by that doc
}

Index is a TF-IDF vector search index over wiki documents. This is a deliberate v1 simplification of the spec's "embeddings index": the spec named semantic search as the goal but did not specify an embedding provider, and adding one would mean either an external API dependency (contradicting "Golem stores no credentials") or an arbitrary vendor choice. TF-IDF cosine similarity gets meaningfully better-than-grep retrieval with zero network calls and zero credentials — pure Go, no cgo.

func Build

func Build(docs []Doc) *Index

func EnsureIndex

func EnsureIndex(wikiDir, indexPath string) (*Index, error)

EnsureIndex is the one place staleness, rebuild, and search come together: it loads the on-disk index if it's still fresh, or rebuilds it from current wiki content if it's missing or any document's hash has changed since the index was last saved (spec: Error Handling).

func LoadFromFile

func LoadFromFile(path string) (*Index, error)

func (*Index) Search

func (idx *Index) Search(query string, topK int) []Match

Search returns the topK documents most similar to query, ranked highest score first.

func (*Index) SearchExpanded

func (idx *Index) SearchExpanded(query string, topK int) []Match

SearchExpanded returns the topK TF-IDF matches, then appends any docs that those matches link to (one hop only) and are not already in the direct results. Linked results score at half the referring doc's score so they always sort after direct matches. The Via field on each linked Match names the doc that mentioned it, so callers can show provenance.

type Match

type Match struct {
	Path  string
	Score float64
	Via   string // non-empty when this result was reached by link expansion, not direct TF-IDF
}

Jump to

Keyboard shortcuts

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