Versions in this module Expand all Collapse all v2 v2.2.0 Nov 4, 2026 Changes in this version + const CredentialName + const DefaultBaseURL + const DefaultBatchSize + const DefaultDailyTokenCap + const DefaultDimensions + const DefaultMinScore + const DefaultModel + const DefaultTimeoutSeconds + const MaxBatchSize + const MaxCurrencyLen + const MaxDailyTokenCap + const MaxDimensions + const MaxKeyLen + const MaxMinScore + const MaxPricePerMillion + const MaxTimeoutSeconds + const MinDailyTokenCap + const MinDimensions + const MinKeyLen + const MinMinScore + const MinTimeoutSeconds + const TestSentence + var ErrBadMasterKey = errors.New("主密钥文件内容无效") + var ErrBudgetExceeded = errors.New("今日 token 预算已用完") + var ErrInvalidConfig = errors.New("语义检索配置不合法") + var ErrKeyNotReady = errors.New("API Key 不可用") + var ErrNoMasterKey = errors.New("主密钥文件不存在") + var ErrThrottled = errors.New("测试过于频繁,请稍等几秒再试") + var ErrVaultUnavailable = errors.New("当前运行方式没有持久数据目录,无法保存密钥") + func BoundHost(u *url.URL) string + func EstimateTokens(inputs []string) int + func LastFour(key string) string + func ParseBaseURL(raw string, allowPrivate bool) (*url.URL, error) + func ValidateAPIKey(raw string) (string, error) + type CallError struct + Kind ErrKind + Message string + RetryAfter time.Duration + Status int + func (e *CallError) Error() string + func (e *CallError) Retryable() bool + type Client struct + func NewClient(cfg Config, key, userAgent string) (*Client, error) + func (c *Client) Embed(ctx context.Context, inputs []string) (*EmbedResult, error) + type Config struct + AllowPrivate bool + BaseURL string + BatchSize int + DailyTokenCap int64 + Dimensions int + MinScore float64 + Model string + PriceCurrency string + PricePerMillion float64 + TimeoutSeconds int + func DefaultConfig() Config + func (c Config) Normalize() Config + func (c Config) Validate() error + type Credential struct + BoundHost string + Last4 string + Name string + Sealed string + UpdatedAt time.Time + type EmbedResult struct + Dimensions int + Latency time.Duration + Model string + Reported bool + Status int + Tokens int + Vectors [][]float32 + type ErrKind string + const KindAuth + const KindBadRequest + const KindBadResponse + const KindBlocked + const KindCanceled + const KindNetwork + const KindNotFound + const KindRateLimited + const KindRedirect + const KindServer + const KindTLS + const KindTimeout + type GuardView struct + Mode string + type KeyState string + const KeyHostMismatch + const KeyNone + const KeyOK + const KeyUnreadable + type KeyView struct + BoundHost string + HasKey bool + Last4 string + Reason string + State KeyState + UpdatedAt *time.Time + VaultAvailable bool + type Limits struct + MaxBatchSize int + MaxCurrencyLen int + MaxDailyTokenCap int64 + MaxDimensions int + MaxKeyLen int + MaxMinScore float64 + MaxPricePerMillion float64 + MaxTimeoutSeconds int + MinDailyTokenCap int64 + MinDimensions int + MinKeyLen int + MinMinScore float64 + MinTimeoutSeconds int + func DefaultLimits() Limits + type Options struct + DataDir string + Now func() time.Time + Persistence Persistence + TestInterval time.Duration + UserAgent string + type Persistence interface + DeleteEmbeddingCredential func(ctx context.Context) error + EmbeddingUsageDays func(ctx context.Context, fromDay, toDay string) ([]UsageDay, error) + EmbeddingUsageTotals func(ctx context.Context) (UsageTotals, error) + GetEmbeddingConfig func(ctx context.Context) (Config, error) + GetEmbeddingCredential func(ctx context.Context) (Credential, bool, error) + PutEmbeddingCredential func(ctx context.Context, c Credential) error + ReserveEmbeddingTokens func(ctx context.Context, day string, estimate, cap int64) (bool, error) + SettleEmbeddingTokens func(ctx context.Context, day string, estimate, actual int64, failed bool) error + UpdateEmbeddingConfig func(ctx context.Context, mutate func(Config) Config, validate func(Config) error) (Config, error) + type Service struct + func NewService(o Options) *Service + func (s *Service) ClearKey(ctx context.Context) (View, error) + func (s *Service) Embed(ctx context.Context, inputs []string) (*EmbedResult, error) + func (s *Service) SetKey(ctx context.Context, raw string) (View, error) + func (s *Service) Status(ctx context.Context) (View, error) + func (s *Service) Test(ctx context.Context, draft *Update) (TestResult, error) + func (s *Service) UpdateConfig(ctx context.Context, upd Update) (View, error) + func (s *Service) Usage(ctx context.Context, days int) ([]UsageDay, error) + type TestResult struct + Dimensions int + HTTPStatus int + Host string + Kind string + LatencyMS int64 + Message string + Model string + OK bool + Tokens int + Warning string + type Update struct + AllowPrivate *bool + BaseURL *string + BatchSize *int + DailyTokenCap *int64 + Dimensions *int + MinScore *float64 + Model *string + PriceCurrency *string + PricePerMillion *float64 + TimeoutSeconds *int + func (u Update) ApplyTo(cur Config) Config + type UsageDay struct + Day string + Errors int64 + Requests int64 + Tokens int64 + type UsageTotals struct + Errors int64 + Requests int64 + Tokens int64 + type UsageView struct + Cap int64 + Day string + Remaining *int64 + Today UsageDay + Totals UsageTotals + type Vault struct + func NewVault(dir string) *Vault + func (v *Vault) Available() bool + func (v *Vault) Open(sealed, boundHost string) (string, error) + func (v *Vault) Seal(plain, boundHost string) (string, error) + type View struct + Config Config + Defaults Config + Guard GuardView + Key KeyView + Limits Limits + Usage UsageView