storetest

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package storetest is the contract every brain store must meet. Run it from a store's own tests (MemoryStore and postgres.Store do), so a new store or store method cannot ship without the same tenant, tree and search rules.

Two tenants share one store. Each case asserts what a caller gets under its own scope: its own rows, ErrNotFound for another tenant's ids, and an error for an empty scope. A store owns its embedding, so the contract hands newStore the Embedder a case needs (nil: lexical only).

Index

Constants

View Source
const Dimension = 3

Dimension is the length of every vector Embedder returns.

Variables

This section is empty.

Functions

func Filter

func Filter(t testing.TB, m map[string]any) brain.Filter

Filter decodes m into a filter, failing the test when it is invalid.

func Kind

func Kind(ctx context.Context, s brain.Store, name string) (brain.ObjectKind, error)

Kind is the registered kind named name in s, or brain.ErrNotFound.

func Namespace

func Namespace(t testing.TB, nv ...string) brain.Namespace

Namespace parses nv into a namespace, failing the test when it is invalid.

func Put

func Put(s brain.Store, obj brain.Object) error

Put writes obj straight to s under obj's own namespace, indexed by its text.

func Run

func Run(t *testing.T, newStore func(t *testing.T, emb brain.Embedder) brain.Store)

Run runs the contract. newStore returns an empty store for each case, which embeds with emb (nil: lexical only).

Types

type Embedder

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

Embedder embeds a text as the vector of the first word of a synonym group in it (car and automobile share one vector, banana and fruit another; anything else is a third), counts every text it embeds, and fails on a text with the word poison.

func (*Embedder) Embed

func (e *Embedder) Embed(_ context.Context, texts []string) ([][]float32, error)

Embed implements brain.Embedder.

func (*Embedder) Model

func (*Embedder) Model() string

Model implements brain.Embedder.

func (*Embedder) Take

func (e *Embedder) Take() int

Take is the texts embedded since the last Take, and starts the count again.

func (*Embedder) Texts

func (e *Embedder) Texts() int

Texts is how many texts e has embedded.

Jump to

Keyboard shortcuts

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