memory

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package memory implements the v0.1 Memory decision chain (ADR-009): the canonical store lives in PostgreSQL (FTS + pg_trgm + pgvector share the transaction system), embeddings are produced by a pluggable Embedder, and retrieval filters tenant/sensitivity before scoring. Deletion is a tombstone (deletion intent survives; projections can rebuild).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DevEmbedder

type DevEmbedder struct{}

DevEmbedder produces a deterministic, normalized 384-dimension vector from the content hash. It exists so the full pipeline (store, FTS/vector hybrid retrieval, control API) runs without an external embedding service; it must not be used where semantic similarity matters.

func (DevEmbedder) Embed

func (DevEmbedder) Embed(_ context.Context, content string) ([]float32, error)

type Embedder

type Embedder interface {
	Embed(context.Context, string) ([]float32, error)
}

Embedder turns memory content into the canonical vector space. The dev embedder is deterministic but semantically meaningless; production deployments plug a real embedding service behind this interface.

type Gateway

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

Gateway orchestrates memory writes and retrieval: it embeds content, validates the decision inputs and delegates persistence to the canonical store.

func NewGateway

func NewGateway(embedder Embedder, memories store.MemoryStore) *Gateway

func (*Gateway) Get

func (g *Gateway) Get(ctx context.Context, tenantID string, id uuid.UUID) (store.MemoryRecord, error)

Get reads one record (tombstone state included).

func (*Gateway) Put

Put embeds (unless a caller-supplied embedding is given), validates, and persists. It returns the record and whether the write replayed an existing identical document.

func (*Gateway) Search

func (g *Gateway) Search(ctx context.Context, in SearchInput) ([]store.MemoryRecord, error)

Search embeds the keyword query when no vector is given and delegates the hybrid scoring to the canonical store.

func (*Gateway) Tombstone

func (g *Gateway) Tombstone(ctx context.Context, tenantID string, id uuid.UUID, expectedVersion int64) (store.MemoryRecord, error)

Tombstone soft-deletes a record with a CAS on its resource version.

type HTTPEmbedder

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

HTTPEmbedder calls a preconfigured HTTPS embedding boundary. The endpoint is operator configuration, never Agent-controlled data.

func NewHTTPEmbedder

func NewHTTPEmbedder(endpoint, bearerToken string, client *http.Client) (*HTTPEmbedder, error)

func (*HTTPEmbedder) Embed

func (e *HTTPEmbedder) Embed(ctx context.Context, content string) ([]float32, error)

type PutInput

type PutInput struct {
	TenantID        string
	Namespace       string
	Key             string
	ContentType     string
	Content         string
	Embedding       []float32
	EmbeddingSource string // caller-supplied embedding; empty = embed content
	Sensitivity     string
	SourceTaskID    *uuid.UUID
	SourceRunID     *uuid.UUID
	SourceAttemptID *uuid.UUID
	Provenance      map[string]any
	RetentionUntil  *time.Time
}

PutInput is one memory write.

type SearchInput

type SearchInput struct {
	TenantID    string
	Query       string
	Embedding   []float32
	Namespace   string
	Sensitivity string
	Limit       int
}

SearchInput is one retrieval request; at least one of Query or Embedding must be present.

Jump to

Keyboard shortcuts

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