Documentation
¶
Overview ¶
Package cache decorates an embedding.Embedder with an explicit, caller-owned Store. It caches individual input vectors while preserving embedding batch order and resolved model identity.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNilEmbedder indicates that New received a nil Embedder. ErrNilEmbedder = errors.New("nil embedder") // ErrNilStore indicates that New received a nil Store. ErrNilStore = errors.New("nil store") // ErrInvalidIdentity indicates that New received a blank cache identity. ErrInvalidIdentity = errors.New("invalid cache identity") // ErrModelMismatch indicates that entries in one batch resolve to different models. ErrModelMismatch = errors.New("embedding model mismatch") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Identity namespaces entries by the caller-owned embedding-output contract.
Identity string
}
Config configures an Embedder.
type Embedder ¶
type Embedder struct {
// contains filtered or unexported fields
}
Embedder decorates a base embedding.Embedder with a caller-provided Store. Its state is immutable after construction.
func New ¶
New constructs a Store-backed decorator without performing dependency I/O.
Example ¶
package main
import (
"context"
"fmt"
"github.com/dotcommander/reliquary/embedding"
"github.com/dotcommander/reliquary/embedding/cache"
)
func main() {
base := exampleEmbedder{}
store := &exampleStore{entries: make(map[string]cache.Entry)}
cached, err := cache.New(base, store, cache.Config{Identity: "example:v1"})
if err != nil {
panic(err)
}
result, err := cached.Embed(context.Background(), embedding.Request{Inputs: []string{"hello"}})
fmt.Println(err == nil, result.Model.Name, len(result.Vectors))
}
type exampleEmbedder struct{}
func (exampleEmbedder) Embed(_ context.Context, request embedding.Request) (embedding.Result, error) {
vectors := make([]embedding.Vector, len(request.Inputs))
for index, input := range request.Inputs {
vectors[index] = embedding.Vector{float32(len(input))}
}
return embedding.Result{Model: embedding.ModelRef{Name: "example", Dim: 1}, Vectors: vectors}, nil
}
type exampleStore struct {
entries map[string]cache.Entry
}
func (s *exampleStore) Get(_ context.Context, key string) (cache.Entry, bool, error) {
entry, ok := s.entries[key]
return entry, ok, nil
}
func (s *exampleStore) Set(_ context.Context, key string, entry cache.Entry) error {
s.entries[key] = entry
return nil
}
Output: true example 1
Click to show internal directories.
Click to hide internal directories.