model

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 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 model is a recall.Extractor backed by a language model, so that RememberText can be given text alone and work out the statements in it.

The model only proposes. Every proposal still goes through the registry and the fold, so a model can name only registered predicates, must quote its evidence from the text, and cannot change what supersession means.

Index

Constants

View Source
const (
	DefaultOpenAIEmbedModel = "text-embedding-3-small"
	DefaultOpenAIEmbedDim   = 512
	DefaultOllamaEmbedModel = "nomic-embed-text"
	DefaultVoyageEmbedModel = "voyage-3.5"
)

Default embedding models. Each follows the extractor's provider, so a setup that already sends text to a provider embeds with the same one. text-embedding-3-small at 512 dimensions is what the LongMemEval user-facts run measured (Recall lexical 88.8, with this embedder 92.9).

View Source
const DefaultAnthropicModel = "claude-opus-5-5"

DefaultAnthropicModel is the model used when a spec names the anthropic provider without a model.

View Source
const DefaultLocalEmbedModel = "all-minilm-l6-v2"

DefaultLocalEmbedModel is the model the local provider runs when a spec names none. It runs inside the recall binary, in pure Go, so search by meaning needs no key and no service: all-MiniLM-L6-v2 (Apache-2.0), 384 dimensions, about 90 MB, downloaded once on first use.

Variables

This section is empty.

Functions

func EmbedFor added in v0.20.0

func EmbedFor(extractSpec string) string

EmbedFor is the embedding model that follows an extraction model spec: openai:* embeds with text-embedding-3-small at 512 dimensions, ollama:* with nomic-embed-text, and anthropic:*, which has no embedding API, with the local model that runs inside recall. It returns "" for an openai spec pointed at another endpoint by OPENAI_BASE_URL, which may not serve embeddings, and for no model.

func FetchLocalModel added in v0.20.0

func FetchLocalModel(ctx context.Context, name, dir string, progress io.Writer) error

FetchLocalModel downloads a local model's files into dir/<name>, checking each against its pinned SHA-256 and writing it into place only when it matches. Files already present are not downloaded again. progress, when not nil, is told what is being fetched.

func LocalModelDir added in v0.20.0

func LocalModelDir() string

LocalModelDir is where downloaded models live: $RECALL_MODEL_DIR, else models/ under Recall's home ($RECALL_HOME, then ~/.local/share/recall, with the spellings before 0.23.0 still honored; see recallhome.Home). Copy a model's files there to use it on a machine without internet access.

func LocalModelReady added in v0.20.0

func LocalModelReady(name, dir string) bool

LocalModelReady reports whether every file of a local model is already downloaded into dir.

func LocalModelSize added in v0.20.0

func LocalModelSize(name string) int64

LocalModelSize is the download size of a local model in bytes.

Types

type Config

type Config struct {
	// Provider is "anthropic", "openai", or "ollama". openai also serves any
	// endpoint that speaks the OpenAI chat completions API, such as vLLM or
	// Groq, through BaseURL or OPENAI_BASE_URL.
	Provider string
	Model    string
	BaseURL  string
	APIKey   string
	// HTTPClient is optional.
	HTTPClient *http.Client
}

Config selects the model. Empty BaseURL and APIKey are read from the provider's usual environment variables.

func Parse

func Parse(spec string) (Config, error)

Parse reads a "provider:model" spec, such as "anthropic:claude-opus-5-5", "openai:gpt-5-mini", or "ollama:llama3.1". A bare "anthropic" selects DefaultAnthropicModel.

type EmbedConfig added in v0.20.0

type EmbedConfig struct {
	// Provider is "openai", "ollama", or "voyage". openai also serves any
	// endpoint that speaks the OpenAI embeddings API, through BaseURL or
	// OPENAI_BASE_URL.
	Provider string
	Model    string
	// Dim asks the model for vectors of this size, where it can shorten
	// them (text-embedding-3, voyage-3.5); 0 takes the model's own size.
	Dim        int
	BaseURL    string
	APIKey     string
	HTTPClient *http.Client
}

EmbedConfig selects an embedding model. Empty BaseURL and APIKey are read from the provider's usual environment variables.

func ParseEmbed added in v0.20.0

func ParseEmbed(spec string) (EmbedConfig, error)

ParseEmbed reads a "provider:model[@dim]" spec, such as "openai:text-embedding-3-small@512", "ollama:nomic-embed-text", or "voyage:voyage-3.5". A provider alone takes its default model.

func (EmbedConfig) KnownDim added in v0.20.0

func (c EmbedConfig) KnownDim() int

KnownDim is the size of the vectors this configuration returns, or 0 when the model is not one Recall knows.

func (EmbedConfig) Spec added in v0.20.0

func (c EmbedConfig) Spec() string

Spec is the configuration as ParseEmbed reads it, such as "openai:text-embedding-3-small@512". It names the vector space, so two configurations with the same Spec embed compatibly.

type Embedder added in v0.20.0

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

Embedder is a recall.Embedder backed by an embeddings API. OpenAI, Ollama (through its OpenAI-compatible endpoint) and Voyage all take the same request and answer in the same shape.

func NewEmbedder added in v0.20.0

func NewEmbedder(cfg EmbedConfig) (*Embedder, error)

NewEmbedder checks the configuration and builds the embedder. It makes no request until the first Embed.

func (*Embedder) Dim added in v0.20.0

func (e *Embedder) Dim() int

Dim is the size of the vectors it returns, or 0 when unknown.

func (*Embedder) Embed added in v0.20.0

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

Embed returns the vector for text.

func (*Embedder) Spec added in v0.20.0

func (e *Embedder) Spec() string

Spec names the vector space this embedder writes; see EmbedConfig.Spec.

type Embedding added in v0.20.0

type Embedding interface {
	Embed(ctx context.Context, text string) ([]float32, error)
	Spec() string
	Dim() int
}

Embedding is an embedder that names its vector space and their size.

func OpenEmbedding added in v0.20.0

func OpenEmbedding(cfg EmbedConfig, progress io.Writer) (Embedding, error)

OpenEmbedding builds the embedder a configuration names: a hosted or Ollama model, or a local one that runs in this process (progress hears about its first download).

type Extractor

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

Extractor proposes statements from text with a language model.

func NewExtractor

func NewExtractor(cfg Config) (*Extractor, error)

NewExtractor checks the configuration and builds the extractor. It makes no request until the first Extract.

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, text string, reg recall.Registry) ([]recall.Proposal, error)

Extract asks the model for the statements in text, then keeps only the ones the registry admits. A proposal that misquotes the text or gives a value of the wrong type is dropped rather than failing the batch; the text itself is kept as a note either way.

For a client with an open vocabulary (recall.OpenVocabulary), the model sees the predicates already in use and may coin new ones, giving each a cardinality, a description, and a value type.

func (*Extractor) Select added in v0.14.0

func (e *Extractor) Select(ctx context.Context, request string, candidates []recall.Belief) ([]int, error)

Select asks the model which of the candidate statements a request to forget names, for recall's Client.ForgetText.

type LocalEmbedder added in v0.20.0

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

LocalEmbedder runs a local model inside this process. It loads the model on first use and serializes calls; one embedding takes milliseconds.

func NewLocalEmbedder added in v0.20.0

func NewLocalEmbedder(cfg EmbedConfig, progress io.Writer) (*LocalEmbedder, error)

NewLocalEmbedder checks the configuration. It downloads nothing until the first Embed (or Prepare); progress, when not nil, hears about a download.

func (*LocalEmbedder) Close added in v0.20.0

func (e *LocalEmbedder) Close() error

Close releases the model.

func (*LocalEmbedder) Dim added in v0.20.0

func (e *LocalEmbedder) Dim() int

Dim is the size of the vectors.

func (*LocalEmbedder) Embed added in v0.20.0

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

Embed returns the normalized vector for text.

func (*LocalEmbedder) Prepare added in v0.20.0

func (e *LocalEmbedder) Prepare(ctx context.Context) error

Prepare downloads the model if needed and loads it.

func (*LocalEmbedder) Spec added in v0.20.0

func (e *LocalEmbedder) Spec() string

Spec names the vector space: "local:all-minilm-l6-v2".

Jump to

Keyboard shortcuts

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