Documentation
¶
Overview ¶
Package cache owns response-cache eligibility, semantic identity, versioned canonical records, and stream replay.
Index ¶
- Constants
- Variables
- func ChatKey(identity ChatIdentity) (string, error)
- func CompleteStream(events []inference.StreamEvent) (inference.ChatResponse, error)
- func EmbeddingKey(identity EmbeddingIdentity) (string, error)
- func StreamEvents(response inference.ChatResponse, options inference.StreamOptions) ([]inference.StreamEvent, error)
- type ChatIdentity
- type Clock
- type EmbeddingIdentity
- type Policy
- type ProviderPolicy
- type Repository
- type Store
- type TenantPolicy
Constants ¶
const RecordSchemaVersion = 1
RecordSchemaVersion identifies the canonical response-cache record schema.
const SemanticKeyVersion = 2
SemanticKeyVersion identifies the canonical cache-identity encoding.
Variables ¶
var ( // ErrIneligible reports a request whose identity is not cache-safe. ErrIneligible = errors.New("request is not eligible for response caching") // ErrTenantRequired reports a request without tenant identity. ErrTenantRequired = errors.New("cache tenant ID is required") // ErrGenerationRequired reports a request without catalog identity. ErrGenerationRequired = errors.New("catalog generation ID is required") // ErrMutableImage reports a remote image that can change without a new key. ErrMutableImage = errors.New("remote image input is mutable") // ErrUnknownExtension reports provider semantics outside the canonical identity. ErrUnknownExtension = errors.New("provider extension semantics are not cache-safe") // ErrInvalidJSONContract reports an invalid tool or output schema. ErrInvalidJSONContract = errors.New("request JSON contract is invalid") )
var ( // ErrStoreRequired reports an absent response-cache byte store. ErrStoreRequired = errors.New("response-cache store is required") // ErrCorruptRecord reports invalid durable response-cache data. ErrCorruptRecord = errors.New("response-cache record is invalid") // ErrKindMismatch reports a record payload that does not match its kind. ErrKindMismatch = errors.New("response-cache record kind does not match") )
var ( // ErrNoStreamEvents reports an empty canonical event sequence. ErrNoStreamEvents = errors.New("stream has no canonical events") // ErrUnsupportedContent reports content that canonical replay cannot represent. ErrUnsupportedContent = errors.New("cached stream content is not text") )
Functions ¶
func ChatKey ¶
func ChatKey(identity ChatIdentity) (string, error)
ChatKey returns the versioned semantic key for an eligible chat request.
func CompleteStream ¶
func CompleteStream(events []inference.StreamEvent) (inference.ChatResponse, error)
CompleteStream builds one canonical completed result from stream events.
func EmbeddingKey ¶
func EmbeddingKey(identity EmbeddingIdentity) (string, error)
EmbeddingKey returns the versioned semantic key for an eligible embedding request.
func StreamEvents ¶
func StreamEvents(response inference.ChatResponse, options inference.StreamOptions) ([]inference.StreamEvent, error)
StreamEvents reconstructs canonical stream events from a completed result.
Types ¶
type ChatIdentity ¶
type ChatIdentity struct {
TenantID string
CatalogGeneration string
Request inference.ChatRequest
Policy Policy
}
ChatIdentity contains all semantic inputs for one chat cache entry.
type EmbeddingIdentity ¶
type EmbeddingIdentity struct {
TenantID string
CatalogGeneration string
Request inference.EmbeddingRequest
Policy Policy
}
EmbeddingIdentity contains all semantic inputs for one embedding cache entry.
type Policy ¶
type Policy struct {
Provider ProviderPolicy `json:"provider"`
Tenant TenantPolicy `json:"tenant"`
}
Policy contains all routing policy that can change a response.
type ProviderPolicy ¶
type ProviderPolicy struct {
Order []string `json:"order,omitempty"`
Only []string `json:"only,omitempty"`
Ignore []string `json:"ignore,omitempty"`
AllowFallbacks bool `json:"allow_fallbacks"`
Route string `json:"route,omitempty"`
ModelOverrides map[string]string `json:"model_overrides,omitempty"`
}
ProviderPolicy contains request-scoped provider routing semantics.
type Repository ¶
type Repository interface {
GetChat(context.Context, string) (inference.ChatResponse, time.Time, bool, error)
PutChat(context.Context, string, inference.ChatResponse) error
GetEmbedding(context.Context, string) (inference.EmbeddingResponse, time.Time, bool, error)
PutEmbedding(context.Context, string, inference.EmbeddingResponse) error
}
Repository stores versioned canonical inference results.
type Store ¶
type Store interface {
GetResponse(context.Context, string) ([]byte, bool, error)
SetResponse(context.Context, string, []byte) error
}
Store is the byte-cache contract required by the repository.
type TenantPolicy ¶
type TenantPolicy struct {
AllowedModels []string `json:"allowed_models,omitempty"`
AllowedProviders []string `json:"allowed_providers,omitempty"`
RateLimitTier string `json:"rate_limit_tier,omitempty"`
CredentialStrategy string `json:"credential_strategy,omitempty"`
}
TenantPolicy contains tenant-scoped route restrictions.