graph

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportGraph

func ExportGraph(kg KnowledgeGraph, format, title string) ([]byte, error)

Types

type Entity

type Entity struct {
	Name         string   `json:"name"`
	EntityType   string   `json:"entityType"`
	Observations []string `json:"observations"`
}

Entity represents a knowledge graph node with observations.

type GraphRepository

type GraphRepository interface {
	CreateEntities([]Entity) ([]Entity, error)
	CreateRelations([]Relation) ([]Relation, error)
	AddObservations([]Observation) ([]Observation, error)
	DeleteEntities(entityNames []string) error
	DeleteObservations(deletions []Observation) error
	DeleteRelations(relations []Relation) error
	ReadGraph() (KnowledgeGraph, error)
	SearchNodes(query string) (KnowledgeGraph, error)
	SearchNodesFiltered(query string, includeArchived bool) (KnowledgeGraph, error)
	OpenNodes(names []string) (KnowledgeGraph, error)
	OpenNodesFiltered(names []string, includeArchived bool) (KnowledgeGraph, error)
	EntityCount() (int64, error)
	EntityTypeCounts() (map[string]int64, error)
	ListEntities(entityType string) (KnowledgeGraph, error)
	ListRelations(relationType, fromEntity string) ([]Relation, error)
	TraverseGraph(entity, relationType, direction string, maxDepth int) ([]TraverseNode, []TraverseEdge, error)
	GetIntegrationMap(ctx context.Context, service string, depth int) (IntegrationMap, error)
	FindPath(from, to string, maxDepth int) ([]PathEdge, error)
	UpdateEntity(oldName, newName, newType string) error
}

GraphRepository is the outbound port implemented by internal/infra/db.

type GraphService

type GraphService interface {
	GraphRepository
}

GraphService is the inbound port called by internal/adapter/mcp and decorated by the audit logger in internal/app. Embedding GraphRepository allows decoration without re-listing every method.

type IntegrationEdge

type IntegrationEdge struct {
	Target     string `json:"target"`
	Schema     string `json:"schema,omitempty"`      // event-topic schema name
	Version    string `json:"version,omitempty"`     // api version
	Paths      int    `json:"paths,omitempty"`       // api path count
	Confidence string `json:"confidence"`            // "authoritative" | "inferred"
	SourceRepo string `json:"source_repo,omitempty"` // originating repo
}

IntegrationEdge is a single integration relationship entry in an IntegrationMap.

type IntegrationMap

type IntegrationMap struct {
	Service      string            `json:"service"`
	Publishes    []IntegrationEdge `json:"publishes"`
	Subscribes   []IntegrationEdge `json:"subscribes"`
	ExposesAPI   []IntegrationEdge `json:"exposes_api"`
	ProvidesGRPC []IntegrationEdge `json:"provides_grpc"`
	GRPCDeps     []IntegrationEdge `json:"grpc_deps"`
	Calls        []IntegrationEdge `json:"calls"`
	Coverage     string            `json:"graph_coverage"` // "full" | "partial" | "inferred" | "none"
}

IntegrationMap aggregates all integration relationships for a service.

type KnowledgeGraph

type KnowledgeGraph struct {
	Entities  []Entity   `json:"entities"`
	Relations []Relation `json:"relations"`
}

KnowledgeGraph represents the complete graph structure.

type MemoryService

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

MemoryService implements GraphService by delegating to a GraphRepository.

func NewMemoryService

func NewMemoryService(repo GraphRepository) *MemoryService

NewMemoryService creates a MemoryService backed by repo.

func (*MemoryService) AddObservations

func (srv *MemoryService) AddObservations(obs []Observation) ([]Observation, error)

func (*MemoryService) CreateEntities

func (srv *MemoryService) CreateEntities(entities []Entity) ([]Entity, error)

func (*MemoryService) CreateRelations

func (srv *MemoryService) CreateRelations(relations []Relation) ([]Relation, error)

func (*MemoryService) DeleteEntities

func (srv *MemoryService) DeleteEntities(names []string) error

func (*MemoryService) DeleteObservations

func (srv *MemoryService) DeleteObservations(deletions []Observation) error

func (*MemoryService) DeleteRelations

func (srv *MemoryService) DeleteRelations(relations []Relation) error

func (*MemoryService) EntityCount

func (srv *MemoryService) EntityCount() (int64, error)

func (*MemoryService) EntityTypeCounts

func (srv *MemoryService) EntityTypeCounts() (map[string]int64, error)

func (*MemoryService) FindPath

func (srv *MemoryService) FindPath(from, to string, maxDepth int) ([]PathEdge, error)

func (*MemoryService) GetIntegrationMap

func (srv *MemoryService) GetIntegrationMap(ctx context.Context, service string, depth int) (IntegrationMap, error)

func (*MemoryService) ListEntities

func (srv *MemoryService) ListEntities(entityType string) (KnowledgeGraph, error)

func (*MemoryService) ListRelations

func (srv *MemoryService) ListRelations(relationType, fromEntity string) ([]Relation, error)

func (*MemoryService) OpenNodes

func (srv *MemoryService) OpenNodes(names []string) (KnowledgeGraph, error)

func (*MemoryService) OpenNodesFiltered

func (srv *MemoryService) OpenNodesFiltered(names []string, includeArchived bool) (KnowledgeGraph, error)

func (*MemoryService) ReadGraph

func (srv *MemoryService) ReadGraph() (KnowledgeGraph, error)

func (*MemoryService) SearchNodes

func (srv *MemoryService) SearchNodes(query string) (KnowledgeGraph, error)

func (*MemoryService) SearchNodesFiltered

func (srv *MemoryService) SearchNodesFiltered(query string, includeArchived bool) (KnowledgeGraph, error)

func (*MemoryService) TraverseGraph

func (srv *MemoryService) TraverseGraph(entity, relationType, direction string, maxDepth int) ([]TraverseNode, []TraverseEdge, error)

func (*MemoryService) UpdateEntity

func (srv *MemoryService) UpdateEntity(oldName, newName, newType string) error

type Observation

type Observation struct {
	EntityName   string   `json:"entityName"`
	Contents     []string `json:"contents"`
	Observations []string `json:"observations,omitempty"` // For deletion
}

Observation contains facts about an entity.

type PathEdge

type PathEdge struct {
	From         string `json:"from"`
	RelationType string `json:"relationType"`
	To           string `json:"to"`
	Confidence   string `json:"confidence,omitempty"`
}

PathEdge is a single directed edge on the path between two entities. The edge reflects the actual stored direction regardless of traversal direction.

type Relation

type Relation struct {
	From         string `json:"from"`
	To           string `json:"to"`
	RelationType string `json:"relationType"`
	// Confidence indicates how the relation was derived.
	// "authoritative" — from an explicit contract file.
	// "inferred"      — from a config heuristic.
	// "ambiguous"     — caller explicitly marked the edge as uncertain.
	Confidence string `json:"confidence,omitempty"`
}

Relation represents a directed edge between two entities.

type TraverseEdge

type TraverseEdge struct {
	From         string `json:"from"`
	To           string `json:"to"`
	RelationType string `json:"relationType"`
	Confidence   string `json:"confidence,omitempty"`
}

TraverseEdge is a directed edge discovered during graph traversal.

type TraverseNode

type TraverseNode struct {
	Name         string   `json:"name"`
	EntityType   string   `json:"entityType"`
	Observations []string `json:"observations"`
	Distance     int      `json:"distance"`
	Path         []string `json:"path"` // entity names from start (exclusive) to this node (inclusive)
}

TraverseNode is a node reached during graph traversal, enriched with distance from the start entity and the path of entity names leading to it.

Jump to

Keyboard shortcuts

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