Documentation
¶
Overview ¶
Package veloxquant is the VeloxQuant Go SDK: memory intelligence and optimization for local AI on Apple Silicon and beyond. It hides MLX and Python runtime implementation details behind an idiomatic Go API for hardware detection, memory/KV-cache estimation, optimization profile selection, and communication with a local VeloxQuant runtime.
Index ¶
- Constants
- Variables
- func FormatBytes(b uint64) string
- type AutoPilotConfig
- type AutoPilotPlan
- type ChatChunk
- type ChatRequest
- type ChatResponse
- type ChatStream
- type Client
- func (c *Client) AutoPilot(ctx context.Context, cfg AutoPilotConfig) (*Session, error)
- func (c *Client) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
- func (c *Client) ChatStream(ctx context.Context, req ChatRequest) (*ChatStream, error)
- func (c *Client) Monitor(opts ...MonitorOption) *monitor.Monitor
- type InferenceMetrics
- type MemoryEstimate
- type MemoryRequest
- type MemoryService
- type Message
- type ModelArchitecture
- type ModelRecommendationRequest
- type ModelsService
- type MonitorConfig
- type MonitorOption
- type OptimizationRecommendation
- type OptimizationRequest
- type OptimizeService
- type Option
- type Precision
- type RuntimeService
- type RuntimeStatus
- type Session
- type SystemInfo
- type SystemService
- type Usage
Constants ¶
Variables ¶
var ( ErrUnsupportedPlatform = errors.New("unsupported platform") ErrInsufficientMemory = errors.New("insufficient memory") ErrModelNotFound = errors.New("model not found") ErrInvalidConfig = errors.New("invalid configuration") )
Sentinel errors returned by the SDK. Use errors.Is to check for these after wrapping with fmt.Errorf("...: %w", err).
Functions ¶
func FormatBytes ¶
FormatBytes renders a byte count as a human-readable string, e.g. "24.0 GB".
Types ¶
type AutoPilotConfig ¶
type AutoPilotConfig struct {
// Task is used to select a suitable model, e.g. "coding", "chat",
// "reasoning", "vision", "agent", "translation".
Task string
// Model may be a specific model name, or "auto" (or empty) to let
// AutoPilot choose one based on Task and available hardware.
Model string
// ContextLength, if set, overrides AutoPilot's automatic context
// length selection.
ContextLength int
}
AutoPilotConfig describes the intent behind an AutoPilot session: what task the caller wants to accomplish, and optionally which model to use.
type AutoPilotPlan ¶
type AutoPilotPlan struct {
Hardware SystemInfo
SelectedModel string
ContextLength int
CompressionBits int
EstimatedMemoryBytes uint64
SafetyMarginBytes uint64
Profile optimize.Profile
Reason string
}
AutoPilotPlan documents every decision AutoPilot made when constructing a Session, so the process is transparent and debuggable.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Stream bool `json:"stream,omitempty"`
}
ChatRequest describes a chat completion request.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Text string `json:"text"`
Usage Usage `json:"usage"`
Metrics InferenceMetrics `json:"metrics"`
}
ChatResponse is the result of a chat completion request.
type ChatStream ¶
type ChatStream struct {
// contains filtered or unexported fields
}
ChatStream is a handle to a streaming chat completion. Call Next to advance, Chunk to read the current piece of text, and Err to check for errors after iteration ends. Always call Close when done. Once the stream is finished (Next returns false with a nil Err), Metrics reports the completed request's tokens/sec and time-to-first-token.
func (*ChatStream) Chunk ¶
func (s *ChatStream) Chunk() ChatChunk
Chunk returns the most recently read chunk.
func (*ChatStream) Close ¶
func (s *ChatStream) Close() error
Close releases the underlying connection.
func (*ChatStream) Err ¶
func (s *ChatStream) Err() error
Err returns the first error encountered while streaming, if any.
func (*ChatStream) Metrics ¶ added in v0.3.0
func (s *ChatStream) Metrics() InferenceMetrics
Metrics reports performance characteristics of the stream so far. TokensPerSecond and TimeToFirstToken are approximate: they're derived from the number of non-empty content chunks and wall-clock time, since OpenAI-compatible streaming responses don't report per-chunk token counts.
func (*ChatStream) Next ¶
func (s *ChatStream) Next() bool
Next advances the stream. It returns false when the stream ends (check Err for failures).
type Client ¶
type Client struct {
System *SystemService
Memory *MemoryService
Optimize *OptimizeService
Runtime *RuntimeService
Models *ModelsService
// contains filtered or unexported fields
}
Client is the main entry point to the VeloxQuant Go SDK. Construct one with NewClient. Client is safe for concurrent use.
func NewClient ¶
NewClient constructs a VeloxQuant Client. By default it connects to a runtime at http://localhost:8765 with a 60s HTTP timeout; use the With* options to customize behavior.
func (*Client) AutoPilot ¶
AutoPilot inspects the host system, selects a compatible model and context length for the given task, chooses a VeloxQuant compression strategy, and returns a ready-to-use Session.
func (*Client) Chat ¶
func (c *Client) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
Chat sends a chat completion request to the configured runtime and returns the full response.
func (*Client) ChatStream ¶
func (c *Client) ChatStream(ctx context.Context, req ChatRequest) (*ChatStream, error)
ChatStream starts a streaming chat completion request.
func (*Client) Monitor ¶
func (c *Client) Monitor(opts ...MonitorOption) *monitor.Monitor
Monitor returns a Monitor sampling memory from this client's system detector at a periodic interval (5s by default; override with WithMonitorInterval). Between samples, any Chat or ChatStream call made through this Client also pushes a live update carrying that request's TokensPerSecond and TimeToFirstToken, merged onto the most recent memory sample — so subscribers see inference performance as it happens rather than waiting for the next tick.
type InferenceMetrics ¶
type InferenceMetrics struct {
TokensPerSecond float64 `json:"tokens_per_second"`
TimeToFirstToken time.Duration `json:"time_to_first_token"`
TotalDuration time.Duration `json:"total_duration"`
}
InferenceMetrics reports performance characteristics of a completed inference request.
type MemoryEstimate ¶
type MemoryEstimate struct {
ModelMemoryBytes uint64
KVCacheMemoryBytes uint64
RuntimeOverheadBytes uint64
TotalMemoryBytes uint64
OptimizedKVBytes uint64
OptimizedTotalBytes uint64
SavedBytes uint64
SavedPercent float64
RecommendedStrategy string
}
MemoryEstimate is the result of a memory estimation.
type MemoryRequest ¶
type MemoryRequest struct {
Model ModelArchitecture
ContextLength int
Precision Precision
}
MemoryRequest describes a memory estimation query.
type MemoryService ¶
type MemoryService struct {
// contains filtered or unexported fields
}
MemoryService exposes model and KV-cache memory estimation.
func (*MemoryService) Estimate ¶
func (m *MemoryService) Estimate(ctx context.Context, req MemoryRequest) (MemoryEstimate, error)
Estimate computes memory requirements for a model at a given context length and precision.
type ModelArchitecture ¶
type ModelArchitecture = memory.Architecture
ModelArchitecture re-exports memory.Architecture at the top level.
type ModelRecommendationRequest ¶
type ModelRecommendationRequest struct {
Task string
AvailableMemoryBytes uint64
ContextLength int
}
ModelRecommendationRequest describes a model recommendation query.
type ModelsService ¶
type ModelsService struct {
// contains filtered or unexported fields
}
ModelsService exposes the VeloxQuant model registry.
func (*ModelsService) List ¶
func (m *ModelsService) List() []models.Info
List returns all known models.
func (*ModelsService) Recommend ¶
func (m *ModelsService) Recommend(ctx context.Context, req ModelRecommendationRequest) ([]models.Info, error)
Recommend returns models suited to the requested task that fit within AvailableMemoryBytes, ranked best first.
func (*ModelsService) RecommendScored ¶ added in v0.3.0
func (m *ModelsService) RecommendScored(ctx context.Context, req ModelRecommendationRequest) ([]models.Scored, error)
RecommendScored behaves like Recommend but also returns the score and human-readable reasoning behind each candidate's ranking.
type MonitorConfig ¶ added in v0.3.0
type MonitorConfig struct {
// contains filtered or unexported fields
}
MonitorConfig configures a Monitor returned by Client.Monitor.
type MonitorOption ¶ added in v0.3.0
type MonitorOption func(*MonitorConfig)
MonitorOption configures a Monitor. Use the WithMonitor* functions to build options.
func WithMonitorInterval ¶ added in v0.3.0
func WithMonitorInterval(interval time.Duration) MonitorOption
WithMonitorInterval sets how often the Monitor samples system memory. Defaults to 5 seconds.
type OptimizationRecommendation ¶
type OptimizationRecommendation struct {
Profile optimize.Profile
CompressionMethod string
CompressionBits int
EstimatedMemoryBefore uint64
EstimatedMemoryAfter uint64
ContextLength int
Reason string
}
OptimizationRecommendation is VeloxQuant's suggested optimization strategy for a model/context combination.
type OptimizationRequest ¶
type OptimizationRequest struct {
Model string
Architecture ModelArchitecture
ContextLength int
}
OptimizationRequest describes an optimization recommendation query.
type OptimizeService ¶
type OptimizeService struct {
// contains filtered or unexported fields
}
OptimizeService exposes VeloxQuant optimization profile recommendations.
func (*OptimizeService) Recommend ¶
func (o *OptimizeService) Recommend(ctx context.Context, req OptimizationRequest) (OptimizationRecommendation, error)
Recommend returns VeloxQuant's recommended optimization strategy for the given model and context length.
type Option ¶
type Option func(*config)
Option configures a Client. Use the With* functions to build options.
func WithAutoDetect ¶
func WithAutoDetect() Option
WithAutoDetect enables automatic hardware detection and profile selection when the Client is constructed.
func WithHTTPTimeout ¶
WithHTTPTimeout sets the timeout used for HTTP requests to the runtime.
func WithOpenAICompatibleRuntime ¶
WithOpenAICompatibleRuntime configures the client to send chat requests to an OpenAI-compatible endpoint (e.g. "http://localhost:8765/v1") instead of the native VeloxQuant runtime API.
func WithProfile ¶
WithProfile forces a specific VeloxQuant optimization profile rather than letting the SDK choose one automatically.
func WithRuntimeURL ¶
WithRuntimeURL sets the base URL of the VeloxQuant runtime. Defaults to http://localhost:8765.
type Precision ¶
Precision re-exports memory.Precision at the top level so callers don't need to import the memory subpackage for common usage.
type RuntimeService ¶
type RuntimeService struct {
// contains filtered or unexported fields
}
RuntimeService exposes communication with a local VeloxQuant runtime.
func (*RuntimeService) Health ¶
func (r *RuntimeService) Health(ctx context.Context) (RuntimeStatus, error)
Health checks whether the VeloxQuant runtime is reachable and healthy.
type RuntimeStatus ¶
RuntimeStatus describes the health of a VeloxQuant runtime instance.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a ready-to-use AI session produced by AutoPilot, bound to a specific model and optimization plan.
func (*Session) Plan ¶
func (s *Session) Plan() AutoPilotPlan
Plan returns the decisions AutoPilot made to construct this Session.
type SystemInfo ¶
type SystemInfo struct {
Platform string
Architecture string
CPUModel string
AppleSilicon bool
TotalMemory uint64
AvailableMemory uint64
RecommendedProfile string
}
SystemInfo describes the host system relevant to running local LLM inference.
type SystemService ¶
type SystemService struct {
// contains filtered or unexported fields
}
SystemService exposes hardware and platform detection.
func (*SystemService) Info ¶
func (s *SystemService) Info(ctx context.Context) (SystemInfo, error)
Info returns details about the host system.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vq
command
Command vq is the VeloxQuant CLI: hardware diagnostics, model memory analysis, optimization recommendations, benchmarking, and a local runtime bridge.
|
Command vq is the VeloxQuant CLI: hardware diagnostics, model memory analysis, optimization recommendations, benchmarking, and a local runtime bridge. |
|
examples
|
|
|
autopilot
command
Example: letting AutoPilot select a model, context length, and compression strategy based on detected hardware.
|
Example: letting AutoPilot select a model, context length, and compression strategy based on detected hardware. |
|
chat
command
Example: a single chat completion request against a local VeloxQuant runtime.
|
Example: a single chat completion request against a local VeloxQuant runtime. |
|
server
command
Example: building a small HTTP service on top of the VeloxQuant Go SDK, exposing memory estimation and chat as JSON endpoints.
|
Example: building a small HTTP service on top of the VeloxQuant Go SDK, exposing memory estimation and chat as JSON endpoints. |
|
streaming
command
Example: streaming a chat completion token-by-token.
|
Example: streaming a chat completion token-by-token. |
|
internal
|
|
|
httpclient
Package httpclient provides a small, shared HTTP client wrapper used by the runtime and openai packages: context-aware requests, JSON encoding helpers, and typed error responses.
|
Package httpclient provides a small, shared HTTP client wrapper used by the runtime and openai packages: context-aware requests, JSON encoding helpers, and typed error responses. |
|
langchain
module
|
|
|
mcp
module
|
|
|
Package memory implements VeloxQuant's memory intelligence: estimating how much RAM a model and its KV cache will need, and how much VeloxQuant compression can save.
|
Package memory implements VeloxQuant's memory intelligence: estimating how much RAM a model and its KV cache will need, and how much VeloxQuant compression can save. |
|
Package models provides a curated registry of known local LLMs and task-based recommendations.
|
Package models provides a curated registry of known local LLMs and task-based recommendations. |
|
Package monitor provides thread-safe, subscribable monitoring of memory and inference metrics.
|
Package monitor provides thread-safe, subscribable monitoring of memory and inference metrics. |
|
Package openai implements a minimal client for OpenAI-compatible chat completion APIs, used to talk to the VeloxQuant runtime (or any other OpenAI-compatible local server).
|
Package openai implements a minimal client for OpenAI-compatible chat completion APIs, used to talk to the VeloxQuant runtime (or any other OpenAI-compatible local server). |
|
Package optimize provides VeloxQuant optimization profile selection and compression recommendations for a given model and context length.
|
Package optimize provides VeloxQuant optimization profile selection and compression recommendations for a given model and context length. |
|
Package runtime implements the HTTP client used to communicate with a local VeloxQuant runtime process (typically at http://localhost:8765).
|
Package runtime implements the HTTP client used to communicate with a local VeloxQuant runtime process (typically at http://localhost:8765). |
|
Package system provides hardware and platform detection for VeloxQuant, including Apple Silicon detection and system memory inspection.
|
Package system provides hardware and platform detection for VeloxQuant, including Apple Silicon detection and system memory inspection. |