session

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSpaceUnknown   = errors.New("space not registered")
	ErrSpaceExpired   = errors.New("space expired")
	ErrSpaceForbidden = errors.New("space access denied")
)

Errors returned by the space registry.

Functions

This section is empty.

Types

type MemoryBank

type MemoryBank struct {
	Store store.VectorStore
}

MemoryBank is a thin wrapper around a VectorStore implementation.

func NewMemoryBank

func NewMemoryBank(ctx context.Context, connStr string) (*MemoryBank, error)

NewMemoryBank creates a new Postgres-backed memory bank.

func NewMemoryBankWithStore

func NewMemoryBankWithStore(s store.VectorStore) *MemoryBank

NewMemoryBankWithStore creates a memory bank backed by a custom vector store implementation.

func (*MemoryBank) Close

func (mb *MemoryBank) Close() error

Close releases underlying resources if the store implements io.Closer.

func (*MemoryBank) CreateSchema

func (mb *MemoryBank) CreateSchema(ctx context.Context, schemaPath string) error

CreateSchema initialises the backing store if it supports schema management.

func (*MemoryBank) SearchMemory

func (mb *MemoryBank) SearchMemory(ctx context.Context, sessionID string, queryEmbedding []float32, limit int) ([]model.MemoryRecord, error)

SearchMemory returns top-k similar memories

func (*MemoryBank) StoreMemory

func (mb *MemoryBank) StoreMemory(ctx context.Context, sessionID, content, metadata string, embedding []float32) error

StoreMemory inserts a long-term record

type SessionMemory

type SessionMemory struct {
	Bank *MemoryBank

	Embedder embed.Embedder
	Engine   *memengine.Engine
	Spaces   *SpaceRegistry
	// contains filtered or unexported fields
}

SessionMemory wraps MemoryBank with short- and long-term layers including a configurable short-term buffer and embedding provider.

func NewSessionMemory

func NewSessionMemory(bank *MemoryBank, shortTermSize int) *SessionMemory

NewSessionMemory wraps MemoryBank with short-term cache

func (*SessionMemory) AddShortTerm

func (sm *SessionMemory) AddShortTerm(sessionID, content, metadata string, embedding []float32)

AddShortTerm stores in ephemeral session cache

func (*SessionMemory) Embed

func (sm *SessionMemory) Embed(ctx context.Context, text string) ([]float32, error)

Embed ensures an embedder is available and returns the embedding for the text.

func (*SessionMemory) ExportShortTerm added in v1.10.3

func (sm *SessionMemory) ExportShortTerm() map[string][]model.MemoryRecord

ExportShortTerm returns a snapshot of the in-memory short-term history.

func (*SessionMemory) FlushToLongTerm

func (sm *SessionMemory) FlushToLongTerm(ctx context.Context, sessionID string) error

FlushToLongTerm writes the short-term cache to the configured vector store.

func (*SessionMemory) ImportShortTerm added in v1.10.3

func (sm *SessionMemory) ImportShortTerm(data map[string][]model.MemoryRecord)

ImportShortTerm overwrites the in-memory short-term history with the provided data.

func (*SessionMemory) RetrieveContext

func (sm *SessionMemory) RetrieveContext(ctx context.Context, sessionID, query string, limit int) ([]model.MemoryRecord, error)

RetrieveContext returns combined short- and long-term memory

func (*SessionMemory) WithEmbedder

func (sm *SessionMemory) WithEmbedder(e embed.Embedder) *SessionMemory

WithEmbedder overrides the embedder used by the session memory.

func (*SessionMemory) WithEngine

func (sm *SessionMemory) WithEngine(e *memengine.Engine) *SessionMemory

WithEngine attaches an advanced memory engine for long-term storage and retrieval.

type SharedSession

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

func NewSharedSession

func NewSharedSession(base *SessionMemory, local string, spaces ...string) *SharedSession

NewSharedSession binds a local sessionID and optional initial shared spaces.

func (*SharedSession) AddShortLocal

func (ss *SharedSession) AddShortLocal(content string, metadata map[string]string)

AddShortLocal appends a short-term memory to the *local* session buffer.

func (*SharedSession) AddShortTo

func (ss *SharedSession) AddShortTo(space, content string, metadata map[string]string) error

AddShortTo writes a short-term memory directly into a shared space buffer.

func (*SharedSession) BroadcastLong

func (ss *SharedSession) BroadcastLong(ctx context.Context, content string, metadata map[string]any) ([]model.MemoryRecord, error)

BroadcastLong writes a long-term memory to the local session and all spaces.

func (*SharedSession) ExportJoinedSpaces added in v1.10.3

func (ss *SharedSession) ExportJoinedSpaces() []string

ExportJoinedSpaces returns the list of currently joined shared spaces.

func (*SharedSession) FlushLocal

func (ss *SharedSession) FlushLocal(ctx context.Context) error

FlushLocal promotes the local short-term buffer to long-term storage.

func (*SharedSession) FlushSpace

func (ss *SharedSession) FlushSpace(ctx context.Context, space string) error

FlushSpace promotes a shared space short-term buffer to long-term.

func (*SharedSession) ImportJoinedSpaces added in v1.10.3

func (ss *SharedSession) ImportJoinedSpaces(spaces []string)

ImportJoinedSpaces restores the list of joined shared spaces.

func (*SharedSession) Join

func (ss *SharedSession) Join(space string) error

Join adds a shared space (sessionID) to the view.

func (*SharedSession) Leave

func (ss *SharedSession) Leave(space string)

Leave removes a shared space (sessionID) from the view.

func (*SharedSession) Retrieve

func (ss *SharedSession) Retrieve(ctx context.Context, query string, limit int) ([]model.MemoryRecord, error)

Retrieve merges short-term (local + spaces) and filtered long-term results. Long-term retrieval oversamples then filters to the allowed sessionIDs.

func (*SharedSession) RetrieveShared

func (ss *SharedSession) RetrieveShared(ctx context.Context, query string, limit int) ([]model.MemoryRecord, error)

RetrieveShared returns only joined shared spaces (excludes local).

func (*SharedSession) Spaces

func (ss *SharedSession) Spaces() []string

Spaces returns the current list of shared spaces.

func (*SharedSession) StoreLongTo

func (ss *SharedSession) StoreLongTo(ctx context.Context, sessionID, content string, metadata map[string]any) (model.MemoryRecord, error)

StoreLongTo writes a long-term memory directly to a specific session/space. If Engine is configured it will be used; otherwise we fall back to Bank + Embed.

type Space

type Space struct {
	Name      string
	ACL       map[string]SpaceRole
	ExpiresAt time.Time
	CreatedAt time.Time
	UpdatedAt time.Time
}

Space represents a collaborative memory namespace shared across sessions.

type SpaceRegistry

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

SpaceRegistry keeps track of collaborative memory spaces, their ACLs and TTLs.

func NewSpaceRegistry

func NewSpaceRegistry(defaultTTL time.Duration) *SpaceRegistry

NewSpaceRegistry builds an empty registry with the provided default TTL.

func (*SpaceRegistry) CanRead

func (sr *SpaceRegistry) CanRead(spaceName, principal string) bool

CanRead reports whether the principal has read access to the space.

func (*SpaceRegistry) CanWrite

func (sr *SpaceRegistry) CanWrite(spaceName, principal string) bool

CanWrite reports whether the principal has write access to the space.

func (*SpaceRegistry) Check

func (sr *SpaceRegistry) Check(spaceName, principal string, requireWrite bool) error

Check enforces access and returns explicit errors.

func (*SpaceRegistry) Grant

func (sr *SpaceRegistry) Grant(spaceName, principal string, role SpaceRole, ttl time.Duration) error

Grant assigns or updates a role for a principal inside a space.

func (*SpaceRegistry) List

func (sr *SpaceRegistry) List(principal string) []string

List returns active spaces the principal can read.

func (*SpaceRegistry) Prune

func (sr *SpaceRegistry) Prune() []string

Prune removes expired spaces.

func (*SpaceRegistry) Revoke

func (sr *SpaceRegistry) Revoke(spaceName, principal string)

Revoke removes a principal from the space ACL.

func (*SpaceRegistry) Upsert

func (sr *SpaceRegistry) Upsert(name string, ttl time.Duration, acl map[string]SpaceRole) *Space

Upsert creates or updates a space definition.

type SpaceRole

type SpaceRole string

SpaceRole defines the access level granted to a principal within a shared space.

const (
	SpaceRoleReader SpaceRole = "reader"
	SpaceRoleWriter SpaceRole = "writer"
	SpaceRoleAdmin  SpaceRole = "admin"
)

Jump to

Keyboard shortcuts

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