types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package types holds the domain entities used throughout memmy.

Storage backends serialize these values into their native primitives (SQLite tables, Postgres rows, Bigtable column families). The shapes defined here are part of the design contract — see DESIGN.md §4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalTenant

func CanonicalTenant(tuple map[string]string) string

CanonicalTenant returns the canonical string form of a tenant tuple: keys and values trimmed, keys sorted, separated by NUL bytes. Stable across runs and processes.

func TenantID

func TenantID(tuple map[string]string) string

TenantID derives a stable 16-byte hex tenant identifier from a tuple. SHA-256 of the canonical form, truncated to 16 bytes (32 hex chars).

Types

type DemoteRequest

type DemoteRequest struct {
	Tenant map[string]string
	NodeID string
}

DemoteRequest / DemoteResult — explicit, caller-driven inhibition on a single node. The caller indicates "this hit was misleading or wrong." Weight is clamped at NodeFloor; the node is never deleted.

type DemoteResult

type DemoteResult struct {
	NodeID            string
	NewWeight         float64
	SkippedRefractory bool
}

type EdgeKind

type EdgeKind uint8

EdgeKind classifies a memory association edge. Affects initial weight and decay rate; retrieval logic does not branch on Kind.

const (
	// EdgeStructural — same source message or temporal adjacency. Created
	// at write time. Slow decay.
	EdgeStructural EdgeKind = iota
	// EdgeCoRetrieval — appeared together in the top-K seed set after
	// reranking. Created or reinforced at read time.
	EdgeCoRetrieval
	// EdgeCoTraversal — graph expansion hopped this edge AND the target
	// node ended up in the final returned result set.
	EdgeCoTraversal
)

func (EdgeKind) String

func (k EdgeKind) String() string

type ForgetRequest

type ForgetRequest struct {
	Tenant    map[string]string
	MessageID string
	Before    time.Time
}

ForgetRequest / ForgetResult — see DESIGN.md §9.1.

type ForgetResult

type ForgetResult struct {
	DeletedNodes   int
	DeletedEdges   int
	DeletedVectors int
}

type HNSWMeta

type HNSWMeta struct {
	Dim            int
	EntryPoint     string
	MaxLayer       int
	M              int
	M0             int
	EfConstruction int
	EfSearch       int
	ML             float64
	Size           int
}

HNSWMeta is per-tenant index metadata. Read fresh from the backend on every operation that needs it (no in-memory cache — DESIGN.md §0 #3).

type HNSWRecord

type HNSWRecord struct {
	NodeID    string
	Layer     int
	Neighbors map[int][]string
}

HNSWRecord stores the per-node neighbor lists across all layers it participates in. Static after insert. See DESIGN.md §4.4.

type MarkRequest

type MarkRequest struct {
	Tenant   map[string]string
	Since    time.Time
	Strength float64
}

MarkRequest / MarkResult — retroactively boost every node in the tenant whose CreatedAt falls within [Since, now]. Strength scales the per-node delta; older nodes within the window receive a smaller share. See DESIGN.md §8.2.

type MarkResult

type MarkResult struct {
	NodesAffected          int
	NodesSkippedRefractory int
}

type MemoryEdge

type MemoryEdge struct {
	From          string
	To            string
	TenantID      string
	Kind          EdgeKind
	Weight        float64
	LastTouched   time.Time
	CreatedAt     time.Time
	AccessCount   uint64
	TraverseCount uint64
}

MemoryEdge is a directed Hebbian association between two nodes. Distinct from HNSW navigation links. See DESIGN.md §4.3 / §7.5.

type Message

type Message struct {
	ID        string
	TenantID  string
	Text      string
	Metadata  map[string]string
	CreatedAt time.Time
}

Message is the original full text the caller wrote, persisted once and referenced by every chunk that came from it. See DESIGN.md §4.5.

type Node

type Node struct {
	ID           string
	TenantID     string
	SourceMsgID  string
	SentenceSpan [2]int
	Text         string
	EmbeddingDim int
	CreatedAt    time.Time
	LastTouched  time.Time
	Weight       float64
	AccessCount  uint64
	Tombstoned   bool
}

Node is a chunk's metadata. The vector itself lives in the VectorIndex's `vectors` collection. See DESIGN.md §4.2.

type RecallHit

type RecallHit struct {
	NodeID         string
	Text           string
	SourceMsgID    string
	SourceText     string
	Score          float64
	ScoreBreakdown ScoreBreakdown
	Path           []string
}

type RecallRequest

type RecallRequest struct {
	Tenant      map[string]string
	Query       string
	K           int
	Hops        int
	OversampleN int
}

RecallRequest / RecallResult / RecallHit — see DESIGN.md §6, §9.1.

type RecallResult

type RecallResult struct {
	Results []RecallHit
}

type ReinforceRequest

type ReinforceRequest struct {
	Tenant map[string]string
	NodeID string
}

ReinforceRequest / ReinforceResult — explicit, caller-driven LTP bump on a single node. The caller indicates "this hit was useful in my answer." See DESIGN.md §8.2.

type ReinforceResult

type ReinforceResult struct {
	NodeID            string
	NewWeight         float64
	SkippedRefractory bool
}

type ScoreBreakdown

type ScoreBreakdown struct {
	Sim        float64
	NodeWeight float64
	GraphMult  float64
	Depth      int
}

ScoreBreakdown is returned alongside RecallHit for explainability.

type StatsRequest

type StatsRequest struct {
	Tenant map[string]string
}

StatsRequest / StatsResult — see DESIGN.md §9.1.

type StatsResult

type StatsResult struct {
	NodeCount       int
	MemoryEdgeCount int
	HNSWSize        int
	AvgNodeWeight   float64
	AvgEdgeWeight   float64
}

type TenantInfo

type TenantInfo struct {
	ID        string
	Tuple     map[string]string
	CreatedAt time.Time
}

TenantInfo is the entry registered in the `tenants` collection.

type WriteRequest

type WriteRequest struct {
	Tenant   map[string]string
	Message  string
	Metadata map[string]string
}

WriteRequest / WriteResult — see DESIGN.md §9.1.

type WriteResult

type WriteResult struct {
	MessageID string
	NodeIDs   []string
}

Jump to

Keyboard shortcuts

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