Documentation
¶
Overview ¶
Package embedding provides semantic vector embeddings for symbols. Uses MiniLM-L6-v2 via hugot (pure-Go ONNX runtime) for offline embedding generation. Model auto-downloads from Hugging Face on first use (~30MB). Vectors are stored in an HNSW index (coder/hnsw) for nearest-neighbor search.
Index ¶
- Constants
- type Embedder
- func (e *Embedder) AddVector(id string, vec []float32)
- func (e *Embedder) Close() error
- func (e *Embedder) Count() int
- func (e *Embedder) Embed(ctx context.Context, text string) ([]float32, error)
- func (e *Embedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
- func (e *Embedder) Search(query []float32, k int) []string
- type Searcher
- func (s *Searcher) Close() error
- func (s *Searcher) Count() int
- func (s *Searcher) EmbedAndSearch(ctx context.Context, query string, k int) ([]types.Hash, error)
- func (s *Searcher) IndexBatch(ctx context.Context, nodes []types.Node, filePaths []string) error
- func (s *Searcher) IndexNode(ctx context.Context, node types.Node, filePath string) error
Constants ¶
const (
// Dims is the embedding vector dimensionality for BGE-small-en-v1.5.
Dims = 384
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Embedder ¶
type Embedder struct {
// contains filtered or unexported fields
}
Embedder generates embedding vectors and provides nearest-neighbor search.
func New ¶
New creates an Embedder, downloading the model if needed. The model is cached at ~/.cache/knowing/models/.
func (*Embedder) AddVector ¶
AddVector indexes a symbol ID with its embedding vector for nearest-neighbor search.
func (*Embedder) EmbedBatch ¶
EmbedBatch returns embedding vectors for multiple texts.
type Searcher ¶
type Searcher struct {
// contains filtered or unexported fields
}
Searcher wraps an Embedder and provides the VectorSearcher interface expected by the context engine. It resolves HNSW string keys (hex-encoded node hashes) back to types.Hash values.
func NewSearcher ¶
NewSearcher creates a Searcher from an initialized Embedder.
func (*Searcher) EmbedAndSearch ¶
EmbedAndSearch embeds the query text and returns the k nearest symbol hashes.
func (*Searcher) IndexBatch ¶
IndexBatch embeds multiple nodes and adds them to the HNSW index. More efficient than individual IndexNode calls due to batched embedding.