Documentation
¶
Overview ¶
Package graphflow provides a library-first graph extraction/build/report/export pipeline over CortexDB's graph and RDF storage.
The package is intentionally layered:
- Detector finds input documents.
- Extractor emits a unified extraction schema.
- Build persists that schema into CortexDB's graph store.
- Analyze derives deterministic graph summaries.
- RenderReport produces markdown output.
- Export writes graph.json plus GRAPH_REPORT.md.
The default closed loop is deterministic and does not require an LLM. Model-dependent extractors can be plugged in later via the Extractor interface.
Index ¶
- Constants
- func MarkMastered(ctx context.Context, db *cortexdb.DB, concepts []string, at time.Time) (marked []string, unknown []string, err error)
- func NewMCPServer(db *cortexdb.DB, detector Detector, extractor Extractor, opts MCPServerOptions) (*mcp.Server, error)
- func RenderReport(_ context.Context, report *AnalysisReport) (string, error)
- func SaveTemporalFact(ctx context.Context, db *cortexdb.DB, fact TemporalFact) error
- func SupersedeFact(ctx context.Context, db *cortexdb.DB, from, typ string, asOf time.Time) (int, error)
- func ValidateExtraction(result *ExtractionResult) error
- type AnalysisReport
- type AnalyzeRequest
- type Analyzer
- type BuildOptions
- type BuildResult
- type CommunityOptions
- type CommunityReport
- type CommunitySummary
- type Confidence
- type Detector
- type ExportRequest
- type ExportResult
- type Exporter
- type ExtractionEdge
- type ExtractionNode
- type ExtractionResult
- type Extractor
- type FilesystemDetector
- type GlobalSearchOptions
- type GlobalSearchResult
- type GraphEdit
- type GraphEditOptions
- type GraphEditPlan
- type GraphEditReport
- type HeuristicExtractor
- type JSONGenerator
- type LLMExtractor
- type LearningConcept
- type LearningGraph
- type LearningImportReport
- type LearningPathResult
- type LearningRelation
- type MCPServerOptions
- type MultiHopOptions
- type MultiHopResult
- type MultiHopStep
- type OrganizeOptions
- type OrganizeReport
- type Pipeline
- type Reporter
- type ResolveGroup
- type ResolveOptions
- type ResolveReport
- type RunRequest
- type RunResult
- type SourceDocument
- type TemporalFact
- type TemporalFilter
- type Toolbox
- type TopNode
Constants ¶
const ( EditOpAdd = "add" EditOpUpdate = "update" EditOpDelete = "delete" EditKindEntity = "entity" EditKindRelation = "relation" )
Edit ops and kinds.
const ( RelRequires = "requires" // prerequisite: from requires to RelPartOf = "part_of" // topic hierarchy: concept part_of chapter/topic RelExampleOf = "example_of" // worked example / instance of a concept RelApplies = "applies" // a concept applied by another (law applied by technique) )
Relation types used by learning graphs.
Variables ¶
This section is empty.
Functions ¶
func MarkMastered ¶ added in v2.62.0
func MarkMastered(ctx context.Context, db *cortexdb.DB, concepts []string, at time.Time) (marked []string, unknown []string, err error)
MarkMastered records that the learner has mastered the given concepts, by stamping `mastered_at` on their graph nodes. Unknown concept names are reported back so a caller can surface a typo rather than silently no-op.
func NewMCPServer ¶
func NewMCPServer(db *cortexdb.DB, detector Detector, extractor Extractor, opts MCPServerOptions) (*mcp.Server, error)
NewMCPServer returns an MCP server that exposes the graphflow tool surface.
func RenderReport ¶
func RenderReport(_ context.Context, report *AnalysisReport) (string, error)
RenderReport renders a deterministic markdown report.
func SaveTemporalFact ¶ added in v2.56.0
SaveTemporalFact records a fact with validity time. valid_from / valid_to / recorded_at are written (RFC3339) into the relation edge's JSON properties via UpsertRelations. When fact.ValidFrom is nil it defaults to now. When fact.Supersede is set, any currently-open fact for the same (From, Type) subject is closed at ValidFrom first, so the subject's history stays a chain of non-overlapping intervals.
func SupersedeFact ¶ added in v2.56.0
func SupersedeFact(ctx context.Context, db *cortexdb.DB, from, typ string, asOf time.Time) (int, error)
SupersedeFact closes every currently-open fact matching (from, typ) by setting their valid_to to asOf, and returns how many were closed. "Open" means the edge carries a valid_from but no valid_to. This is the mechanism behind SaveTemporalFact's Supersede option and can also be called directly to retire a subject's current value without asserting a replacement.
func ValidateExtraction ¶
func ValidateExtraction(result *ExtractionResult) error
ValidateExtraction checks that an extraction result is structurally usable.
Types ¶
type AnalysisReport ¶
type AnalysisReport struct {
GeneratedAt time.Time `json:"generated_at"`
NodeCount int `json:"node_count"`
EdgeCount int `json:"edge_count"`
NodeTypes map[string]int `json:"node_types,omitempty"`
RelationTypes map[string]int `json:"relation_types,omitempty"`
Confidence map[string]int `json:"confidence,omitempty"`
TopNodes []TopNode `json:"top_nodes,omitempty"`
SuggestedQuestions []string `json:"suggested_questions,omitempty"`
}
AnalysisReport is the deterministic summary of a graphflow graph.
func Analyze ¶
func Analyze(ctx context.Context, db *cortexdb.DB, req AnalyzeRequest) (*AnalysisReport, error)
Analyze computes a deterministic summary over graphflow nodes and edges.
type AnalyzeRequest ¶
type AnalyzeRequest struct {
TopN int `json:"top_n,omitempty"`
}
AnalyzeRequest scopes deterministic graph analysis.
type Analyzer ¶
type Analyzer interface {
Analyze(ctx context.Context, db *cortexdb.DB, req AnalyzeRequest) (*AnalysisReport, error)
}
Analyzer derives deterministic graph summaries from a persisted graphflow subgraph.
type BuildOptions ¶
type BuildOptions struct {
Collection string `json:"collection,omitempty"`
ReplaceEdges bool `json:"replace_edges,omitempty"`
}
BuildOptions controls persistence behavior.
type BuildResult ¶
BuildResult summarizes one build operation.
func Build ¶
func Build(ctx context.Context, db *cortexdb.DB, extractions []ExtractionResult, opts BuildOptions) (*BuildResult, error)
Build persists extraction results into the existing CortexDB graph store.
type CommunityOptions ¶ added in v2.54.0
type CommunityOptions struct {
LLM JSONGenerator // required: writes each community report
MinSize int // skip communities with fewer entities (default 3)
Max int // cap communities summarized (0 = all)
}
CommunityOptions configures BuildCommunitySummaries.
type CommunityReport ¶ added in v2.54.0
type CommunityReport struct {
Communities []CommunitySummary `json:"communities"`
}
CommunityReport is the set of community summaries produced by one build.
func BuildCommunitySummaries ¶ added in v2.54.0
func BuildCommunitySummaries(ctx context.Context, db *cortexdb.DB, opts CommunityOptions) (*CommunityReport, error)
BuildCommunitySummaries detects entity communities (Louvain) and writes an LLM report for each, persisting them as knowledge documents in the "communities" collection (so they are retrievable and survive across runs) and returning them. It is the prerequisite for GlobalSearch. Per-community LLM failures are non-fatal (that community is skipped).
type CommunitySummary ¶ added in v2.54.0
type CommunitySummary struct {
ID int `json:"id"`
Title string `json:"title"`
Summary string `json:"summary"`
Findings []string `json:"findings,omitempty"`
Entities []string `json:"entities"`
Size int `json:"size"`
}
CommunitySummary is one LLM-written community report.
type Confidence ¶
type Confidence string
Confidence labels whether an edge was directly found or only inferred by an upstream extractor.
const ( ConfidenceExtracted Confidence = "EXTRACTED" ConfidenceInferred Confidence = "INFERRED" ConfidenceAmbiguous Confidence = "AMBIGUOUS" )
type Detector ¶
type Detector interface {
Detect(ctx context.Context, root string) ([]SourceDocument, error)
}
Detector enumerates input documents.
type ExportRequest ¶
type ExportRequest struct {
OutputDir string `json:"output_dir"`
Analysis *AnalysisReport `json:"analysis,omitempty"`
Report string `json:"report,omitempty"`
// View selects the ExportHTML renderer: "2d" (default, Cytoscape) or "3d"
// (a WebGL 3d-force-graph scene). Ignored by Export (JSON-only).
View string `json:"view,omitempty"`
}
ExportRequest writes a graphflow bundle to disk.
type ExportResult ¶
type ExportResult struct {
OutputDir string `json:"output_dir"`
GraphJSON string `json:"graph_json"`
ReportMarkdown string `json:"report_markdown,omitempty"`
GraphHTML string `json:"graph_html,omitempty"`
}
ExportResult returns the written file paths.
func Export ¶
func Export(ctx context.Context, db *cortexdb.DB, req ExportRequest) (*ExportResult, error)
Export writes a minimal graphflow bundle to disk.
func ExportHTML ¶
func ExportHTML(ctx context.Context, db *cortexdb.DB, req ExportRequest) (*ExportResult, error)
ExportHTML generates an HTML visualization of the graph. It embeds the graph data directly in the HTML file and loads the visualization libraries from a CDN at runtime. req.View selects the renderer: "2d" (default, Cytoscape) or "3d" (3d-force-graph / WebGL). Open the file in any modern browser.
type Exporter ¶
type Exporter interface {
Export(ctx context.Context, db *cortexdb.DB, req ExportRequest) (*ExportResult, error)
}
Exporter writes graphflow outputs to disk.
type ExtractionEdge ¶
type ExtractionEdge struct {
Source string `json:"source"`
Target string `json:"target"`
Relation string `json:"relation"`
Confidence Confidence `json:"confidence"`
Directed bool `json:"directed,omitempty"`
SourceFile string `json:"source_file,omitempty"`
SourceLocation string `json:"source_location,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
ExtractionEdge is one extracted graph edge before persistence.
type ExtractionNode ¶
type ExtractionNode struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type,omitempty"`
Summary string `json:"summary,omitempty"`
SourceFile string `json:"source_file,omitempty"`
SourceLocation string `json:"source_location,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
ExtractionNode is one extracted graph node before persistence.
type ExtractionResult ¶
type ExtractionResult struct {
SourceID string `json:"source_id"`
SourceType string `json:"source_type,omitempty"`
Title string `json:"title,omitempty"`
Nodes []ExtractionNode `json:"nodes"`
Edges []ExtractionEdge `json:"edges"`
Metadata map[string]string `json:"metadata,omitempty"`
}
ExtractionResult is the canonical schema that all extractors must emit.
type Extractor ¶
type Extractor interface {
Extract(ctx context.Context, doc SourceDocument) (*ExtractionResult, error)
}
Extractor converts one input document into the canonical extraction schema.
type FilesystemDetector ¶
type FilesystemDetector struct {
IncludeExtensions []string
ExcludeDirs []string
MaxFileBytes int64
ReadContent bool
}
FilesystemDetector is a deterministic detector for local text/code corpora.
func (FilesystemDetector) Detect ¶
func (d FilesystemDetector) Detect(ctx context.Context, root string) ([]SourceDocument, error)
Detect enumerates source documents under a root directory.
type GlobalSearchOptions ¶ added in v2.54.0
type GlobalSearchOptions struct {
LLM JSONGenerator // required
MaxPoints int // top key points fed to the reduce step (default 12)
// BuildIfEmpty builds community summaries first when none are persisted yet.
BuildIfEmpty bool
}
GlobalSearchOptions configures GlobalSearch.
type GlobalSearchResult ¶ added in v2.54.0
type GlobalSearchResult struct {
Query string `json:"query"`
Answer string `json:"answer"`
CommunitiesUsed int `json:"communities_used"`
SupportingPoints []string `json:"supporting_points,omitempty"`
}
GlobalSearchResult is the answer to a whole-corpus question.
func GlobalSearch ¶ added in v2.54.0
func GlobalSearch(ctx context.Context, db *cortexdb.DB, query string, opts GlobalSearchOptions) (*GlobalSearchResult, error)
GlobalSearch answers a whole-corpus question by map-reducing over community reports (Microsoft-GraphRAG global search): each community's report yields query-relevant key points with helpfulness scores (map), and the top points are synthesized into one answer (reduce). Requires community summaries to exist (BuildCommunitySummaries) unless BuildIfEmpty is set.
type GraphEdit ¶ added in v2.62.0
type GraphEdit struct {
Op string `json:"op"` // add|update|delete
Kind string `json:"kind"` // entity|relation
// Entity fields (Kind == "entity").
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Summary string `json:"summary,omitempty"`
// Relation fields (Kind == "relation").
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
RelType string `json:"rel_type,omitempty"`
// Reason is the model's justification; surfaced in dry runs.
Reason string `json:"reason,omitempty"`
}
GraphEdit is one proposed mutation.
type GraphEditOptions ¶ added in v2.62.0
type GraphEditOptions struct {
// LLM is required by UpdateGraphFromText; ApplyGraphEdits ignores it.
LLM JSONGenerator
// DryRun reports what would change without touching the graph.
DryRun bool
// AllowDelete must be set for delete edits to apply. Deletion is
// destructive and not reversible, so it is opt-in.
AllowDelete bool
// MaxDeletes caps how many deletes may apply in one pass (0 = default 20),
// so a confused model cannot wipe a graph in a single call.
MaxDeletes int
// MaxContextEntities bounds how many existing entities are shown to the
// model (0 = default 60).
MaxContextEntities int
}
GraphEditOptions configures how a plan is produced and applied.
type GraphEditPlan ¶ added in v2.62.0
type GraphEditPlan struct {
Edits []GraphEdit `json:"edits"`
}
GraphEditPlan is a set of mutations.
func ProposeGraphEdits ¶ added in v2.62.0
func ProposeGraphEdits(ctx context.Context, db *cortexdb.DB, text string, opts GraphEditOptions) (*GraphEditPlan, error)
ProposeGraphEdits returns the edits an LLM would make for this text without applying them — useful for showing a user a diff before committing.
type GraphEditReport ¶ added in v2.62.0
type GraphEditReport struct {
EntitiesAdded int `json:"entities_added"`
EntitiesUpdated int `json:"entities_updated"`
EntitiesDeleted int `json:"entities_deleted"`
RelationsAdded int `json:"relations_added"`
RelationsDeleted int `json:"relations_deleted"`
Skipped []string `json:"skipped,omitempty"`
Applied []GraphEdit `json:"applied,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
}
GraphEditReport summarizes an applied (or simulated) plan.
func ApplyGraphEdits ¶ added in v2.62.0
func ApplyGraphEdits(ctx context.Context, db *cortexdb.DB, plan GraphEditPlan, opts GraphEditOptions) (*GraphEditReport, error)
ApplyGraphEdits applies a mutation plan deterministically. It is the single write path used by UpdateGraphFromText, and is also useful on its own when a caller (or an agent like Claude Code) has already decided on the edits.
func UpdateGraphFromText ¶ added in v2.62.0
func UpdateGraphFromText(ctx context.Context, db *cortexdb.DB, text string, opts GraphEditOptions) (*GraphEditReport, error)
UpdateGraphFromText reconciles new text against the existing graph with an LLM: it finds the entities the text already shares with the graph, shows the model that subgraph plus the text, and asks for the edits — including corrections (update) and retractions (delete) — needed to make the graph reflect the text. The proposed plan is then applied by ApplyGraphEdits.
Deletes require opts.AllowDelete; use opts.DryRun first to review.
type HeuristicExtractor ¶
type HeuristicExtractor struct{}
HeuristicExtractor is a deterministic extractor that emits a basic node/edge graph from text and code.
func (HeuristicExtractor) Extract ¶
func (HeuristicExtractor) Extract(_ context.Context, doc SourceDocument) (*ExtractionResult, error)
Extract emits a document node, entity nodes, mention edges, and simple co-occurrence edges.
type JSONGenerator ¶
type JSONGenerator interface {
GenerateJSON(ctx context.Context, systemPrompt string, userPrompt string) ([]byte, error)
}
JSONGenerator is the minimal interface required for an LLM-backed extractor.
type LLMExtractor ¶
type LLMExtractor struct {
Client JSONGenerator
MaxChars int
}
LLMExtractor delegates extraction to a model that returns JSON matching the extraction schema.
func (LLMExtractor) Extract ¶
func (e LLMExtractor) Extract(ctx context.Context, doc SourceDocument) (*ExtractionResult, error)
Extract calls the configured JSON generator and normalizes the returned payload.
type LearningConcept ¶ added in v2.62.0
type LearningConcept struct {
Name string `json:"name"`
Type string `json:"type,omitempty"` // see allowedConceptTypes
Subject string `json:"subject,omitempty"` // physics|chemistry|math|language|…
Summary string `json:"summary,omitempty"`
Difficulty int `json:"difficulty,omitempty"` // 1..5, optional
Mastered bool `json:"mastered,omitempty"` // filled in by queries
}
LearningConcept is one node in a learning graph.
func MissingPrerequisites ¶ added in v2.62.0
func MissingPrerequisites(ctx context.Context, db *cortexdb.DB, target string, known []string) ([]LearningConcept, error)
MissingPrerequisites returns the concepts in `target`'s prerequisite closure that are not yet mastered — the direct answer to "why am I stuck on this?". When `known` is nil the mastered set comes from the graph.
func NextConcepts ¶ added in v2.62.0
func NextConcepts(ctx context.Context, db *cortexdb.DB, known []string, limit int) ([]LearningConcept, error)
NextConcepts returns the learnable frontier: concepts that are not yet mastered but whose every prerequisite is. These are exactly what the learner is ready to study now. When `known` is nil the mastered set comes from the graph. limit <= 0 returns all.
type LearningGraph ¶ added in v2.62.0
type LearningGraph struct {
Subject string `json:"subject,omitempty"`
Concepts []LearningConcept `json:"concepts"`
Relations []LearningRelation `json:"relations"`
}
LearningGraph is an importable study-material graph.
type LearningImportReport ¶ added in v2.62.0
type LearningImportReport struct {
Subject int `json:"-"`
Concepts int `json:"concepts"`
Relations int `json:"relations"`
}
LearningImportReport summarizes an import.
func ImportLearningGraph ¶ added in v2.62.0
func ImportLearningGraph(ctx context.Context, db *cortexdb.DB, lg LearningGraph) (*LearningImportReport, error)
ImportLearningGraph writes concepts and their prerequisite/structure edges into the knowledge graph through the standard GraphRAG upsert path, so they are queryable by every existing tool (expand_graph, SPARQL, the graph view) in addition to the learning queries below. Relation endpoints that were not declared as concepts are backfilled, so an edge is never left dangling. Idempotent: re-importing updates in place.
type LearningPathResult ¶ added in v2.62.0
type LearningPathResult struct {
Target string `json:"target"`
Steps []LearningConcept `json:"steps"` // prerequisites first, target last
Known []string `json:"known"` // already-mastered concepts that were skipped
// Concepts that genuinely lie on a prerequisite cycle — not merely the ones
// waiting behind one. Each appears once. See cyclicConcepts.
Cycles []string `json:"cycles"`
Missing bool `json:"missing"` // target not present in the graph
}
LearningPathResult is an ordered study plan.
func LearningPath ¶ added in v2.62.0
func LearningPath(ctx context.Context, db *cortexdb.DB, target string, known []string) (*LearningPathResult, error)
LearningPath returns an ordered study plan for reaching `target`: every concept in the target's prerequisite closure, topologically sorted so that a concept always appears after the concepts it requires, with anything already mastered removed. When `known` is nil the mastered set is loaded from the graph.
If the prerequisite edges contain a cycle (LLM-extracted material sometimes does), the cycle is broken deterministically — the remaining concepts are still emitted, lowest difficulty first — and the involved concepts are reported in Cycles rather than hanging or silently dropping them.
type LearningRelation ¶ added in v2.62.0
type LearningRelation struct {
From string `json:"from"`
To string `json:"to"`
Type string `json:"type,omitempty"` // requires|part_of|example_of|applies
}
LearningRelation is one edge in a learning graph.
type MCPServerOptions ¶
type MCPServerOptions struct {
Implementation *mcp.Implementation
Instructions string
Logger *slog.Logger
}
MCPServerOptions configures the graphflow MCP server wrapper.
type MultiHopOptions ¶ added in v2.56.0
type MultiHopOptions struct {
LLM JSONGenerator // required: decides sufficiency and emits the next query
MaxHops int // cap retrieval iterations (default 4)
TopKPerHop int // knowledge hits pulled per hop (default 5)
}
MultiHopOptions configures MultiHopSearch.
type MultiHopResult ¶ added in v2.56.0
type MultiHopResult struct {
Query string `json:"query"`
Answer string `json:"answer"`
Hops int `json:"hops"`
Steps []MultiHopStep `json:"steps,omitempty"`
}
MultiHopResult is the answer to a multi-hop question, with the full hop trace.
func MultiHopSearch ¶ added in v2.56.0
func MultiHopSearch(ctx context.Context, db *cortexdb.DB, query string, opts MultiHopOptions) (*MultiHopResult, error)
MultiHopSearch answers a complex question by iterating retrieve → reason → retrieve. Starting from the original question, each hop runs a GraphRAG search (auto retrieval mode, graph-light), folds its snippets into a deduped evidence set, and asks the LLM whether the evidence now answers the question. When the LLM says "enough" (or hands back no next query, or MaxHops is reached, or it repeats an earlier query), the loop stops and the answer is emitted — either the LLM's own answer or, if it left that blank, a final reduce call over all evidence. Best-effort by design: an LLM/parse failure on a hop stops the loop and answers from evidence gathered so far rather than hard-failing, unless there is neither evidence nor an answer to return.
type MultiHopStep ¶ added in v2.56.0
type MultiHopStep struct {
Query string `json:"query"`
Snippets []string `json:"snippets,omitempty"`
}
MultiHopStep records one retrieval hop for transparency: the query that drove it and the snippets it contributed to the evidence set.
type OrganizeOptions ¶ added in v2.41.0
type OrganizeOptions struct {
// IncludeMemories scans the agent-memory store (messages). Defaults to true
// when both IncludeMemories and IncludeKnowledge are left false.
IncludeMemories bool
// IncludeKnowledge scans durable knowledge (documents).
IncludeKnowledge bool
// MaxDocuments caps the number of texts scanned (0 = no cap).
MaxDocuments int
// LLM, when set, replaces the deterministic candidate extractor with an LLM
// that distills clean, typed entities and only explicitly-stated relations.
// When nil, extraction stays fully deterministic (no LLM, no embedder) — the
// default. Results are written through the same GraphRAG upsert path either
// way, so the graph view and GraphRAG retrieval read them identically.
LLM JSONGenerator
}
OrganizeOptions configures OrganizeFromBrain.
type OrganizeReport ¶ added in v2.41.0
type OrganizeReport struct {
DocumentsScanned int `json:"documents_scanned"`
EntityCount int `json:"entity_count"` // new entities written
RelationCount int `json:"relation_count"` // relations written
CandidatesSeen int `json:"candidates_seen"`
CandidatesKept int `json:"candidates_kept"`
}
OrganizeReport summarizes an organize pass.
func OrganizeFromBrain ¶ added in v2.41.0
func OrganizeFromBrain(ctx context.Context, db *cortexdb.DB, opts OrganizeOptions) (*OrganizeReport, error)
OrganizeFromBrain extracts entities and relations from stored memories (and, optionally, durable knowledge) and writes them into the knowledge graph, so a brain that only holds free-text memories gains a navigable entity graph.
Extraction is deterministic (no LLM or embedder). Raw capitalized/backtick candidates are filtered for quality — common English words are dropped, and a single-occurrence candidate is kept only if it looks like a real entity (domain, path, code identifier, CamelCase, or contains a digit) or recurs across texts. Entities are written through the public GraphRAG upsert path so they get "entity:<name>" ids and lexical vectors matching SaveKnowledge, and EXISTING entities are never re-written (so their richer type is preserved). Co-occurrence ("co_occurs") relations link entities sharing a sentence. Idempotent. For typed relations, save them explicitly or use an LLM extractor.
type Pipeline ¶
Pipeline wires detector and extractor into the deterministic graphflow loop.
func NewPipeline ¶
NewPipeline constructs a graphflow pipeline.
type Reporter ¶
type Reporter interface {
Render(ctx context.Context, report *AnalysisReport) (string, error)
}
Reporter renders an analysis report.
type ResolveGroup ¶ added in v2.55.0
ResolveGroup is one set of entities merged into a canonical name.
type ResolveOptions ¶ added in v2.55.0
type ResolveOptions struct {
// LLM, when set, additionally proposes acronym/synonym merges that
// normalization cannot catch (e.g. K8s ↔ Kubernetes). Optional.
LLM JSONGenerator
// DryRun reports the merges it would make without applying them.
DryRun bool
}
ResolveOptions configures ResolveEntities.
type ResolveReport ¶ added in v2.55.0
type ResolveReport struct {
EntitiesBefore int `json:"entities_before"`
EntitiesMerged int `json:"entities_merged"` // alias nodes removed
Groups []ResolveGroup `json:"groups"`
DryRun bool `json:"dry_run,omitempty"`
}
ResolveReport summarizes an entity-resolution pass.
func ResolveEntities ¶ added in v2.55.0
func ResolveEntities(ctx context.Context, db *cortexdb.DB, opts ResolveOptions) (*ResolveReport, error)
ResolveEntities finds duplicate/alias entities and merges each group into a single canonical node. Returns what it did (or would do, when DryRun).
type RunRequest ¶
type RunRequest struct {
Root string `json:"root"`
OutputDir string `json:"output_dir"`
Build BuildOptions `json:"build,omitempty"`
Analyze AnalyzeRequest `json:"analyze,omitempty"`
}
RunRequest is the end-to-end graphflow pipeline input.
type RunResult ¶
type RunResult struct {
Documents []SourceDocument `json:"documents,omitempty"`
Extractions []ExtractionResult `json:"extractions,omitempty"`
Build BuildResult `json:"build"`
Analysis *AnalysisReport `json:"analysis,omitempty"`
Report string `json:"report,omitempty"`
Export *ExportResult `json:"export,omitempty"`
}
RunResult summarizes a full graphflow pipeline execution.
type SourceDocument ¶
type SourceDocument struct {
ID string `json:"id"`
Path string `json:"path,omitempty"`
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Content string `json:"content,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
SourceDocument is one input document identified by a detector stage.
type TemporalFact ¶ added in v2.56.0
type TemporalFact struct {
From string `json:"from"`
To string `json:"to"`
Type string `json:"type"`
ValidFrom *time.Time `json:"valid_from,omitempty"`
ValidTo *time.Time `json:"valid_to,omitempty"`
// Supersede, when set on SaveTemporalFact, closes any currently-open fact
// for the same (From, Type) subject at ValidFrom before recording this one
// — the "new value replaces old" pattern (e.g. a changed job title).
Supersede bool `json:"supersede,omitempty"`
// RecordedAt is the wall-clock time the fact was written (transaction time).
// Set by SaveTemporalFact; read back by QueryFactsAsOf.
RecordedAt *time.Time `json:"recorded_at,omitempty"`
}
TemporalFact is a relation (From -Type-> To) that holds over a validity interval [ValidFrom, ValidTo). A nil ValidTo means the fact is open-ended — still valid now. RecordedAt (transaction time) is set by SaveTemporalFact and populated on read by QueryFactsAsOf.
func QueryFactsAsOf ¶ added in v2.56.0
func QueryFactsAsOf(ctx context.Context, db *cortexdb.DB, at time.Time, filter TemporalFilter) ([]TemporalFact, error)
QueryFactsAsOf returns the temporal facts whose validity interval contains the instant `at` — i.e. valid_from <= at AND (valid_to IS NULL OR at < valid_to) — optionally scoped by subject and/or predicate. Endpoint node ids are resolved to entity display names (falling back to the id suffix), matching the community.go loadEntityDisplayNames pattern.
type TemporalFilter ¶ added in v2.56.0
type TemporalFilter struct {
From string `json:"from,omitempty"` // subject display name or entity id
Type string `json:"type,omitempty"` // predicate / edge type
}
TemporalFilter optionally scopes QueryFactsAsOf to a subject and/or predicate. A zero filter returns every temporal fact valid at the queried instant.
type Toolbox ¶
type Toolbox struct {
// contains filtered or unexported fields
}
Toolbox exposes graphflow as a tool-call surface.
func NewToolbox ¶
NewToolbox constructs a graphflow tool facade.
func (*Toolbox) Definitions ¶
func (t *Toolbox) Definitions() []cortexdb.ToolDefinition
Definitions returns JSON-schema-like graphflow tool definitions.