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
- Variables
- func ArtifactDigest(path, backend string) (string, error)
- func BundledLoRA(model string) (*transport.AdapterSpec, error)
- func CompanionIndex(entries []modelregistry.ModelDescriptor, ...) (map[string]CompanionAsset, error)
- func CompanionRebuildCommand(model modelregistry.ModelDescriptor) string
- func Dir(dataRoot, override string) string
- func DirectoryDigest(dir string) (string, error)
- func DownloadFile(ctx context.Context, srcURL, destPath string, progressW io.Writer) error
- func DownloadOpenVINOIR(ctx context.Context, repo, revision, destDir string, out io.Writer, ...) error
- func EnsureModelAvailable(ctx context.Context, reg modelregistry.Registry, modelName string, ...) (err error)
- func FileDigest(path string) (string, error)
- func FormatSize(n int64) string
- func ReadCompanionIndex(data []byte) (map[string]CompanionAsset, error)
- func RenderCompanionIndex(index map[string]CompanionAsset) ([]byte, error)
- func Resolve(dir, name, backendType, wantDigest string) (path string, err error)
- func ResolveMMProj(modelPath string) string
- func VerifyCompanionCoverage(entries []modelregistry.ModelDescriptor, index map[string]CompanionAsset, ...) error
- func WithDownloadOrigin(ctx context.Context, origin string) context.Context
- func WithDownloadToken(ctx context.Context, token string) context.Context
- func WriteModelProfile(...) error
- type AccessDenied
- type Admin
- func (a *Admin) DiskStats(ctx context.Context) (DiskStats, error)
- func (a *Admin) Inventory() ([]NodeModel, error)
- func (a *Admin) ListModels(_ context.Context) ([]NodeModel, error)
- func (a *Admin) ReceiveModel(ctx context.Context, manifest PushManifest, r io.Reader) (PushResult, error)
- func (a *Admin) RemoveModel(_ context.Context, name string) error
- func (a *Admin) Retain(name string) (func(), error)
- type AutoPullOptions
- type CompanionAsset
- type CompanionManifest
- type CompanionRequirement
- type DiskStats
- type DownloadProgress
- type DownloadProgressWriter
- type ModelReceiver
- type NodeAdmin
- func (a *NodeAdmin) DiskStats(ctx context.Context) (transport.NodeDiskStats, error)
- func (a *NodeAdmin) ListModels(ctx context.Context) ([]transport.NodeModel, error)
- func (a *NodeAdmin) ReceiveModel(ctx context.Context, manifest transport.PushManifest, reader io.Reader) (transport.PushResult, error)
- type NodeModel
- type PushFormat
- type PushManifest
- type PushResult
Constants ¶
const CompanionIndexFilename = "index.json"
CompanionIndexFilename is the embedded companion index beside the companion archives.
const DefaultSubdir = "models"
DefaultSubdir is the models directory name under a data root when no explicit override is configured.
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.
const LoRASettingsFile = "adapter.json"
Variables ¶
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 ¶
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 ¶
Dir resolves the models directory: an explicit override if non-empty, otherwise <dataRoot>/<DefaultSubdir>.
func DirectoryDigest ¶
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 ¶
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 ¶
FileDigest returns the hex-encoded sha256 digest of a file's content.
func FormatSize ¶
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 ¶
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 ¶
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 ¶
WithDownloadOrigin binds the desktop token to the explicitly selected repository origin.
func WithDownloadToken ¶
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 ¶
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 NewProtectedAdmin ¶
NewProtectedAdmin checks owner residency while holding the model's exclusive mutation claim.
func (*Admin) DiskStats ¶
DiskStats reports free/used/total bytes on the filesystem backing the models directory.
func (*Admin) Inventory ¶
Inventory reads installed sizes and metadata without hashing model weights.
func (*Admin) ListModels ¶
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 ¶
RemoveModel deletes a model's directory. ErrModelNotFound if it does not exist.
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 ¶
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 ¶
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.
type ModelReceiver ¶
type ModelReceiver func(context.Context, transport.PushManifest, io.Reader) (transport.PushResult, error)
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 ¶
NewNodeAdmin exposes the model store through the common node management contract.
func NewProtectedNodeAdmin ¶
NewProtectedNodeAdmin shares model acquisition and mutation protection with the owner.
func (*NodeAdmin) ListModels ¶
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.