embed

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package embed provides embedding-based tool retrieval for the skillgraph gateway. It embeds tool descriptions once at boot, rebuilds on config change, and exposes cosine-similarity search with optional two-tier (server → tool) hierarchy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Provider  Provider
	Endpoint  string // e.g. http://localhost:11434 or https://api.openai.com
	APIKey    string
	Model     string
	Dimension int // 0 = model default; set via EMBED_DIMENSIONS (e.g. 256 for Matryoshka)
}

Config holds embedding configuration, resolved from env vars.

func ResolveConfig

func ResolveConfig() Config

ResolveConfig detects the embedding provider using the same priority chain as the LLM provider in refine/engine.go. Priority: LLM_BASE_URL (Ollama/LiteLLM) > OPENAI_API_KEY

type Embedder

type Embedder struct {
	// contains filtered or unexported fields
}

Embedder calls the embedding API and returns a float32 vector.

func NewEmbedder

func NewEmbedder(cfg Config) *Embedder

NewEmbedder creates an Embedder from a resolved Config.

func (*Embedder) Embed

func (e *Embedder) Embed(ctx context.Context, text string) ([]float32, error)

Embed returns the embedding vector for text.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index is a thread-safe in-memory embedding index over tool descriptions.

func NewIndex

func NewIndex(embedder *Embedder) *Index

NewIndex creates an empty Index.

func (*Index) Find

func (idx *Index) Find(ctx context.Context, query string, k int, serverFilter string) ([]SearchResult, error)

Find returns the top-k tools most similar to query. If serverFilter is non-empty, only tools from that server are considered.

func (*Index) Len

func (idx *Index) Len() int

Len returns the number of indexed tools.

func (*Index) Rebuild

func (idx *Index) Rebuild(ctx context.Context, tools []ToolEntry) error

Rebuild replaces the index with a fresh set of tool embeddings. Blocks until all embeddings are fetched. Called at boot and on config change.

type Provider

type Provider int

Provider selects the embedding backend.

const (
	ProviderNone   Provider = iota
	ProviderOllama          // LLM_BASE_URL pointing at Ollama, or OLLAMA_HOST
	ProviderOpenAI          // OPENAI_API_KEY
)

type SearchResult

type SearchResult struct {
	Server      string
	ToolName    string
	Description string
	Score       float32
}

SearchResult is a single match returned by Find.

type ToolEntry

type ToolEntry struct {
	Server      string
	ToolName    string // resolved name (e.g. "gitnexus_impact")
	Description string
	Vector      []float32
}

ToolEntry is a single indexed tool.

Jump to

Keyboard shortcuts

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