inmem

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 5 Imported by: 0

README

embedding/cache/inmem

store := inmem.New()
cached, err := embeddingcache.New(base, store, embeddingcache.Config{
	Identity: "openai:text-embedding-3-small:1536:input-v1",
})

embedding/cache/inmem is a concurrency-safe, process-local implementation of cache.Store. It clones vectors on writes and reads so callers, the decorator, and the Store do not share mutable backing arrays. The zero Store value is ready to use.

Entries live only for the lifetime of the Store. The package provides no TTL, eviction, capacity limit, persistence, statistics, or lifecycle methods.

Documentation

Overview

Package inmem provides a concurrency-safe, process-local implementation of cache.Store. The zero Store value is ready to use.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store keeps embedding cache entries in process memory. It is safe for concurrent use, and its zero value is ready to use.

func New

func New() *Store

New constructs an empty Store.

Example
package main

import (
	"context"
	"fmt"

	"github.com/dotcommander/reliquary/embedding"
	"github.com/dotcommander/reliquary/embedding/cache"
	"github.com/dotcommander/reliquary/embedding/cache/inmem"
)

func main() {
	store := inmem.New()
	entry := cache.Entry{
		Model:  embedding.ModelRef{Name: "example", Dim: 2},
		Vector: embedding.Vector{1, 2},
	}
	if err := store.Set(context.Background(), "key", entry); err != nil {
		panic(err)
	}

	got, ok, err := store.Get(context.Background(), "key")
	fmt.Println(ok, err == nil, got.Model.Name, got.Vector)
}
Output:
true true example [1 2]

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (cache.Entry, bool, error)

Get returns an isolated copy of the entry stored under key.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, entry cache.Entry) error

Set stores an isolated copy of entry under key, replacing any prior value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL