v0.7.0

store Expiration, Vectors, and Types

Last updated

This page lists the core/store expiration and vector methods and the exported Entry, ValueType, and AOFRecord types.

Expiration

func (c *core) TTL(key string) int64
func (c *core) Expire(key string, seconds int64) error
func (c *core) ExpireAt(key string, timestamp int64) error
func (c *core) Persist(key string) error

TTL returns -2 when missing or expired and -1 without expiry.

Vectors

var ErrNoEmbedder = errors.New("no embedder: OPENAI_API_KEY not provided")

func (c *core) VSearch(ctx context.Context, text, pattern string, k int) ([]string, error)
func (c *core) VSim(key1, key2 string) (float64, error)
func (c *core) VGet(key string) ([]float32, bool)

Entry and Record Types

type Entry struct {
    Key       string    `json:"key"`
    Type      ValueType `json:"type"`
    CreatedAt int64     `json:"created_at"`
    UpdatedAt *int64    `json:"updated_at,omitempty"`
    ExpireAt  *int64    `json:"expire_at,omitempty"`
    Vector    []float32 `json:"vector,omitempty"`
}

func (e *Entry) Value() string

type ValueType int
const (
    TypeJSON ValueType = iota
    TypeString
    TypeInt
    TypeFloat
    TypeBool
    TypeDate
)
func (t ValueType) String() string

type AOFRecord struct {
    Timestamp int64   `json:"ts"`
    Command   string  `json:"cmd"`
    Key       string  `json:"key"`
    Value     string  `json:"value,omitempty"`
    ExpireAt  *int64  `json:"expire_at,omitempty"`
    Vector    *string `json:"vector,omitempty"`
}
中文