graph

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package graph implements the SQLite graph store for Cortex.

It provides knowledge graph operations for creating, querying, and deleting edges between observations. The store implements the domain.GraphRepository interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store implements the SQLite graph store.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore creates a new graph store with the given database connection.

func (*Store) CountAllEdges

func (s *Store) CountAllEdges(ctx context.Context) (int, error)

CountAllEdges counts all edges in the system.

func (*Store) CountEdgesByObservation

func (s *Store) CountEdgesByObservation(ctx context.Context, obsID int64) (int, error)

CountEdgesByObservation counts edges connected to a specific observation.

func (*Store) CreateEdge

func (s *Store) CreateEdge(ctx context.Context, edge *domain.Edge) error

CreateEdge creates a relationship between two observations. Returns domain.ErrAlreadyExists if an edge with the same (from, to, relation_type) exists.

func (*Store) DeleteEdge

func (s *Store) DeleteEdge(ctx context.Context, id int64) error

DeleteEdge removes a relationship between observations.

func (*Store) GetContradictions

func (s *Store) GetContradictions(ctx context.Context, from, to time.Time) ([]*domain.Edge, error)

GetContradictions retrieves contradiction edges created in a time range.

func (*Store) GetEdge

func (s *Store) GetEdge(ctx context.Context, id int64) (*domain.Edge, error)

GetEdge retrieves a specific edge by its ID.

func (*Store) GetEdgesForObservation

func (s *Store) GetEdgesForObservation(ctx context.Context, obsID int64) ([]*domain.Edge, error)

GetEdgesForObservation retrieves all edges where the observation is either source or target.

func (*Store) GetEdgesValidAt added in v1.0.0

func (s *Store) GetEdgesValidAt(ctx context.Context, obsID int64, at time.Time) ([]*domain.Edge, error)

GetEdgesValidAt retrieves edges for an observation that were valid at the given time. An edge is valid at time `at` if: (valid_from IS NULL OR valid_from <= at) AND (invalid_at IS NULL OR invalid_at > at).

func (*Store) GetEvolutionChain

func (s *Store) GetEvolutionChain(ctx context.Context, fromObsID, toObsID int64) ([]*domain.Edge, error)

GetEvolutionChain retrieves all edges that share the same endpoints.

func (*Store) GetRelated

func (s *Store) GetRelated(ctx context.Context, obsID int64, depth int) ([]*domain.Observation, error)

GetRelated retrieves observations related to the given observation ID, up to the specified depth using a recursive CTE.

func (*Store) UpdateEdge

func (s *Store) UpdateEdge(ctx context.Context, edge *domain.Edge) error

UpdateEdge updates mutable edge fields by ID.

Jump to

Keyboard shortcuts

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