Graphs

Graphs allow you to store and query knowledge graphs, social networks, and other graph-structured data. SeeMe.ai uses DGraph as the underlying graph database.

Graphs

Get all graphs

graphs = client.get_graphs()

Create a graph

from seeme.types import Graph

my_graph = Graph(
    name="Knowledge Graph",
    description="A graph of entities and relationships",
    kind="knowledge"
)

my_graph = client.create_graph(my_graph)
ParameterTypeDescription
graphGraphThe graph object

Graph properties:

PropertyTypeDescription
idstrUnique id for the graph
created_atstrThe creation date
updated_atstrLast updated date
namestrThe graph name
descriptionstrThe graph description
user_idstrThe user id of the graph creator
active_version_idstrThe id of the active graph version
kindstrGraph type: “property”, “knowledge”, “social”, “network”
configstrJSON configuration
schema_configstrNode/edge type definitions
versionsList[GraphVersion]List of graph versions
publicboolWhether the graph is public

Get a graph

graph = client.get_graph(my_graph.id)

Update a graph

my_graph.description = "Updated knowledge graph"
client.update_graph(my_graph)

Delete a graph

client.delete_graph(my_graph.id)

Get graph statistics

stats = client.get_graph_stats(my_graph.id)

Graph Versions

Get all graph versions

versions = client.get_graph_versions(my_graph.id)

Create a graph version

from seeme.types import GraphVersion

new_version = GraphVersion(
    name="v2",
    description="Expanded schema",
    graph_id=my_graph.id
)

new_version = client.create_graph_version(my_graph.id, new_version)

GraphVersion properties:

PropertyTypeDescription
idstrUnique id for the version
namestrThe version name
descriptionstrThe version description
graph_idstrThe parent graph id
versionstrVersion label
version_numberintAuto-incrementing version number
space_namestrDGraph space name
graph_schemastrSchema definition
node_countintNumber of nodes
edge_countintNumber of edges
configstrVersion configuration

Get a graph version

version = client.get_graph_version(my_graph.id, new_version.id)

Update a graph version

new_version.description = "Production schema"
client.update_graph_version(my_graph.id, new_version)

Delete a graph version

client.delete_graph_version(my_graph.id, new_version.id)

Set active graph version

client.set_active_graph_version(my_graph.id, new_version.id)

Duplicate a graph version

Create a copy of an existing version:

duplicated = client.duplicate_graph_version(my_graph.id, new_version.id)

Graph Nodes

Create a node

from seeme.types import GraphNode

node = GraphNode(
    type="Person",
    external_id="person_001",
    properties={
        "name": "John Doe",
        "age": 30,
        "email": "john@example.com"
    }
)

result = client.create_graph_node(my_graph.id, new_version.id, node)

GraphNode properties:

PropertyTypeDescription
uidstrDGraph internal UID
external_idstrYour custom identifier
typestrNode type (e.g., “Person”, “Company”)
propertiesdictKey-value properties

Create multiple nodes (bulk)

nodes = [
    GraphNode(type="Person", external_id="p1", properties={"name": "Alice"}),
    GraphNode(type="Person", external_id="p2", properties={"name": "Bob"}),
    GraphNode(type="Company", external_id="c1", properties={"name": "Acme Inc"})
]

result = client.create_graph_nodes(my_graph.id, new_version.id, nodes)

Get a node

node = client.get_graph_node(my_graph.id, new_version.id, node_uid)

Update a node

updated_node = GraphNode(
    type="Person",
    properties={"name": "John Smith", "age": 31}
)

client.update_graph_node(my_graph.id, new_version.id, node_uid, updated_node)

Delete a node

client.delete_graph_node(my_graph.id, new_version.id, node_uid)

Query nodes

params = {
    "type": "Person",
    "limit": 100
}

nodes = client.query_graph_nodes(my_graph.id, new_version.id, params)

Graph Edges

Create an edge

from seeme.types import GraphEdge

edge = GraphEdge(
    source_uid=person_node_uid,
    target_uid=company_node_uid,
    type="WORKS_AT",
    properties={
        "since": "2020-01-01",
        "role": "Engineer"
    }
)

result = client.create_graph_edge(my_graph.id, new_version.id, edge)

GraphEdge properties:

PropertyTypeDescription
uidstrDGraph internal UID
source_uidstrSource node UID
target_uidstrTarget node UID
typestrEdge type (e.g., “WORKS_AT”, “KNOWS”)
propertiesdictKey-value properties

Create multiple edges (bulk)

edges = [
    GraphEdge(source_uid=p1_uid, target_uid=p2_uid, type="KNOWS"),
    GraphEdge(source_uid=p1_uid, target_uid=c1_uid, type="WORKS_AT"),
]

result = client.create_graph_edges(my_graph.id, new_version.id, edges)

Delete an edge

client.delete_graph_edge(my_graph.id, new_version.id)

Graph Queries

Execute DQL (DGraph Query Language) queries on your graph:

query = """
{
    people(func: type(Person)) {
        uid
        name
        age
        works_at {
            name
        }
    }
}
"""

result = client.execute_graph_query(my_graph.id, new_version.id, query)
ParameterTypeDescription
graph_idstrThe graph id
version_idstrThe graph version id
querystrDQL query string

Example: Find connected nodes

query = """
{
    connections(func: uid("0x1")) {
        uid
        name
        knows {
            uid
            name
        }
    }
}
"""

result = client.execute_graph_query(my_graph.id, new_version.id, query)

Example: Filter by property

query = """
{
    engineers(func: type(Person)) @filter(eq(role, "Engineer")) {
        uid
        name
        email
    }
}
"""

result = client.execute_graph_query(my_graph.id, new_version.id, query)