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
- func EmbedFor(extractSpec string) string
- func FetchLocalModel(ctx context.Context, name, dir string, progress io.Writer) error
- func LocalModelDir() string
- func LocalModelReady(name, dir string) bool
- func LocalModelSize(name string) int64
- type Config
- type EmbedConfig
- type Embedder
- type Embedding
- type Extractor
- type LocalEmbedder
Constants ¶
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).
const DefaultAnthropicModel = "claude-opus-5-5"
DefaultAnthropicModel is the model used when a spec names the anthropic provider without a model.
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
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
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
LocalModelReady reports whether every file of a local model is already downloaded into dir.
func LocalModelSize ¶ added in v0.20.0
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.
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
Dim is the size of the vectors it returns, or 0 when unknown.
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 ¶
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.
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) 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".