Documentation
¶
Overview ¶
Package embeddings provides a pure-Go TF-IDF retrieval engine over symbol metadata (name + qualified name + signature + docstring). It is the in-process semantic-similarity signal consumed by graph.SemanticSearch.
Why TF-IDF rather than a neural embedding model?
- Zero runtime dependencies (Grove's non-negotiable constraint).
- Predictable cost — Index() is O(N · L) and Query() is O(Q · K).
- Strong baseline for code retrieval: identifiers, paths, and docstrings have heavy lexical overlap with intent strings.
The engine can be swapped for an external embedding service later by implementing the same Engine interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine interface {
Index(symbols []core.SymbolRecord)
Query(query string, limit int) []Scored
}
Engine is the contract any embedding backend must satisfy.
type Scored ¶
type Scored struct {
Symbol *core.SymbolRecord
Score float64
}
Scored is one ranked result.
type TFIDF ¶
type TFIDF struct {
// contains filtered or unexported fields
}
TFIDF is a small in-memory term-frequency / inverse-document-frequency index.
Each symbol is treated as a "document" whose tokens come from {name, qualifiedName, signature, docstring, parentSymbol}.
func NewTFIDF ¶
func NewTFIDF() *TFIDF
NewTFIDF returns an empty engine. Call Index() before Query().
func (*TFIDF) Index ¶
func (t *TFIDF) Index(symbols []core.SymbolRecord)
Index builds the index from the given symbols. Calling Index again replaces the previous index entirely.
type VectorCacher ¶ added in v0.6.0
type VectorCacher interface {
// IndexWithCache behaves like Index but reads previously computed
// vectors from cache, writes newly computed ones back, and prunes
// entries whose IDs are no longer present.
IndexWithCache(symbols []core.SymbolRecord, cache map[string][]float32)
}
VectorCacher is implemented by engines whose per-document vectors are a pure function of the document text and can therefore be reused across index rebuilds. Symbol IDs embed the file content SHA, so an unchanged ID guarantees unchanged text. TF-IDF cannot implement this: its weights depend on corpus-wide document frequencies.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package model2vec is a pure-Go inference engine for MinishLab's Model2Vec static embeddings, bundled with the potion-base-8M model.
|
Package model2vec is a pure-Go inference engine for MinishLab's Model2Vec static embeddings, bundled with the potion-base-8M model. |