Introduction to Knowledge Graphs

Introduction

ArcGIS Knowledge integrates graph and spatial analytics to support data discovery, collaborative investigations, link analysis, and information sharing across organizations. An ArcGIS Enterprise portal configured for ArcGIS Knowledge is required. Find out more at Configure ArcGIS Knowledge

In order to use the arcgis.graph capabilities in the ArcGIS API for Python, you must have an existing knowledge graph. Learn more about creating knowledge graphs.

What is a knowledge graph?

A knowledge graph consists of entities and the relationships between them. Each of these entities and relationships can also have properties that contain information describing the entity or relationship. Entities in the model represent real-world objects, concepts, or events. Relationships in the model express how entities are associated with each other.

Key Terms

A few key terms to understand are:

  • Knowledge Graph: A network that connects people, places, things, and events with each other through relationships.
  • Data Model: Defines the types of entities and relationships that can exist in the knowledge graph along with their properties.
  • Entity: Representation of a specific thing in the graph such as a person, building, vehicle, etc. These can have any number of properties and be either spatial or nonspatial.
  • Relationship: Connects two entities in the graph and represents their relationship such as knows, works_at, drives, etc. These can have any number of properties and are nonspatial.
  • Properties: key-value pairs that describe the entity or relationships such as name, start_date, make, model, etc.

Connect

Using the ArcGIS API for Python, you can connect to a KnowledgeGraph with arcgis.graph:

from arcgis.gis import GIS
from arcgis.graph import KnowledgeGraph

url = "https://myHostName.domain.com/server/rest/services/Hosted/myServiceName/KnowledgeGraphServer"
gis = GIS("home")
knowledge_graph = KnowledgeGraph(url=url, gis=gis)

A knowledge graph service is composed of two primary resources, the data and data model. The data contains entities and relationships with their associated properties.

Create

Using the ArcGIS API for Python, you can create a new Knowledge Graph using create_service().

gis = GIS("home")
result = gis.content.create_service(
    name="myKnowledgeGraph",
    capabilities="Query,Editing,Create,Update,Delete",
    service_type="KnowledgeGraph",
)

Services can also be created using create parameters to choose more service options.

result = gis.content.create_service(
    name="",
    service_type="KnowledgeGraph",
    create_params={
        "name": "myKnowledgeGraph",
        "capabilities": "Query",
        "jsonProperties": {
            "supportsProvenance": False,
            "arcgisManagedData": False,
            "dataSourceItemID": "f63a6725058c4c05a63480521acffe01",
        },
    },
)

Finally, the result from create_service can be used to initialize the KnowledgeGraph.

knowledge_graph = KnowledgeGraph(url=result.url, gis=gis)

Data Model

The data model defines the schema of the knowledge graph by defining the entity types and relationship types in the graph:

knowledge_graph.datamodel

The response from datamodel has many useful components that describe the schema of the knowledge graph. Important information to look for on the data model includes spatial reference, strictness, whether the service is arcgis managed, information on the unique identifier property, and search indexes. The data model also includes detailed information on each entity and relationship type.

{'data_model_timestamp': datetime.datetime(2023, 3, 22, 14, 4, 44, 432000),
 'spatial_reference': {'wkid': 4326},
 'entity_types': <dictionary of entity types>, # see below for more info on type dictionaries
 'relationship_types': <dictionary of relationship types>, # see below for more info on type dictionaries
 'strict': False,
 'objectid_property': 'objectid',
 'globalid_property': 'globalid',
 'arcgis_managed': True,
 'identifier_info': {'identifier_mapping_info': {'uniform_property': {'identifier_property_name': 'globalid'}},
  'identifier_generation_info': {'uuid_method_hint': 'esriUUIDESRI'}},
 'search_indexes': {'esri__search_idx': {'name': 'esri__search_idx',
   'supported_category': 'Both',
   'analyzers': [{'name': 'text_en'}, {'name': 'identity'}],
   'search_properties': {'Document': {'property_names': ['metadata',
      'keywords',
      'fileExtension',
      'globalid',
      'name',
      'text',
      'title',
      'contentType',
      'url']},
    'HasDocument': {'property_names': ['globalid']},
    'Observation': {'property_names': ['quality_grade',
      'globalid',
      'time_observed',
      'description',
      'location',
      'observation_url',
      'photo_url',
      'species_guess',
      'most_disagree_with_identificati',
      'place_guess']},
    'Observed': {'property_names': ['globalid']},
    'ObservedIn': {'property_names': ['globalid']},
    'Reviewed': {'property_names': ['globalid']},
    'Species': {'property_names': ['taxon_common_name',
      'globalid',
      'taxon_name',
      'taxon_wikipedia',
      'taxon_photo_url']},
    'User': {'property_names': ['globalid', 'name', 'created_date']}}}}}

Entity and relationship types each have a format very similar to each other including basic information about the type like the name, role and strictness as well as properties and field indexes on the type. For a single type, this could look like:

{'Company': {
    'name': 'Company',
    'alias': '',
    'role': 'esriGraphNamedObjectRegular',
    'strict': False,
    'properties': {
        'name': {
            'name': 'name',
            'alias': 'name',
            'fieldType': 'esriFieldTypeString',
            'hasZ': False,
            'hasM': False,
            'nullable': True,
            'editable': True,
            'visible': True,
            'required': False,
            'isSystemMaintained': False,
            'role': 'esriGraphPropertyRegular'
        },
        'objectid': {
            'name': 'objectid',
            'alias': 'objectid',
            'fieldType': 'esriFieldTypeOID',
            'hasZ': False,
            'hasM': False,
            'nullable': False,
            'editable': False,
            'visible': True,
            'required': True,
            'isSystemMaintained': True,
            'role': 'esriGraphPropertyRegular'
        },
        'globalid': {
            'name': 'globalid',
            'alias': 'globalid',
            'fieldType': 'esriFieldTypeGlobalID',
            'hasZ': False,
            'hasM': False,
            'nullable': False,
            'editable': False,
            'visible': True,
            'required': True,
            'isSystemMaintained': True,
            'role': 'esriGraphPropertyRegular'
        },
        'shape': {
            'name': 'shape',
            'alias': 'shape',
            'fieldType': 'esriFieldTypeGeometry',
            'geometryType': 'esriGeometryPoint',
            'hasZ': False,
            'hasM': False,
            'nullable': True,
            'editable': True,
            'visible': True,
            'required': False,
            'isSystemMaintained': False,
            'role': 'esriGraphPropertyRegular'
        }
    },
   'field_indexes': {
        'esri__oid_idx': {
            'name': 'esri__oid_idx',
            'fields': ['objectid'],
            'isAscending': True,
            'isUnique': True
        },
        'esri__globalid_idx': {
            'name': 'esri__globalid_idx',
            'fields': ['globalid'],
            'isAscending': True,
            'isUnique': True
        },
        'esri__shape_geo_idx': {
            'name': 'esri__shape_geo_idx',
            'fields': ['shape'],
            'isAscending': True,
            'isUnique': False
        }
    }
}

Path Forward

The knowledge graph can be used to search and query a knowledge graph as well as add, update and delete types and instances of the data. These will help you to create and use your knowledge graphs.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.