graph

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TriplesToGraph

func TriplesToGraph(triples []Triple) ([]*Entity, []*Relation)

TriplesToGraph converts extracted triples into entities and relations.

Types

type Entity

type Entity struct {
	ID        string         `json:"id"`
	Name      string         `json:"name"`
	Type      string         `json:"type"` // person | project | technology | concept | file | decision
	MemoryIDs []string       `json:"memory_ids"`
	Metadata  map[string]any `json:"metadata,omitempty"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

Entity represents a named concept extracted from memories.

type EntityStore

type EntityStore interface {
	UpsertEntity(ctx context.Context, entity *Entity) error
	GetEntity(ctx context.Context, id string) (*Entity, error)
	FindEntities(ctx context.Context, query string, limit int) ([]*Entity, error)
	UpsertRelation(ctx context.Context, rel *Relation) error
	GetRelations(ctx context.Context, entityID string) ([]*Relation, error)
	GetNeighbors(ctx context.Context, entityID string, depth int) ([]*Entity, []*Relation, error)
}

EntityStore defines the persistence interface for entities and relations.

type InMemoryGraph

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

InMemoryGraph is a basic in-memory knowledge graph for MVP.

func NewInMemoryGraph

func NewInMemoryGraph() *InMemoryGraph

func (*InMemoryGraph) FindEntities

func (g *InMemoryGraph) FindEntities(_ context.Context, query string, limit int) ([]*Entity, error)

func (*InMemoryGraph) GetEntity

func (g *InMemoryGraph) GetEntity(_ context.Context, id string) (*Entity, error)

func (*InMemoryGraph) GetNeighbors

func (g *InMemoryGraph) GetNeighbors(_ context.Context, entityID string, depth int) ([]*Entity, []*Relation, error)

func (*InMemoryGraph) GetRelations

func (g *InMemoryGraph) GetRelations(_ context.Context, entityID string) ([]*Relation, error)

func (*InMemoryGraph) Stats

func (g *InMemoryGraph) Stats() (entityCount, relationCount int)

Stats returns graph statistics.

func (*InMemoryGraph) UpsertEntity

func (g *InMemoryGraph) UpsertEntity(_ context.Context, entity *Entity) error

func (*InMemoryGraph) UpsertRelation

func (g *InMemoryGraph) UpsertRelation(_ context.Context, rel *Relation) error

type Relation

type Relation struct {
	ID        string    `json:"id"`
	FromID    string    `json:"from_id"`
	ToID      string    `json:"to_id"`
	Type      string    `json:"type"` // uses | depends_on | created_by | related_to | supersedes | part_of
	Weight    float64   `json:"weight"`
	MemoryIDs []string  `json:"memory_ids"`
	CreatedAt time.Time `json:"created_at"`
}

Relation represents a directed edge between two entities.

type Triple

type Triple struct {
	Subject   string `json:"subject"`
	Predicate string `json:"predicate"`
	Object    string `json:"object"`
	MemoryID  string `json:"memory_id"`
}

Triple is a subject-predicate-object extracted from text.

func ExtractTriples

func ExtractTriples(content, memoryID string) []Triple

ExtractTriples extracts subject-predicate-object triples from text content. Uses simple pattern matching for MVP; can be upgraded to LLM-based extraction later.

Jump to

Keyboard shortcuts

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