memgraph

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package memgraph provides a store.Store implementation backed by Memgraph, a Bolt-compatible graph database. It uses Cypher queries and the neo4j-go-driver for all persistence operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GraphAdapter

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

GraphAdapter wraps MemgraphStore and implements graph.Client. It is needed because graph.Client.SearchEntities has a different signature than store.Store.SearchEntities — Go does not allow two methods with the same name but different signatures on the same struct, so we use this thin adapter for the graph interface. All other methods delegate directly to the underlying MemgraphStore.

func NewGraphAdapter

func NewGraphAdapter(s *MemgraphStore) *GraphAdapter

NewGraphAdapter creates a GraphAdapter that delegates to the given MemgraphStore.

func (*GraphAdapter) AppendEpisode

func (g *GraphAdapter) AppendEpisode(ctx context.Context, factID, episodeID string) error

AppendEpisode adds an episode/session ID to a fact's episodes list.

func (*GraphAdapter) AppendMemoryToFact

func (g *GraphAdapter) AppendMemoryToFact(ctx context.Context, factID, memoryID string) error

AppendMemoryToFact adds a memory ID to a fact's source_memory_ids list.

func (*GraphAdapter) Close

func (g *GraphAdapter) Close() error

Close releases the driver resources. Delegates to MemgraphStore.

func (*GraphAdapter) EnsureSchema

func (g *GraphAdapter) EnsureSchema(ctx context.Context) error

EnsureSchema creates indexes, constraints, and vector indexes on Memgraph. Memgraph does not support IF NOT EXISTS on constraints, so "already exists" errors are caught and logged as warnings.

func (*GraphAdapter) GetEntity

func (g *GraphAdapter) GetEntity(ctx context.Context, id string) (*models.Entity, error)

GetEntity retrieves a single entity by ID. Delegates to MemgraphStore.

func (*GraphAdapter) GetFactsBetween

func (g *GraphAdapter) GetFactsBetween(ctx context.Context, sourceID, targetID string) ([]models.Fact, error)

GetFactsBetween returns all active facts between two entities (bidirectional).

func (*GraphAdapter) GetFactsForEntity

func (g *GraphAdapter) GetFactsForEntity(ctx context.Context, entityID string) ([]models.Fact, error)

GetFactsForEntity returns all active facts involving an entity (as source or target).

func (*GraphAdapter) GetMemoryFacts

func (g *GraphAdapter) GetMemoryFacts(ctx context.Context, memoryID string) ([]models.Fact, error)

GetMemoryFacts returns all facts derived from a given memory ID.

func (*GraphAdapter) Healthy

func (g *GraphAdapter) Healthy(ctx context.Context) bool

Healthy returns true if the Memgraph database is reachable.

func (*GraphAdapter) InvalidateFact

func (g *GraphAdapter) InvalidateFact(ctx context.Context, id string, expiredAt, invalidAt time.Time) error

InvalidateFact sets ExpiredAt and InvalidAt on a RELATES_TO relationship.

func (*GraphAdapter) RecallByGraph

func (g *GraphAdapter) RecallByGraph(ctx context.Context, query string, embedding []float32, limit int) ([]string, error)

RecallByGraph returns memory IDs relevant to a query via fact text search and extraction.

func (*GraphAdapter) SearchEntities

func (g *GraphAdapter) SearchEntities(ctx context.Context, query string, _ []float32, project string, limit int) ([]graph.EntityResult, error)

SearchEntities finds entities by text search, optionally filtered by project. This implements graph.Client.SearchEntities (different signature from store.Store.SearchEntities).

func (*GraphAdapter) SearchFacts

func (g *GraphAdapter) SearchFacts(ctx context.Context, query string, _ []float32, limit int) ([]graph.FactResult, error)

SearchFacts performs a text search over RELATES_TO relationships using property-level CONTAINS matching (Memgraph does not support text indexes on edges).

func (*GraphAdapter) UpsertEntity

func (g *GraphAdapter) UpsertEntity(ctx context.Context, entity models.Entity) error

UpsertEntity creates or updates an Entity node. Delegates to MemgraphStore.

func (*GraphAdapter) UpsertFact

func (g *GraphAdapter) UpsertFact(ctx context.Context, fact models.Fact) error

UpsertFact creates or updates a RELATES_TO relationship between two entities.

type MemgraphStore

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

MemgraphStore implements store.Store using Memgraph (Bolt-compatible).

func New

func New(ctx context.Context, uri, username, password, database string, logger *slog.Logger) (*MemgraphStore, error)

New creates a new MemgraphStore and verifies connectivity.

func (*MemgraphStore) Close

func (s *MemgraphStore) Close() error

Close releases the driver connection.

func (*MemgraphStore) Delete

func (s *MemgraphStore) Delete(ctx context.Context, id string) error

Delete removes a memory by ID. Returns store.ErrNotFound if nothing was deleted.

func (*MemgraphStore) EnsureCollection

func (s *MemgraphStore) EnsureCollection(ctx context.Context) error

EnsureCollection creates all indexes, constraints, and vector indexes in Memgraph. Delegates to GraphAdapter.EnsureSchema which runs each DDL statement individually.

func (*MemgraphStore) FindDuplicates

func (s *MemgraphStore) FindDuplicates(ctx context.Context, vector []float32, threshold float64) ([]models.SearchResult, error)

FindDuplicates returns memories whose vector similarity to the given vector is at or above the threshold.

func (*MemgraphStore) Get

func (s *MemgraphStore) Get(ctx context.Context, id string) (*models.Memory, error)

Get retrieves a single memory by ID.

func (*MemgraphStore) GetChain

func (s *MemgraphStore) GetChain(ctx context.Context, id string) ([]models.Memory, error)

GetChain follows the supersedes_id chain and returns the full history, newest first. Stops when supersedes_id is empty, the referenced memory is not found, or a cycle is detected.

func (*MemgraphStore) GetEntity

func (s *MemgraphStore) GetEntity(ctx context.Context, id string) (*models.Entity, error)

GetEntity retrieves a single entity by ID.

func (*MemgraphStore) LinkMemoryToEntity

func (s *MemgraphStore) LinkMemoryToEntity(ctx context.Context, entityID, memoryID string) error

LinkMemoryToEntity appends a memory ID to an entity's memory_ids list (idempotent).

func (*MemgraphStore) List

func (s *MemgraphStore) List(ctx context.Context, filters *store.SearchFilters, limit uint64, cursor string) ([]models.Memory, string, error)

List returns memories matching the given filters with cursor-based pagination. The cursor is the SKIP offset encoded as a decimal string; "" means page 0.

func (*MemgraphStore) Search

func (s *MemgraphStore) Search(ctx context.Context, vector []float32, limit uint64, filters *store.SearchFilters) ([]models.SearchResult, error)

Search finds memories similar to the query vector using Memgraph's vector search.

func (*MemgraphStore) SearchEntities

func (s *MemgraphStore) SearchEntities(ctx context.Context, name string) ([]models.Entity, error)

SearchEntities finds entities whose name contains the given string (case-insensitive).

func (*MemgraphStore) Stats

Stats returns collection statistics including type and scope counts plus health metrics.

func (*MemgraphStore) UpdateAccessMetadata

func (s *MemgraphStore) UpdateAccessMetadata(ctx context.Context, id string) error

UpdateAccessMetadata increments access count and updates last_accessed time.

func (*MemgraphStore) UpdateConflictFields

func (s *MemgraphStore) UpdateConflictFields(ctx context.Context, id, conflictGroupID, conflictStatus string) error

UpdateConflictFields sets ConflictGroupID and ConflictStatus on an existing memory.

func (*MemgraphStore) UpdateReinforcement

func (s *MemgraphStore) UpdateReinforcement(ctx context.Context, id string, confidenceBoost float64) error

UpdateReinforcement boosts the confidence of an existing memory (capped at 1.0) and increments reinforced_count.

func (*MemgraphStore) Upsert

func (s *MemgraphStore) Upsert(ctx context.Context, memory models.Memory, vector []float32) error

Upsert inserts or updates a memory node with its embedding vector.

func (*MemgraphStore) UpsertEntity

func (s *MemgraphStore) UpsertEntity(ctx context.Context, entity models.Entity) error

UpsertEntity inserts or updates an entity node.

Jump to

Keyboard shortcuts

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