Help us shape the future of Go! Take the 2026 Go Developer Survey

embed

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEndpoint = "http://localhost:11434"

DefaultEndpoint is the default Ollama API endpoint.

View Source
const DefaultModel = "nomic-embed-text"

DefaultModel is the default Ollama embedding model.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float64) float64

CosineSimilarity computes the cosine similarity between two vectors. Returns 0 if either vector is zero-length or has zero magnitude.

func DeserializeLegacyVector

func DeserializeLegacyVector(b []byte) []float64

DeserializeLegacyVector decodes a pre-migration little-endian float64 blob.

func DeserializeVector

func DeserializeVector(b []byte) []float64

DeserializeVector decodes a little-endian float32 blob into a float64 slice.

func SerializeVector

func SerializeVector(v []float64) []byte

SerializeVector encodes a vector as a little-endian float32 blob.

Types

type Client

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

Client communicates with an Ollama instance for embedding generation.

func NewClient

func NewClient() *Client

NewClient creates an Ollama embedding client. It checks MNEMON_EMBED_ENDPOINT, MNEMON_EMBED_MODEL, and MNEMON_EMBED_DIMENSIONS env vars.

func NewClientWithModel

func NewClientWithModel(model string) *Client

NewClientWithModel creates an Ollama embedding client with an explicit model override. Resolution order for the model: explicit argument > MNEMON_EMBED_MODEL env var > DefaultModel. The endpoint and dimensions continue to be resolved from MNEMON_EMBED_ENDPOINT and MNEMON_EMBED_DIMENSIONS env vars.

func (*Client) Available

func (c *Client) Available() bool

Available returns true if the Ollama server is reachable and the model is loaded. Uses a 2s timeout to avoid blocking the CLI on unresponsive servers.

func (*Client) Embed

func (c *Client) Embed(text string) ([]float64, error)

Embed generates an embedding vector for the given text.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the configured Ollama endpoint URL.

func (*Client) Model

func (c *Client) Model() string

Model returns the configured model name.

Jump to

Keyboard shortcuts

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