mcp_fact_graph 0.3.0
mcp_fact_graph: ^0.3.0 copied to clipboard
Temporal knowledge graph with evidence-based fact management, candidate confirmation, and automatic summarization for the MCP ecosystem.
// Evidence in, a fact out, a context bundle and a checked answer: the path
// through the four layers with the in-memory runtime.
import 'package:mcp_fact_graph/mcp_fact_graph.dart';
Future<void> main() async {
// The engine ships mechanisms; the words it judges by, the object types it
// requires fields of and the domain views it computes are the host's. The
// multilingual policy and the starter sets are ready-made choices.
final graph = FactGraphRuntime.inMemory(
defaultWorkspaceId: 'demo',
responsePolicy: const ResponsePolicy.multilingual(),
minimumFields: FactGraphService.starterMinimumFields,
viewComputers: starterViewComputers,
);
// L0: evidence and a fragment read from it.
final evidence = await graph.evidenceService.ingestEvidence(IngestionInput(
workspaceId: 'demo',
sourceType: EvidenceSourceType.text,
sourceId: 'meeting-notes',
content: 'Pilot is set for December 12. Legal review is due November 8.',
));
final fragment = await graph.evidenceService.addFragment(
evidence.evidenceId,
{'summary': 'Pilot is set for December 12'},
);
// L1: a candidate built from the fragment, confirmed into a fact.
final candidate = await graph.factGraphService.createCandidate(
workspaceId: 'demo',
objectType: 'decision',
fragments: [fragment],
);
final confirmation =
await graph.factGraphService.confirmCandidate(candidate.candidateId);
print('fact ${confirmation.factId}');
// Read-only search, ranked by the terms the facts share with the query.
final found = await graph.factGraphService
.searchFacts(workspaceId: 'demo', query: 'pilot december');
print('${found.length} fact(s) match');
// L2: the context bundle for a question, within a token budget.
final bundle = await graph.contextService.buildContext(
workspaceId: 'demo',
query: 'When is the pilot?',
tokenBudget: 512,
);
print('bundle holds ${bundle.facts.length} fact(s)');
// L2: an answer checked against the facts before it reaches the user.
final check = await graph.responseValidationService!.validate(
workspaceId: 'demo',
responseText: 'The pilot is set for December 12.',
);
print('${check.result.name}: ${check.sanitizedResponse}');
}