Adding Fact Triples

How to add fact triples to your Graphiti graph

A โ€œfact tripleโ€ consists of two nodes and an edge between them, where the edge typically contains some fact. You can manually add a fact triple of your choosing to the graph like this:

1from graphiti_core.nodes import EpisodeType, EntityNode
2from graphiti_core.edges import EntityEdge
3import uuid
4from datetime import datetime
5
6source_name = "Bob"
7target_name = "bananas"
8source_uuid = "some existing UUID" # This is an existing node, so we use the existing UUID obtained from Neo4j Desktop
9target_uuid = str(uuid.uuid4()) # This is a new node, so we create a new UUID
10edge_name = "LIKES"
11edge_fact = "Bob likes bananas"
12
13
14source_node = EntityNode(
15 uuid=source_uuid,
16 name=source_name,
17 group_id=""
18)
19target_node = EntityNode(
20 uuid=target_uuid,
21 name=target_name,
22 group_id=""
23)
24edge = EntityEdge(
25 group_id="",
26 source_node_uuid=source_uuid,
27 target_node_uuid=target_uuid,
28 created_at=datetime.now(),
29 name=edge_name,
30 fact=edge_fact
31)
32
33await graphiti.add_triplet(source_node, edge, target_node)

When you add a fact triple, Graphiti will attempt to deduplicate your passed in nodes and edge with the already existing nodes and edges in the graph. If there are no duplicates, it will add them as new nodes and edges.

Also, you can avoid constructing EntityEdge or EntityNode objects manually by using the results of a Graphiti search (see Searching the Graph).

Built with