embeddings

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 5 Imported by: 0

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?

  1. Zero runtime dependencies (Grove's non-negotiable constraint).
  2. Predictable cost — Index() is O(N · L) and Query() is O(Q · K).
  3. 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.

func (*TFIDF) Query

func (t *TFIDF) Query(query string, limit int) []Scored

Query returns the top-`limit` symbols ranked by cosine similarity against the query text. Symbols are returned in descending Score order. Score is always in [0, 1].

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.

Jump to

Keyboard shortcuts

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