memory

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package memory provides in-memory implementations for testing and development.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection added in v0.3.0

type Collection struct {
	// Name is the collection name.
	Name string

	// Description is an optional description.
	Description string

	// VectorIndex holds the vector embeddings.
	VectorIndex vector.Index
	// contains filtered or unexported fields
}

Collection represents a named collection of documents.

type Document added in v0.3.0

type Document struct {
	// ID is the unique document identifier.
	ID string

	// Content is the document text.
	Content string

	// Embedding is the vector embedding (optional, computed if nil).
	Embedding []float32

	// Metadata contains additional document metadata.
	Metadata map[string]string

	// CreatedAt is when the document was created.
	CreatedAt time.Time

	// UpdatedAt is when the document was last updated.
	UpdatedAt time.Time
}

Document represents a document to store in memory.

type HashEmbedder

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

HashEmbedder creates deterministic embeddings using hashing. This is for testing only - not suitable for production.

func NewHashEmbedder

func NewHashEmbedder(dimensions int) *HashEmbedder

NewHashEmbedder creates a new hash-based embedder.

func (*HashEmbedder) Embed

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

Embed implements vector.Embedder.

func (*HashEmbedder) EmbedBatch

func (e *HashEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch implements vector.Embedder.

func (*HashEmbedder) Model

func (e *HashEmbedder) Model() string

Model implements vector.Embedder.

type KnowledgeGraph

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

KnowledgeGraph is an in-memory knowledge graph.

func NewKnowledgeGraph

func NewKnowledgeGraph(name string) *KnowledgeGraph

NewKnowledgeGraph creates a new in-memory knowledge graph.

func (*KnowledgeGraph) AddEdge

func (kg *KnowledgeGraph) AddEdge(ctx context.Context, edge graph.Edge) error

AddEdge implements graph.KnowledgeGraph.

func (*KnowledgeGraph) AddEdgeBatch

func (kg *KnowledgeGraph) AddEdgeBatch(ctx context.Context, edges []graph.Edge) error

AddEdgeBatch implements graph.BatchKnowledgeGraph.

func (*KnowledgeGraph) AddNode

func (kg *KnowledgeGraph) AddNode(ctx context.Context, node graph.Node) error

AddNode implements graph.KnowledgeGraph.

func (*KnowledgeGraph) AddNodeBatch

func (kg *KnowledgeGraph) AddNodeBatch(ctx context.Context, nodes []graph.Node) error

AddNodeBatch implements graph.BatchKnowledgeGraph.

func (*KnowledgeGraph) DeleteEdge

func (kg *KnowledgeGraph) DeleteEdge(ctx context.Context, from, to, edgeType string) error

DeleteEdge implements graph.KnowledgeGraph.

func (*KnowledgeGraph) DeleteNode

func (kg *KnowledgeGraph) DeleteNode(ctx context.Context, id string) error

DeleteNode implements graph.KnowledgeGraph.

func (*KnowledgeGraph) DeleteNodeBatch

func (kg *KnowledgeGraph) DeleteNodeBatch(ctx context.Context, ids []string) error

DeleteNodeBatch implements graph.BatchKnowledgeGraph.

func (*KnowledgeGraph) EdgeCount

func (kg *KnowledgeGraph) EdgeCount() int

EdgeCount returns the number of edges in the graph.

func (*KnowledgeGraph) FindNodes

func (kg *KnowledgeGraph) FindNodes(ctx context.Context, nodeType string, filters map[string]string) ([]graph.Node, error)

FindNodes implements graph.KnowledgeGraph.

func (*KnowledgeGraph) Name

func (kg *KnowledgeGraph) Name() string

Name implements graph.KnowledgeGraph.

func (*KnowledgeGraph) NodeCount

func (kg *KnowledgeGraph) NodeCount() int

NodeCount returns the number of nodes in the graph.

func (*KnowledgeGraph) Traverse

func (kg *KnowledgeGraph) Traverse(ctx context.Context, startNodes []string, opts graph.TraversalOptions) (*graph.TraversalResult, error)

Traverse implements graph.KnowledgeGraph.

func (*KnowledgeGraph) UpsertEdge

func (kg *KnowledgeGraph) UpsertEdge(ctx context.Context, edge graph.Edge) error

UpsertEdge implements graph.KnowledgeGraph.

func (*KnowledgeGraph) UpsertEdgeBatch

func (kg *KnowledgeGraph) UpsertEdgeBatch(ctx context.Context, edges []graph.Edge) error

UpsertEdgeBatch implements graph.BatchKnowledgeGraph.

func (*KnowledgeGraph) UpsertNode

func (kg *KnowledgeGraph) UpsertNode(ctx context.Context, node graph.Node) error

UpsertNode implements graph.KnowledgeGraph.

func (*KnowledgeGraph) UpsertNodeBatch

func (kg *KnowledgeGraph) UpsertNodeBatch(ctx context.Context, nodes []graph.Node) error

UpsertNodeBatch implements graph.BatchKnowledgeGraph.

type Manager added in v0.3.0

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

Manager manages named collections of documents.

func NewManager added in v0.3.0

func NewManager(cfg ManagerConfig) *Manager

NewManager creates a new memory manager.

func (*Manager) Count added in v0.3.0

func (m *Manager) Count(ctx context.Context, collectionName string) (int, error)

Count returns the number of documents in a collection.

func (*Manager) CreateCollection added in v0.3.0

func (m *Manager) CreateCollection(ctx context.Context, name, description string) (*Collection, error)

CreateCollection creates a new named collection.

func (*Manager) Delete added in v0.3.0

func (m *Manager) Delete(ctx context.Context, collectionName, key string) error

Delete removes a document from a collection.

func (*Manager) DeleteCollection added in v0.3.0

func (m *Manager) DeleteCollection(ctx context.Context, name string) error

DeleteCollection removes a collection.

func (*Manager) Get added in v0.3.0

func (m *Manager) Get(ctx context.Context, collectionName, key string) (*Document, error)

Get retrieves a document from a collection.

func (*Manager) GetCollection added in v0.3.0

func (m *Manager) GetCollection(name string) (*Collection, error)

GetCollection retrieves a collection by name.

func (*Manager) GetOrCreateCollection added in v0.3.0

func (m *Manager) GetOrCreateCollection(ctx context.Context, name, description string) (*Collection, error)

GetOrCreateCollection gets an existing collection or creates a new one.

func (*Manager) List added in v0.3.0

func (m *Manager) List(ctx context.Context, collectionName string, limit, offset int) ([]Document, error)

List returns all documents in a collection.

func (*Manager) ListCollections added in v0.3.0

func (m *Manager) ListCollections() []string

ListCollections returns all collection names.

func (*Manager) Search added in v0.3.0

func (m *Manager) Search(ctx context.Context, collectionName, query string, opts SearchOptions) ([]SearchResult, error)

Search performs a similarity search in a collection.

func (*Manager) Store added in v0.3.0

func (m *Manager) Store(ctx context.Context, collectionName, key string, doc *Document) error

Store adds a document to a collection.

type ManagerConfig added in v0.3.0

type ManagerConfig struct {
	// Embedder computes vector embeddings.
	Embedder vector.Embedder
}

ManagerConfig configures the memory manager.

type SearchOptions added in v0.3.0

type SearchOptions struct {
	// TopK is the maximum number of results.
	TopK int

	// MinScore filters results below this threshold.
	MinScore float64

	// Filters are metadata filters to apply.
	Filters map[string]string

	// IncludeMetadata includes metadata in results.
	IncludeMetadata bool
}

SearchOptions configures a search operation.

type SearchResult added in v0.3.0

type SearchResult struct {
	// Document is the matched document.
	Document Document

	// Score is the similarity score.
	Score float64
}

SearchResult represents a search result.

type VectorIndex

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

VectorIndex is an in-memory vector index using brute-force search.

func NewVectorIndex

func NewVectorIndex(name string) *VectorIndex

NewVectorIndex creates a new in-memory vector index.

func (*VectorIndex) Count

func (idx *VectorIndex) Count() int

Count returns the number of nodes in the index.

func (*VectorIndex) Delete

func (idx *VectorIndex) Delete(ctx context.Context, id string) error

Delete implements vector.Index.

func (*VectorIndex) DeleteBatch

func (idx *VectorIndex) DeleteBatch(ctx context.Context, ids []string) error

DeleteBatch implements vector.BatchIndex.

func (*VectorIndex) Insert

func (idx *VectorIndex) Insert(ctx context.Context, node vector.Node) error

Insert implements vector.Index.

func (*VectorIndex) InsertBatch

func (idx *VectorIndex) InsertBatch(ctx context.Context, nodes []vector.Node) error

InsertBatch implements vector.BatchIndex.

func (*VectorIndex) Name

func (idx *VectorIndex) Name() string

Name implements vector.Index.

func (*VectorIndex) Search

func (idx *VectorIndex) Search(ctx context.Context, embedding []float32, k int, filters map[string]string) ([]vector.SearchResult, error)

Search implements vector.Index.

func (*VectorIndex) Upsert

func (idx *VectorIndex) Upsert(ctx context.Context, node vector.Node) error

Upsert implements vector.Index.

func (*VectorIndex) UpsertBatch

func (idx *VectorIndex) UpsertBatch(ctx context.Context, nodes []vector.Node) error

UpsertBatch implements vector.BatchIndex.

Jump to

Keyboard shortcuts

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