modelstore

package
v1.0.0-rc.17 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 33 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 modelstore resolves model names to on-disk paths within a modeld node's models directory. It exists so a session request can omit Path: a remote node has no idea what filesystem layout the runtime that sent the request uses, so the node must resolve ModelName+Type against its own storage instead of trusting a caller-supplied path.

Layout mirrors what the runtime's local catalog providers already scan (runtime/modelrepo/llama, runtime/modelrepo/openvino), so an existing local models directory works unchanged as a node's models dir:

<dir>/<name>/model.gguf              (llama)
<dir>/<name>/openvino_model.xml       (openvino, or openvino_language_model.xml)

Index

Constants

View Source
const CompanionIndexFilename = "index.json"

CompanionIndexFilename is the embedded companion index beside the companion archives.

View Source
const DefaultSubdir = "models"

DefaultSubdir is the models directory name under a data root when no explicit override is configured.

View Source
const LoRAFile = "adapter.gguf"

A named GGUF variant keeps its base, adapter and optional strength together so copying the model to another modeld owner preserves its behaviour.

View Source
const LoRASettingsFile = "adapter.json"

Variables

View Source
var (
	// ErrModelNotFound is returned when no model matching the requested
	// name+type exists in the models directory.
	ErrModelNotFound = transport.ErrModelNotFound
	// ErrDigestMismatch is returned when a caller-supplied digest does not
	// match the on-disk content. Only enforced when the caller supplies a
	// non-empty digest to verify against.
	ErrDigestMismatch = transport.ErrDigestMismatch
	// ErrUnsupportedType is returned for a backend type this package does not
	// know how to resolve.
	ErrUnsupportedType = transport.ErrUnsupportedModelType
)

These alias the transport package's canonical sentinels rather than defining new error values: model resolution errors surface both in-process (slot.Service callers checking modelstore.ErrModelNotFound directly) and across the gRPC wire (Admin.ReceiveModel's errors, encoded/decoded via transport/grpc's sentinel table). A local, unrelated error value here would lose its identity crossing the wire.

Functions

func ArtifactDigest

func ArtifactDigest(path, backend string) (string, error)

ArtifactDigest identifies the complete native artifact. Single-file llama models retain their file SHA256; vision models and OpenVINO use the bundle tree digest.

func BundledLoRA

func BundledLoRA(model string) (*transport.AdapterSpec, error)

func CompanionIndex

func CompanionIndex(entries []modelregistry.ModelDescriptor, archive func(id string) ([]byte, error)) (map[string]CompanionAsset, error)

CompanionIndex derives the published index for every companion the curated catalog requires.

func CompanionRebuildCommand

func CompanionRebuildCommand(model modelregistry.ModelDescriptor) string

CompanionRebuildCommand is the command that rebuilds one model's companion from its pinned snapshot.

func Dir

func Dir(dataRoot, override string) string

Dir resolves the models directory: an explicit override if non-empty, otherwise <dataRoot>/<DefaultSubdir>.

func DirectoryDigest

func DirectoryDigest(dir string) (string, error)

DirectoryDigest hashes relative file names and content in deterministic order. Bundle inputs must be regular files so symbolic links cannot escape the recorded artifact.

func DownloadFile

func DownloadFile(ctx context.Context, srcURL, destPath string, progressW io.Writer) error

DownloadFile downloads a file from srcURL to destPath using a temporary staging file.

func DownloadOpenVINOIR

func DownloadOpenVINOIR(ctx context.Context, repo, revision, destDir string, out io.Writer, progress func(DownloadProgress) error) error

DownloadOpenVINOIR downloads one repository snapshot into a staging directory; an empty revision selects the repository default.

func EnsureModelAvailable

func EnsureModelAvailable(ctx context.Context, reg modelregistry.Registry, modelName string, opts AutoPullOptions) (err error)

EnsureModelAvailable stages every required asset before submitting the complete bundle to its owner. Existing assignments and artifacts survive download failure.

func FileDigest

func FileDigest(path string) (string, error)

FileDigest returns the hex-encoded sha256 digest of a file's content.

func FormatSize

func FormatSize(n int64) string

FormatSize formats a byte count into a human-readable string.

func ReadCompanionIndex

func ReadCompanionIndex(data []byte) (map[string]CompanionAsset, error)

ReadCompanionIndex decodes a companion index.

func RenderCompanionIndex

func RenderCompanionIndex(index map[string]CompanionAsset) ([]byte, error)

RenderCompanionIndex renders a companion index in its published form.

func Resolve

func Resolve(dir, name, backendType, wantDigest string) (path string, err error)

Resolve finds the on-disk path for a model by name and backend type within dir. When wantDigest is non-empty, the resolved artifact's content digest is compared and a mismatch is rejected — this guards against a stale or wrong file answering under a name the caller expects to be a specific model. OpenVINO identity covers regular files and their relative names throughout the bundle.

func ResolveMMProj

func ResolveMMProj(modelPath string) string

ResolveMMProj returns the optional multimodal projector installed next to a resolved llama model path (see llama.MMProjFilename), or "" when the model has none. ArtifactDigest includes an installed projector in bundle identity; vision execution capability is certified separately by the backend's Describe.

func VerifyCompanionCoverage

func VerifyCompanionCoverage(entries []modelregistry.ModelDescriptor, index map[string]CompanionAsset, archive func(id string) ([]byte, error)) error

VerifyCompanionCoverage fails when a published index does not match the catalog's companions.

func WithDownloadOrigin

func WithDownloadOrigin(ctx context.Context, origin string) context.Context

WithDownloadOrigin binds the desktop token to the explicitly selected repository origin.

func WithDownloadToken

func WithDownloadToken(ctx context.Context, token string) context.Context

WithDownloadToken supplies a read token for one Hugging Face download.

func WriteModelProfile

func WriteModelProfile(modelBackend, modelDir, toolProtocol, reasoningProtocol, reasoningFormat string) error

WriteModelProfile writes local parsing protocols to a fresh profile JSON.

Types

type AccessDenied

type AccessDenied struct {
	Status int
	Page   string
}

func (*AccessDenied) Error

func (e *AccessDenied) Error() string

type Admin

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

Admin implements node-side model store management: listing, removal, disk stats, and receiving pushed model blobs. Per the runtime's model distribution design, a node never fetches from an external source — the runtime is the only source of model bytes, and Admin is purely a local sink/inventory over the models directory.

func NewAdmin

func NewAdmin(dir string) *Admin

NewAdmin returns an Admin operating on dir (a resolved models directory, see Dir).

func NewProtectedAdmin

func NewProtectedAdmin(dir string, check func(string) error) (*Admin, error)

NewProtectedAdmin checks owner residency while holding the model's exclusive mutation claim.

func (*Admin) DiskStats

func (a *Admin) DiskStats(ctx context.Context) (DiskStats, error)

DiskStats reports free/used/total bytes on the filesystem backing the models directory.

func (*Admin) Inventory

func (a *Admin) Inventory() ([]NodeModel, error)

Inventory reads installed sizes and metadata without hashing model weights.

func (*Admin) ListModels

func (a *Admin) ListModels(_ context.Context) ([]NodeModel, error)

ListModels enumerates every model in the models directory.

func (*Admin) ReceiveModel

func (a *Admin) ReceiveModel(ctx context.Context, manifest PushManifest, r io.Reader) (PushResult, error)

ReceiveModel is the sink side of PushModel: it consumes r (the raw byte stream described by manifest), verifies it against manifest.Digest, and atomically installs it as the named model. Idempotent: an existing model with a matching digest is kept and the newly received bytes discarded.

Deciding whether to push at all — skipping when the model is already present with a matching digest — is the caller's job (the runtime's reconcile loop checks ListModels first, since it can do that without transferring any bytes). ReceiveModel always accepts and verifies a full stream so there is exactly one, always-correct write path; it is not an optimization for the already-present case.

At most one push per model name may be in flight at a time; a concurrent second push for the same name is rejected immediately.

func (*Admin) RemoveModel

func (a *Admin) RemoveModel(_ context.Context, name string) error

RemoveModel deletes a model's directory. ErrModelNotFound if it does not exist.

func (*Admin) Retain

func (a *Admin) Retain(name string) (func(), error)

Retain prevents mutation while an owner resolves and registers a model allocation.

type AutoPullOptions

type AutoPullOptions struct {
	DataRoot    string
	Receive     ModelReceiver
	ProgressOut io.Writer
	Progress    func(DownloadProgress) error
	Tracker     libtracker.ActivityTracker
}

AutoPullOptions carries options for EnsureModelAvailable.

type CompanionAsset

type CompanionAsset struct {
	Archive       string `json:"archive"`
	ArchiveSHA256 string `json:"archiveSha256"`
	ModelRepo     string `json:"modelRepo"`
	ModelRevision string `json:"modelRevision"`
	Kind          string `json:"kind"`
	Format        string `json:"format"`
}

CompanionAsset publishes one companion archive for one model repository revision.

type CompanionManifest

type CompanionManifest struct {
	Version                 int      `json:"version"`
	Kind                    string   `json:"kind"`
	Format                  string   `json:"format"`
	FormatVersion           int      `json:"format_version"`
	SourceTokenizerSHA256   string   `json:"source_tokenizer_sha256"`
	ControlTokens           []string `json:"control_tokens"`
	PreparationScriptSHA256 string   `json:"preparation_script_sha256"`
}

CompanionManifest is the format identity a companion archive records for its model.

func ReadCompanionArchiveManifest

func ReadCompanionArchiveManifest(archive []byte) (CompanionManifest, error)

ReadCompanionArchiveManifest decodes the manifest of an archive whose contents are already validated.

func ValidateCompanionArchive

func ValidateCompanionArchive(id string, archive []byte) (CompanionManifest, error)

ValidateCompanionArchive verifies one companion archive against its asset ID and the format schema.

type CompanionRequirement

type CompanionRequirement struct {
	Model    modelregistry.ModelDescriptor
	AssetID  string
	Kind     string
	Format   string
	Version  int
	Controls []string
}

CompanionRequirement is the tokenizer companion one curated model declares.

func CompanionRequirements

func CompanionRequirements(entries []modelregistry.ModelDescriptor) ([]CompanionRequirement, error)

CompanionRequirements returns the companion every curated OpenVINO model with a completion or edit contract declares, sourced from the curated catalog rather than from a second list.

type DiskStats

type DiskStats struct {
	FreeBytes  int64
	UsedBytes  int64
	TotalBytes int64
}

DiskStats reports free/used space on the filesystem backing the models directory, so the runtime can decide whether a push would fit before sending gigabytes of model weights.

type DownloadProgress

type DownloadProgress struct {
	Artifact   string `json:"-"`
	Downloaded int64
	Total      int64
}

DownloadProgress is the byte position of one model artifact download.

type DownloadProgressWriter

type DownloadProgressWriter struct {
	Artifact   string
	Total      int64
	Downloaded int64
	LastPrint  time.Time
	Out        io.Writer
	Progress   func(DownloadProgress) error
}

DownloadProgressWriter writes download progress to Out.

func (*DownloadProgressWriter) Write

func (pw *DownloadProgressWriter) Write(p []byte) (int, error)

type ModelReceiver

ModelReceiver installs a complete artifact through its owner's mutation guard.

type NodeAdmin

type NodeAdmin struct{ *Admin }

NodeAdmin adapts local storage and its mutation protection to the daemon contract.

func NewNodeAdmin

func NewNodeAdmin(dir string) *NodeAdmin

NewNodeAdmin exposes the model store through the common node management contract.

func NewProtectedNodeAdmin

func NewProtectedNodeAdmin(dir string, check func(string) error) (*NodeAdmin, error)

NewProtectedNodeAdmin shares model acquisition and mutation protection with the owner.

func (*NodeAdmin) DiskStats

func (a *NodeAdmin) DiskStats(ctx context.Context) (transport.NodeDiskStats, error)

DiskStats reports the model store's filesystem capacity.

func (*NodeAdmin) ListModels

func (a *NodeAdmin) ListModels(ctx context.Context) ([]transport.NodeModel, error)

ListModels lists installed artifacts without loading them.

func (*NodeAdmin) ReceiveModel

func (a *NodeAdmin) ReceiveModel(ctx context.Context, manifest transport.PushManifest, reader io.Reader) (transport.PushResult, error)

ReceiveModel verifies and installs an incoming model through the shared mutation guard.

type NodeModel

type NodeModel struct {
	LoRA       bool
	MediaError string
	Pipeline   string
	Name       string
	Type       string // "llama" | "openvino"
	Digest     string // file SHA256 for single-file llama; tree SHA256 for bundles
	SizeBytes  int64
	// ContextLength is the model's trained context ceiling, from a header-only
	// metadata parse (no device query, no capacity planner) — 0 if that parse
	// failed or was skipped; see ListModels.
	ContextLength int
}

NodeModel is one model as observed on a node's models directory.

type PushFormat

type PushFormat string

PushFormat identifies how a PushModel byte stream is laid out.

const (
	// PushFormatFile is a single-file model (llama GGUF), written as
	// <dir>/<name>/model.gguf.
	PushFormatFile PushFormat = "file"
	// PushFormatTar is a directory model sent as an uncompressed tar stream and
	// unpacked into <dir>/<name>/: an OpenVINO IR bundle, or a llama vision
	// model shipping model.gguf plus its mmproj.gguf projector (see
	// ResolveMMProj) — the tar keeps the two files one atomic install.
	PushFormatTar PushFormat = "tar"
)

type PushManifest

type PushManifest struct {
	Name       string
	Type       string // "llama" | "openvino"
	Digest     string
	TotalBytes int64
	Format     PushFormat
}

PushManifest describes an incoming model push. Digest is the sha256 of the raw byte stream exactly as sent (the tar stream itself for PushFormatTar, not a hash of the unpacked contents) — the receiver verifies it as bytes arrive, before touching the models directory.

type PushResult

type PushResult struct {
	// AlreadyPresent means a model with this name and a matching digest was
	// already installed; the newly received bytes were verified then
	// discarded rather than replacing it.
	AlreadyPresent bool
	BytesWritten   int64
}

PushResult reports what ReceiveModel actually did.

Jump to

Keyboard shortcuts

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