Help us shape the future of Go! Take the 2026 Go Developer Survey

memory

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package memory provides a stable, library-first API for using the libSQL-backed knowledge graph and vector search engine without running the MCP server transport.

Quickstart:

cfg := &memory.Config{ URL: "file:./libsql.db", EmbeddingDims: 1536 }
svc, err := memory.NewService(cfg)
if err != nil { log.Fatal(err) }
defer svc.Close()

ctx := context.Background()
_ = svc.CreateEntities(ctx, "default", []memory.Entity{{
    Name: "Task:1", EntityType: "Task", Observations: []string{"Hello"},
}})

ents, rels, err := svc.SearchText(ctx, "default", "Hello", 10, 0)
_ = ents; _ = rels; _ = err

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URL                string
	AuthToken          string
	ProjectsDir        string
	MultiProjectMode   bool
	EmbeddingDims      int
	MaxOpenConns       int
	MaxIdleConns       int
	ConnMaxIdleSec     int
	ConnMaxLifeSec     int
	EmbeddingsProvider string
}

Config exposes a stable wrapper for database configuration in package mode. Most fields map directly to internal/database.Config.

type Entity added in v0.6.0

type Entity = apptype.Entity

type GraphResult added in v0.6.0

type GraphResult = apptype.GraphResult

type Relation added in v0.6.0

type Relation = apptype.Relation

type SearchResult added in v0.6.0

type SearchResult = apptype.SearchResult

type Service

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

Service provides a library-first API for memory operations without MCP transport.

func NewService

func NewService(cfg *Config) (*Service, error)

NewService constructs a Service with the provided config.

func (*Service) AddObservations

func (s *Service) AddObservations(ctx context.Context, project, entityName string, observations []string) error

AddObservations appends observations to an entity.

func (*Service) Close

func (s *Service) Close() error

Close releases resources.

func (*Service) CreateEntities

func (s *Service) CreateEntities(ctx context.Context, project string, ents []Entity) error

CreateEntities inserts entities.

func (*Service) CreateRelations

func (s *Service) CreateRelations(ctx context.Context, project string, rels []Relation) error

CreateRelations inserts relations.

func (*Service) DeleteEntities

func (s *Service) DeleteEntities(ctx context.Context, project string, names []string) error

func (*Service) DeleteEntity

func (s *Service) DeleteEntity(ctx context.Context, project, name string) error

Deletes / Updates

func (*Service) DeleteObservations

func (s *Service) DeleteObservations(ctx context.Context, project, entity string, ids []int64, contents []string) (int64, error)

func (*Service) DeleteRelation

func (s *Service) DeleteRelation(ctx context.Context, project, source, target, relationType string) error

func (*Service) DeleteRelations

func (s *Service) DeleteRelations(ctx context.Context, project string, rels []Relation) error

func (*Service) DisableHybridSearch

func (s *Service) DisableHybridSearch()

func (*Service) EnableHybridSearch

func (s *Service) EnableHybridSearch(textWeight, vectorWeight, rrfK float64)

Hybrid search toggles

func (*Service) Neighbors

func (s *Service) Neighbors(ctx context.Context, project string, names []string, direction string, limit int) ([]Entity, []Relation, error)

Graph helpers

func (*Service) OpenNodes

func (s *Service) OpenNodes(ctx context.Context, project string, names []string, includeRelations bool) ([]Entity, []Relation, error)

OpenNodes fetches entities (and optionally relations) by names.

func (*Service) ReadGraph

func (s *Service) ReadGraph(ctx context.Context, project string, limit int) ([]Entity, []Relation, error)

ReadGraph returns recent entities + relations with limit.

func (*Service) SearchSimilar added in v0.6.0

func (s *Service) SearchSimilar(ctx context.Context, project string, embedding []float32, limit, offset int) ([]SearchResult, error)

SearchSimilar returns entities ranked by vector distance from the given embedding. Distance is cosine distance (lower is closer) when libSQL vector functions are available.

func (*Service) SearchText

func (s *Service) SearchText(ctx context.Context, project string, query string, limit, offset int) ([]Entity, []Relation, error)

SearchText performs text search via underlying DB.

func (*Service) SearchVector

func (s *Service) SearchVector(ctx context.Context, project string, vector []float32, limit, offset int) ([]Entity, []Relation, error)

SearchVector performs vector search.

func (*Service) ShortestPath

func (s *Service) ShortestPath(ctx context.Context, project, from, to, direction string) ([]Entity, []Relation, error)

func (*Service) UpdateEntities

func (s *Service) UpdateEntities(ctx context.Context, project string, updates []UpdateEntitySpec) error

func (*Service) UpdateRelations

func (s *Service) UpdateRelations(ctx context.Context, project string, updates []UpdateRelationChange) error

func (*Service) Walk

func (s *Service) Walk(ctx context.Context, project string, names []string, maxDepth int, direction string, limit int) ([]Entity, []Relation, error)

type UpdateEntitySpec added in v0.6.0

type UpdateEntitySpec = apptype.UpdateEntitySpec

type UpdateRelationChange added in v0.6.0

type UpdateRelationChange = apptype.UpdateRelationChange

Jump to

Keyboard shortcuts

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