model

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const EmbeddingMatrixKey = "embedding_matrix"

EmbeddingMatrixKey is the metadata field used for multi-vector support.

Variables

This section is empty.

Functions

func AllEmbeddings

func AllEmbeddings(rec MemoryRecord) [][]float32

AllEmbeddings returns every embedding vector associated with the record.

func CloneMetadata

func CloneMetadata(meta map[string]any) map[string]any

func CosineSimilarity

func CosineSimilarity(a, b []float32) float64

CosineSimilarity computes the cosine similarity between two vectors.

func CosineSimilarityMatrix

func CosineSimilarityMatrix(query []float32, matrix [][]float32) float64

CosineSimilarityMatrix computes the best cosine similarity between a query vector and any vector contained within the matrix.

func DecodeEmbeddingMatrix

func DecodeEmbeddingMatrix(raw any) [][]float32

DecodeEmbeddingMatrix coerces arbitrary inputs into a matrix of float32 vectors.

func DecodeMetadata

func DecodeMetadata(metadata string) map[string]any

func FloatFromAny

func FloatFromAny(v any) float64

func HydrateRecordFromMetadata

func HydrateRecordFromMetadata(rec *MemoryRecord, meta map[string]any)

func MaxCosineSimilarity

func MaxCosineSimilarity(query []float32, rec MemoryRecord) float64

MaxCosineSimilarity returns the highest cosine similarity between the query vector and any embedding associated with the record.

func NormalizeMetadata

func NormalizeMetadata(meta map[string]any, fallback time.Time) (importance float64, source, summary string, lastEmbedded time.Time, jsonString string)

func RecordSimilarity

func RecordSimilarity(a, b MemoryRecord) float64

RecordSimilarity computes the maximum similarity between any pair of embeddings contained within the two records.

func RepresentativeEmbedding

func RepresentativeEmbedding(rec MemoryRecord) []float32

RepresentativeEmbedding returns the first non-empty embedding from the record.

func SanitizeEmbeddingMatrix

func SanitizeEmbeddingMatrix(meta map[string]any) [][]float32

SanitizeEmbeddingMatrix normalizes the embedding matrix stored in metadata.

func StringFromAny

func StringFromAny(v any) string

func TimeFromAny

func TimeFromAny(v any) time.Time

func ValidEmbeddingMatrix

func ValidEmbeddingMatrix(meta map[string]any) [][]float32

ValidEmbeddingMatrix extracts a validated embedding matrix from metadata.

Types

type CosineQuery added in v1.13.6

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

CosineQuery prepares the invariant portion of cosine similarity for reuse across many candidate vectors. The query slice must not be mutated while the prepared query is in use.

func NewCosineQuery added in v1.13.6

func NewCosineQuery(vector []float32) CosineQuery

NewCosineQuery prepares a vector for repeated cosine-similarity comparisons.

func (CosineQuery) MaxSimilarity added in v1.13.6

func (q CosineQuery) MaxSimilarity(rec MemoryRecord) float64

MaxSimilarity returns the highest cosine similarity between a prepared query and any embedding associated with the record.

func (CosineQuery) Similarity added in v1.13.6

func (q CosineQuery) Similarity(vector []float32) float64

Similarity computes cosine similarity against a prepared query. Differing vector dimensions retain CosineSimilarity's truncated-vector semantics.

type EdgeType

type EdgeType string

EdgeType enumerates supported knowledge graph relationships between memories.

const (
	EdgeFollows     EdgeType = "follows"
	EdgeExplains    EdgeType = "explains"
	EdgeContradicts EdgeType = "contradicts"
	EdgeDerivedFrom EdgeType = "derived_from"
)

type GraphEdge

type GraphEdge struct {
	Target int64    `json:"target"`
	Type   EdgeType `json:"type"`
}

GraphEdge represents a typed, directed connection between two memory nodes.

func DecodeGraphEdges

func DecodeGraphEdges(raw any) []GraphEdge

decodeGraphEdges attempts to coerce arbitrary metadata into []GraphEdge.

func SanitizeGraphEdges

func SanitizeGraphEdges(meta map[string]any) []GraphEdge

sanitizeGraphEdges normalizes the metadata map and extracts the edge list.

func ValidGraphEdges

func ValidGraphEdges(meta map[string]any) []GraphEdge

func (GraphEdge) Validate

func (g GraphEdge) Validate() error

Validate ensures the edge definition is usable.

type MemoryRecord

type MemoryRecord struct {
	ID              int64       `json:"id"`
	SessionID       string      `json:"session_id"`
	Space           string      `json:"space"`
	Content         string      `json:"content"`
	Metadata        string      `json:"metadata"`
	Embedding       []float32   `json:"embedding"`
	EmbeddingMatrix [][]float32 `json:"embedding_matrix,omitempty"`
	Score           float64     `json:"score"`
	KeywordScore    float64     `json:"keyword_score"`
	Importance      float64     `json:"importance"`
	Source          string      `json:"source"`
	Summary         string      `json:"summary"`
	CreatedAt       time.Time   `json:"created_at"`
	LastEmbedded    time.Time   `json:"last_embedded"`
	WeightedScore   float64     `json:"weighted_score"`
	GraphEdges      []GraphEdge `json:"graph_edges"`
}

MemoryRecord represents a persisted memory entry in the vector store.

Jump to

Keyboard shortcuts

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