Documentation
¶
Index ¶
- Constants
- func Blend(a, b []float32, wa, wb float32) []float32
- func BytesAsVec(b []byte) []float32
- func Cosine(a, b []float32) float32
- func EffectiveAnchor(static, centroid []float32) []float32
- func Normalize(v []float32) []float32
- func VecAsBytes(v []float32) []byte
- type Assignment
- type Embedder
- type Match
- type Ollama
- type OpenAI
- type Space
- type SpaceIndex
Constants ¶
const ( ThresholdAssign = float32(0.40) // post lands in anchor's feed ThresholdFrontier = float32(0.25) // near-miss zone ThresholdSwallow = float32(0.25) // below this = spam MaxAssignments = 2 // top-2 anchors ProximityBoost = float32(0.05) // pro user additive bonus )
Variables ¶
This section is empty.
Functions ¶
func BytesAsVec ¶
BytesAsVec converts a raw byte blob back to a float32 vector.
func EffectiveAnchor ¶
EffectiveAnchor computes normalize(0.5*static + 0.5*centroid). If centroid is nil (no posts yet), returns static as-is.
func VecAsBytes ¶
VecAsBytes converts a float32 vector to a raw byte blob (for DB storage).
Types ¶
type Assignment ¶
Assignment represents a post's assignment to an anchor.
func Assign ¶
func Assign(postVec []float32, anchorVecs [][]float32, isPro bool) (assignments []Assignment, swallowed bool)
Assign returns the top-2 anchor assignments above ThresholdAssign. If isPro, adds ProximityBoost to all similarities before thresholding. Returns nil assignments and swallowed=true if all similarities are below ThresholdSwallow. Posts between ThresholdSwallow and ThresholdAssign are "frontier" (nil assignments, swallowed=false).
type Embedder ¶
type Embedder interface {
Embed(texts []string) ([][]float32, error)
Dims() int
Name() string // unique key for caching, e.g. "openai-3small-512"
}
Embedder produces vector embeddings from text.
func NewFromProvider ¶
NewFromProvider constructs an Embedder by provider name. "auto" (default) tries ollama first, falls back to openai. "ollama": model and baseURL are optional (defaults apply). "openai": reads OPENAI_API_KEY from environment.
type Space ¶
type Space struct {
Slug string `yaml:"slug"`
Description string `yaml:"description"`
Centroid string `yaml:"centroid"`
}
Space is a single entry from spaces.yaml.
func LoadSpaces ¶
LoadSpaces parses a spaces.yaml file.
type SpaceIndex ¶
type SpaceIndex struct {
Spaces []Space
// contains filtered or unexported fields
}
SpaceIndex holds parsed spaces with centroid embeddings for multiple embedders.
func LoadSpaceIndex ¶
func LoadSpaceIndex(yamlPath, cacheDir string, embedders ...Embedder) (*SpaceIndex, error)
LoadSpaceIndex loads spaces.yaml and embeds centroids with every provided embedder. Each embedder's vectors are cached independently in cacheDir as "{name}.bin".
func (*SpaceIndex) EmbedderNames ¶
func (idx *SpaceIndex) EmbedderNames() []string
EmbedderNames returns all loaded embedder names.
func (*SpaceIndex) Lookup ¶
func (idx *SpaceIndex) Lookup(slug, embedderName string) (*Space, []float32)
Lookup returns the Space and its vector for a given slug and embedder.
func (*SpaceIndex) Vecs ¶
func (idx *SpaceIndex) Vecs(embedderName string) [][]float32
Vecs returns the centroid vectors for a given embedder name.