brain

package
v0.0.0-...-2e5d07d Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Learn

func Learn(ctx context.Context, l Interface, tag string, msg *Message) error

Learn records a message into a brain.

func Recall

func Recall(ctx context.Context, br Interface, tag string) iter.Seq2[Message, error]

Recall iterates over all messages a brain knows with a given tag.

func Think

func Think(ctx context.Context, s Interface, tag, prompt string) (string, []string, error)

Think produces a new message and the trace of message IDs used to form it from the given prompt. If the brain does not produce any terms, the result is the empty string regardless of the prompt, with no error.

Types

type Interface

type Interface interface {
	// Learn records a set of tuples.
	//
	// One tuple has an empty prefix to denote the start of the message, and
	// a different tuple has the empty string as its suffix to denote the end
	// of the message. The positions of each in the argument are not guaranteed.
	//
	// Tuples in the argument may share storage for prefixes.
	Learn(ctx context.Context, tag string, msg *Message, tuples []Tuple) error

	// Think iterates all suffixes matching a prefix.
	//
	// Yielded closures replace id and suffix with successive messages' contents.
	// The iterating loop may not call the yielded closure on every iteration.
	// When it does, it uses the closure fully within each loop, allowing the
	// sequence to yield the same closure on each call.
	// Conversely, iterators should expect that the arguments to the closure
	// will be the same on each iteration and must not retain them.
	Think(ctx context.Context, tag string, prefix []string) iter.Seq[func(id, suf *[]byte) error]

	// Forget forgets everything learned from a single given message.
	// If nothing has been learned from the message, it must prevent anything
	// from being learned from a message with that ID.
	Forget(ctx context.Context, tag, id string) error

	// Recall reads out messages the brain knows.
	// At minimum, the message ID and text of each message must be retrieved;
	// other fields may be filled if they are available.
	//
	// Repeated calls using the pagination token returned from the previous
	// must yield every message that the brain had recorded at the time of the
	// first call exactly once. Messages learned after the first call of an
	// enumeration are read at most once.
	//
	// The first call of an enumeration uses an empty pagination token as input.
	// If the returned pagination token is empty, it is interpreted as the end
	// of the enumeration.
	Recall(ctx context.Context, tag, page string, out []Message) (n int, next string, err error)
}

Interface is a store of learned messages which can reproduce them by parts.

It must be safe to call all methods of a brain concurrently with each other.

type Message

type Message = message.Received[userhash.Hash]

Message is the message type used by a Interface.

type Tuple

type Tuple struct {
	// Prefix is the entropy-reduced prefix in reverse order relative to the
	// source message.
	Prefix []string
	// Suffix is the full-entropy term following the prefix.
	Suffix string
}

Tuple is a single Markov chain tuple.

Directories

Path Synopsis
Package braintest provides integration testing facilities for brains.
Package braintest provides integration testing facilities for brains.

Jump to

Keyboard shortcuts

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