Documentation
¶
Overview ¶
Package knowledgegraph turns a codebaseindex scan into a typed, confidence-tagged knowledge graph persisted in the semantic memory store. Extraction is deterministic and local first (components, packages, files, symbols, imports); an optional LLM pass can add inferred concept nodes and edges. Inspired by github.com/Graphify-Labs/graphify.
Index ¶
- Constants
- func EdgeID(namespace, sourceID, targetID, kind string) string
- func Enhance(g *Graph, fn EnhanceFunc) error
- func LocalID(id string) string
- func NodeID(namespace, local string) string
- func NodeLabel(n *semanticmemory.GraphNode) string
- func Rebuild(ctx context.Context, store *semanticmemory.Store, g *Graph) error
- func RebuildWithProgress(ctx context.Context, store *semanticmemory.Store, g *Graph, ...) error
- func Save(ctx context.Context, store *semanticmemory.Store, g *Graph) error
- type EnhanceFunc
- type ExportEdge
- type ExportGraph
- type ExportNode
- type Graph
- type NeighborPage
- type Overview
- type ProgressEvent
- type ProgressFunc
- type Querier
- func (q *Querier) Explain(ctx context.Context, name string) (string, error)
- func (q *Querier) Export(ctx context.Context) (*ExportGraph, error)
- func (q *Querier) FindNodes(ctx context.Context, query string, limit int) ([]semanticmemory.GraphNode, error)
- func (q *Querier) Namespace() string
- func (q *Querier) NeighborPage(ctx context.Context, focus semanticmemory.GraphNode, limit, offset int) (*NeighborPage, error)
- func (q *Querier) NodeByID(ctx context.Context, id string) (*semanticmemory.GraphNode, error)
- func (q *Querier) Overview(ctx context.Context) (*Overview, error)
- func (q *Querier) Path(ctx context.Context, fromName, toName string) (string, error)
- func (q *Querier) PathHops(ctx context.Context, fromName, toName string) ([]string, error)
- func (q *Querier) Query(ctx context.Context, question string) (string, error)
- func (q *Querier) Resolve(ctx context.Context, name string) (*semanticmemory.GraphNode, error)
- func (q *Querier) ScopedExport(ctx context.Context, seeds []semanticmemory.GraphNode, hops int) (*ExportGraph, error)
- func (q *Querier) Stats(ctx context.Context) (string, error)
Constants ¶
const ( NodeComponent = semanticmemory.GraphNodeComponent NodePackage = semanticmemory.GraphNodePackage NodeFile = semanticmemory.GraphNodeFile NodeType = semanticmemory.GraphNodeType NodeFunction = semanticmemory.GraphNodeFunction NodeConcept = semanticmemory.GraphNodeConcept EdgeContains = semanticmemory.GraphEdgeContains EdgeBelongsTo = semanticmemory.GraphEdgeBelongsTo EdgeImports = semanticmemory.GraphEdgeImports EdgeDefines = semanticmemory.GraphEdgeDefines EdgeUses = semanticmemory.GraphEdgeUses EdgeReference = semanticmemory.GraphEdgeReference ConfidenceExtracted = semanticmemory.GraphConfidenceExtracted ConfidenceInferred = semanticmemory.GraphConfidenceInferred )
Node and edge kinds are re-exported from semanticmemory so callers use one vocabulary end to end.
Variables ¶
This section is empty.
Functions ¶
func EdgeID ¶
EdgeID builds a stable edge ID from its endpoints and kind. FNV-1a is used for compactness; the ID is a dedup key, not a security primitive.
func Enhance ¶
func Enhance(g *Graph, fn EnhanceFunc) error
Enhance asks a model for concept nodes and semantic edges over the existing graph outline. Everything it adds is tagged inferred. A malformed response is an error for the caller to warn about, never a partial mutation.
func NodeID ¶
NodeID builds a stable, namespace-qualified node ID so rebuilds upsert in place and separate graphs never collide on the primary key.
func NodeLabel ¶
func NodeLabel(n *semanticmemory.GraphNode) string
String renders a node for display.
func RebuildWithProgress ¶ added in v0.0.215
func RebuildWithProgress(ctx context.Context, store *semanticmemory.Store, g *Graph, progress ProgressFunc) error
RebuildWithProgress replaces a graph and reports its persistence phases.
Types ¶
type EnhanceFunc ¶
EnhanceFunc matches the index enhancement hook signature: it takes a prompt and returns the model's response.
type ExportEdge ¶
type ExportEdge struct {
Source string `json:"source"`
Target string `json:"target"`
Kind string `json:"kind"`
Confidence string `json:"confidence"`
Evidence string `json:"evidence,omitempty"`
}
ExportEdge is the JSON export shape for an edge.
type ExportGraph ¶
type ExportGraph struct {
Namespace string `json:"namespace"`
Nodes []ExportNode `json:"nodes"`
Edges []ExportEdge `json:"edges"`
}
ExportGraph is the top-level graph.json shape.
type ExportNode ¶
type ExportNode struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
Package string `json:"package,omitempty"`
Summary string `json:"summary,omitempty"`
Degree int `json:"degree"`
}
ExportNode is the JSON export shape for a node (graphify-style graph.json).
type Graph ¶
type Graph struct {
Namespace string
Nodes map[string]*semanticmemory.GraphNode
Edges map[string]*semanticmemory.GraphEdge
}
Graph is an in-memory knowledge graph under construction.
func Build ¶
func Build(scan *codebaseindex.ScanResult, namespace string) *Graph
Build constructs a knowledge graph from a codebaseindex scan. Everything it emits is deterministic: structural edges are extracted from the scan, and `uses` edges between files and uniquely-named types are inferred from symbol name references.
type NeighborPage ¶ added in v0.0.220
type NeighborPage struct {
Focus ExportNode `json:"focus"`
Offset int `json:"offset"`
NextOffset int `json:"next_offset,omitempty"`
HasMore bool `json:"has_more"`
Graph ExportGraph `json:"graph"`
}
NeighborPage is a bounded direct-neighborhood view. Clients cache returned pages and fetch the next offset only when the user asks to explore further.
type Overview ¶ added in v0.0.220
type Overview struct {
Namespace string `json:"namespace"`
Nodes []ExportNode `json:"nodes"`
NodeKindCounts map[string]int `json:"node_kind_counts"`
}
Overview is the small architectural map shown before a visualizer loads any symbol-level detail. NodeKindCounts describes the complete graph without transferring every node.
type ProgressEvent ¶ added in v0.0.215
ProgressEvent describes graph persistence work. Total covers nodes and edges, while Current identifies the graph object most recently written.
type ProgressFunc ¶ added in v0.0.215
type ProgressFunc func(ProgressEvent)
ProgressFunc receives optional graph persistence milestones.
type Querier ¶
type Querier struct {
// contains filtered or unexported fields
}
Querier runs read-only graph questions against the semantic memory store.
func NewQuerier ¶
func NewQuerier(store *semanticmemory.Store, namespace string) *Querier
NewQuerier binds a querier to a store and namespace.
func (*Querier) Explain ¶
Explain renders a node and its connections, grouped by edge kind, with confidence tags. Mirrors `graphify explain`.
func (*Querier) Export ¶
func (q *Querier) Export(ctx context.Context) (*ExportGraph, error)
Export dumps the namespace graph in the graphify-style graph.json shape.
func (*Querier) FindNodes ¶
func (q *Querier) FindNodes(ctx context.Context, query string, limit int) ([]semanticmemory.GraphNode, error)
FindNodes returns the best matching nodes for a plain-text query.
func (*Querier) Namespace ¶ added in v0.0.219
Namespace returns the graph namespace this querier is bound to.
func (*Querier) NeighborPage ¶ added in v0.0.220
func (q *Querier) NeighborPage(ctx context.Context, focus semanticmemory.GraphNode, limit, offset int) (*NeighborPage, error)
NeighborPage returns one bounded page of direct neighbors without scanning or serializing the complete graph.
func (*Querier) NodeByID ¶ added in v0.0.219
NodeByID returns a graph node by either its stable stored ID or its local export ID. It rejects nodes from another namespace.
func (*Querier) Overview ¶ added in v0.0.220
Overview returns component nodes (or packages for an index without component classification), plus complete kind counts. It is the cheap first request for visualizing a large graph.
func (*Querier) Path ¶
Path finds the shortest connection between two nodes (edges traversed in either direction) and renders the hop chain.
func (*Querier) PathHops ¶
PathHops returns the hop chain between two nodes for structured output. An empty slice means no path; a nil slice means both names are the same node.
func (*Querier) Query ¶
Query answers a plain-language question with a scoped subgraph: the best matching nodes plus their immediate connections, as compact markdown.
func (*Querier) Resolve ¶
Resolve exposes node resolution for callers that need the matched node itself (e.g. JSON output paths).
func (*Querier) ScopedExport ¶
func (q *Querier) ScopedExport(ctx context.Context, seeds []semanticmemory.GraphNode, hops int) (*ExportGraph, error)
ScopedExport dumps the subgraph reachable within `hops` of the given seed nodes, in the same shape as Export. Used for --json query/explain output.