Skip to content

Knowledge Graph Prompts

Ten prompts for building, querying, exporting, and traversing FCC knowledge graphs. Each prompt includes a code snippet and a description of the expected output.


Table of Contents

  1. Build a Full FCC Knowledge Graph
  2. Query Persona Relationships
  3. Export to RDF
  4. Traverse Shortest Paths
  5. Build a Category Subgraph
  6. Export to JSON-LD
  7. Find All Downstream Dependents
  8. Build an Ontology Schema
  9. Merge Two Knowledge Graphs
  10. Federated Cross-Namespace Query

1. Build a Full FCC Knowledge Graph

Construct a knowledge graph containing all 102 personas, their actions, and artifacts.

from fcc.knowledge.builders import build_full_fcc_graph

graph = build_full_fcc_graph()
print(f"Nodes: {len(graph.nodes)}")
print(f"Edges: {len(graph.edges)}")
print(f"Node types: {set(n.node_type for n in graph.nodes.values())}")

Expected output: A KnowledgeGraph with persona nodes, action nodes, artifact nodes, and edges representing handoffs, feedback loops, and orchestration relationships. The graph should contain 9 node types and 9 edge types.


2. Query Persona Relationships

Find all personas that a given persona hands off to (downstream neighbors).

from fcc.knowledge.builders import build_full_fcc_graph

graph = build_full_fcc_graph()
downstream = graph.get_neighbors("RC", edge_type="handoff", direction="outgoing")
for neighbor in downstream:
    print(f"RC -> {neighbor.node_id} ({neighbor.label})")

Expected output: A list of persona nodes that receive handoffs from the Research Crafter, including BC (Blueprint Crafter) and any other downstream consumers.


3. Export to RDF

Serialize the knowledge graph to RDF/Turtle format for integration with triple stores.

from fcc.knowledge.builders import build_full_fcc_graph
from fcc.knowledge.serializers import RDFSerializer

graph = build_full_fcc_graph()
serializer = RDFSerializer()
rdf_output = serializer.serialize(graph)
with open("fcc_knowledge.ttl", "w") as f:
    f.write(rdf_output)

Expected output: A Turtle file containing RDF triples for all nodes and edges, with FCC-specific namespace prefixes and typed relationships.


4. Traverse Shortest Paths

Find the shortest path between two personas in the knowledge graph.

from fcc.knowledge.builders import build_full_fcc_graph

graph = build_full_fcc_graph()
path = graph.shortest_path("RC", "MOS")
for i, node_id in enumerate(path):
    node = graph.nodes[node_id]
    print(f"  Step {i}: {node_id} ({node.label})")

Expected output: A list of node IDs representing the shortest traversal path from Research Crafter to Model Operations Specialist, passing through intermediate personas like BC, MAR, or ESC.


5. Build a Category Subgraph

Extract a subgraph containing only personas from a specific category.

from fcc.knowledge.builders import build_full_fcc_graph

graph = build_full_fcc_graph()
ml_nodes = [n for n in graph.nodes.values() if n.metadata.get("category") == "ml_lifecycle"]
subgraph = graph.subgraph([n.node_id for n in ml_nodes])
print(f"ML Lifecycle subgraph: {len(subgraph.nodes)} nodes, {len(subgraph.edges)} edges")

Expected output: A KnowledgeGraph containing only the 9 ML Lifecycle persona nodes and the edges between them, preserving internal handoff and feedback relationships.


6. Export to JSON-LD

Serialize the knowledge graph to JSON-LD for web-friendly linked data.

from fcc.knowledge.builders import build_full_fcc_graph
from fcc.knowledge.serializers import JSONLDSerializer

graph = build_full_fcc_graph()
serializer = JSONLDSerializer()
jsonld = serializer.serialize(graph)
print(jsonld[:500])

Expected output: A JSON-LD document with @context defining FCC namespaces, @graph containing node and edge objects with typed relationships and metadata.


7. Find All Downstream Dependents

Recursively find all nodes that depend on a given persona (transitive closure).

from fcc.knowledge.builders import build_full_fcc_graph

graph = build_full_fcc_graph()

def find_all_downstream(graph, start_id, visited=None):
    if visited is None:
        visited = set()
    neighbors = graph.get_neighbors(start_id, direction="outgoing")
    for n in neighbors:
        if n.node_id not in visited:
            visited.add(n.node_id)
            find_all_downstream(graph, n.node_id, visited)
    return visited

dependents = find_all_downstream(graph, "RC")
print(f"RC has {len(dependents)} downstream dependents: {sorted(dependents)}")

Expected output: A set of all persona and artifact IDs that are transitively reachable from RC via outgoing edges. This shows the full impact scope of the Research Crafter.


8. Build an Ontology Schema

Generate an FCCOntology schema from the knowledge graph.

from fcc.knowledge.ontology import FCCOntology
from fcc.knowledge.builders import build_full_fcc_graph

graph = build_full_fcc_graph()
ontology = FCCOntology.from_graph(graph)
print(f"Classes: {len(ontology.classes)}")
print(f"Properties: {len(ontology.properties)}")
print(f"Individuals: {len(ontology.individuals)}")

Expected output: An ontology object with classes for each node type (Persona, Action, Artifact, etc.), properties for each edge type (handoff, feedback, orchestrates, etc.), and individuals for each concrete node.


9. Merge Two Knowledge Graphs

Combine knowledge graphs from different domains into a single unified graph.

from fcc.knowledge.graph import KnowledgeGraph

graph_a = KnowledgeGraph(name="ml_domain")
graph_b = KnowledgeGraph(name="devops_domain")

# Add nodes to each graph...
# Then merge
merged = KnowledgeGraph.merge([graph_a, graph_b], name="unified")
print(f"Merged: {len(merged.nodes)} nodes, {len(merged.edges)} edges")

Expected output: A single KnowledgeGraph containing all nodes and edges from both source graphs. Duplicate node IDs are resolved by the merge strategy (default: keep first, annotate conflicts).


10. Federated Cross-Namespace Query

Query across federated knowledge graphs from different projects.

from fcc.knowledge.federation import FederatedKnowledgeGraph
from fcc.federation.namespace import NamespaceRegistry

registry = NamespaceRegistry()
federated = FederatedKnowledgeGraph(namespace_registry=registry)

# Register graphs from different namespaces
federated.register_graph("fcc", fcc_graph)
federated.register_graph("paom", paom_graph)

# Cross-namespace query
results = federated.resolve("Research Crafter", source_ns="fcc", target_ns="paom")
for result in results:
    print(f"FCC:RC maps to PAOM:{result.entity_id} (confidence: {result.confidence})")

Expected output: A list of resolved entities in the target namespace that correspond to the source entity, with confidence scores indicating match quality. This enables cross-project knowledge discovery.