Multi Model - SAP HANA Cloud Knowledge Graph Engine

Multi Model - SAP HANA Cloud Knowledge Graph Engine

SAP HANA Cloud is a comprehensive database-as-a-service that includes various multi-model engines, specifically designed for handling diverse types of business data. Among these is the SAP HANA Cloud knowledge graph engine which helps businesses connect and analyze corporate knowledge with high efficiency and precision by using data stored in a graph to answer complex queries.

The SAP HANA Cloud knowledge graph engine enables developers to use business context to create applications that infer logic, apply reasoning, and deliver more reliable and relevant results. Knowledge graphs are especially beneficial for GenAI and AI-assisted use cases, providing more accurate grounding of large language models (LLMs) that result in enhanced, intuitive user interactions and improved business processes.

Knowledge Graph and RDF

A knowledge graph is a structured representation of data (adhering to ontology rules), enhanced by real-world information. The knowledge graph captures relationships between entities, such as people, products, or events, and connects them in a meaningful way.

The SAP HANA Cloud knowledge graph engine facilitates working with knowledge graphs built on the RDF framework. RDF, or Resource Description Framework, is a W3C standard that structures graph data using triples in the format of subject-predicate-object. This framework ensures that information is stored semantically, enabling machines to understand the relationships and attributes of various data points.

Communication with the knowledge graph engine utilizing RDF is profoundly enhanced by the SPARQL language. SPARQL, which stands for SPARQL Protocol and RDF Query Language, is specifically designed to query and manipulate RDF data. Through SPARQL, users can pose intricate questions to their graph data, enabling complex queries and the retrieval of highly specific information, facilitating a deeper understanding and actionable insights from the knowledge graph.

Combination of Structure and Semantics

While SQL is powerful for structured, transactional data, RDF provides a more flexible, semantic, and interoperable approach for integrating and querying data across diverse sources. For multi-source, knowledge-driven applications, RDF and knowledge graphs offer significant advantages.

Unique Identifiers: Use URIs (Uniform Resources Identifiers) and namespaces to uniquely identify entities across distributed systems.

Standardized Semantics: Utilize industry-standard vocabularies (e.g. schema.org) to define consistent relationships between data.

Graph-based Querying: Enable powerful, flexible queries using SPARQL, optimized for connected data and real-time insights.

New SQL functions/procedures:

  • SPARQL_TABLE() – function to embed SPARQL SELECT queries in SQL statements
  • SPARQL_EXECUTE() – built-in procedure to execute SPARQL queries
  • SQL_TABLE() - A SPARQL function to embed SQL queries directly within SPARQL statements

The knowledge graph engine also supports importing/exporting RDF file formats (eg: turtle, json-LD), as well as multiple response formats like json, xml and csv.

Use Cases

Below is a selection of use cases that highlight the various advantages and benefits of integrating the knowledge graph with SAP HANA Cloud:

  • Enhance Intelligent Data Applications & Gen AI:

    The in-memory database capabilities of SAP HANA Cloud already provide high-performance data processing, but the addition of a knowledge graph enables applications to gain an extra layer of understanding. This new feature is particularly valuable when it comes to enabling Gen AI use cases, such as grounding large language models (also called GraphRAG) in domain-specific knowledge. By storing and retrieving semantic facts about a business’s operations, relationships, and data, the knowledge graph can provide LLMs with the context they need to deliver more accurate and relevant responses - ultimately improving the quality of human-computer interaction.

  • Establish a Data Fabric:

    With the knowledge graph engine working seamlessly alongside the other multi-model engines in SAP HANA Cloud, such as the relational data, spatial, graph, JSON document store and vector engines, businesses can now bring structured and unstructured data together in a single platform, establishing a data fabric. This unified approach allows companies to query and analyze data holistically, breaking down traditional data silos. The semantic linking of data creates a unified view, allowing for accurate contextual understanding of complex concepts, such as the term “material” in different scenarios like manufacturing, sales, or procurement.

  • Improve Decision Making & Logical Inference:

    Knowledge graphs in general contribute to better data governance by establishing clearer relationships and rules for data entities, which improves logical reasoning and helps users make more informed, accurate decisions with fewer errors.

  • Linked Data and Federated Querying

    Integrate internal data with Linked Open Data (LOD) and enable cross-domain querying with federated SPARQL. For example, to enrich clinical research with external biomedical ontologies.

  • Regulatory Compliance & Fraud Detection

    Automate compliance checks with RDF-based rules and detect hidden risks via graph-based anomaly detection. For example to identify fraud through money transfer and relationship analysis.

Knowledge Graph Benefits

The following are a list of value propositions made possible by leveraging the power of the SAP HANA Cloud knowledge graph engine:

  • Enhances AI Workloads (RAG Scenarios): Provides semantic linking, fact-checking, and reasoning to improve AI accuracy and explainability.

  • Improved Querying & Insights: Enables intelligent querying with SPARQL, allowing pattern-based discovery across complex data relationships.

  • Seamless Integration with Enterprise Data: Bridges master data, ontologies, and external taxonomies for context-aware decision-making.

  • Semantic Data Enrichment: Adds context and relationships to structured and unstructured data, improving AI accuracy and reasoning.

  • Integrated with SAP HANA Cloud: Runs natively within SAP HANA Cloud with no extra licensing costs, ensuring consistent security and authentication.

  • Synergy with Multi-Model Capabilities: Works seamlessly with SQL, Spatial, Document Store, Vector, and Graph Engines.

This lesson will provide participants with a foundational understanding of these concepts through a hands-on practical exercise. This will provide the opportunity to engage directly with the SAP HANA Cloud knowledge graph engine, construct RDF triples, and utilize SPARQL to execute queries against graph data.


Try it out!

Let’s look at a practical use case scenario using the meta data of a project landscape.

The following SPARQL_EXECUTE function will create a knowledge graph containing the Meta Data for the following objects involved in a development project:

  • A Sales Monitor application for an SAP S4/HANA system
  • A View called ‘Monthly Sales View’ in the production S4/HANA system
  • A table called ‘Sales Orders Table’ in the S4/HANA system
  • A database table in the SAP HANA Cloud database called GX_SALES.

Ensure you are logged into Database Explorer with your user.

  1. Open up a new SQL console window and run the below SPARQL_EXECUTE query. This will create a knowledge graph in the schema which describes the relationships between different objects in the system landscape, and also stores information about all the meta data of the project:
Code Snippet
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
CALL SPARQL_EXECUTE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> INSERT DATA { GRAPH <kg_metadata_{placeholder|userid}> { <http://kg.sap.com/apps/SalesMonitor> a :Application ; rdfs:label "Sales Monitor App" ; :usesObject <http://kg.sap.com/db/views/MonthlySales> ; :ownedBy "alice.jones@sap.com" ; :createdOn "2024-02-10T10:30:00Z"^^xsd:dateTime ; :environment "PRD" ; :system "SAP_S4HANA" . <http://kg.sap.com/db/views/MonthlySales> a :View ; rdfs:label "Monthly Sales View" ; :dependsOn <http://kg.sap.com/db/tables/SalesOrders> ; :hasColumn <http://kg.sap.com/db/columns/MonthlySales.TotalAmount> ; :createdOn "2024-01-15T08:00:00Z"^^xsd:dateTime ; :environment "PRD" ; :system "SAP_S4HANA" . <http://kg.sap.com/db/tables/SalesOrders> a :Table ; rdfs:label "Sales Orders Table" ; :createdOn "2022-07-12T09:00:00Z"^^xsd:dateTime ; :system "SAP_S4HANA" . <http://kg.sap.com/db/columns/MonthlySales.TotalAmount> a :Column ; rdfs:label "Total Amount" . <http://kg.sap.com/db/tables/HC_DEV.GX_SALES> a :Table ; rdfs:label "GX_SALES Table" ; :createdOn "2024-03-31T00:00:00Z"^^xsd:dateTime ; :system "SAP_HANA_CLOUD" ; :schema "HC_DEV" ; :hasColumn <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.SALES_ID> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.SALES_DATE> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.SALES_TIME> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.CUSTOMER_ID> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.PRODUCT_ID> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.QUANTITY> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.DISCOUNT_PERCENTAGE> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.DISCOUNT_AMOUNT> , <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.PRICE> . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.SALES_ID> a :Column ; rdfs:label "SALES_ID" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.SALES_DATE> a :Column ; rdfs:label "SALES_DATE" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.SALES_TIME> a :Column ; rdfs:label "SALES_TIME" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.CUSTOMER_ID> a :Column ; rdfs:label "CUSTOMER_ID" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.PRODUCT_ID> a :Column ; rdfs:label "PRODUCT_ID" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.QUANTITY> a :Column ; rdfs:label "QUANTITY" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.DISCOUNT_PERCENTAGE> a :Column ; rdfs:label "DISCOUNT_PERCENTAGE" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.DISCOUNT_AMOUNT> a :Column ; rdfs:label "DISCOUNT_AMOUNT" ; :dataType "NVARCHAR(50)" . <http://kg.sap.com/db/columns/HC_DEV.GX_SALES.PRICE> a :Column ; rdfs:label "PRICE" ; :dataType "NVARCHAR(50)" . } } ', 'Accept: application/sparql-results+json Content-Type: application/sparql-query', ?, ?);

  1. View the entire dataset using the SPARQL_TABLE() function in the following query:
Code Snippet
1234567
-- View knowledge graph data SELECT * FROM SPARQL_TABLE(' SELECT ?s ?p ?o FROM <kg_metadata_{placeholder|userid}> WHERE { ?s ?p ?o . } ORDER BY ?s ');

  1. From the project metadata, to list all the applications in the project and their associated views, run the following query:
Code Snippet
1234567891011121314
-- List all applications and their associated views SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?application ?appLabel ?view ?viewLabel FROM <kg_metadata_{placeholder|userid}> WHERE { ?application a :Application ; rdfs:label ?appLabel ; :usesObject ?view . ?view rdfs:label ?viewLabel . } ');

  1. Now list the views involved in the project and any tables they depend on:
Code Snippet
1234567891011121314
-- Show views and the tables they depend on SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?view ?viewLabel ?table ?tableLabel FROM <kg_metadata_{placeholder|userid}> WHERE { ?view a :View ; rdfs:label ?viewLabel ; :dependsOn ?table . ?table rdfs:label ?tableLabel . } ');

  1. If we want to get a list of all the tables involved in the project, along with the column names or fields, the below query will return that information. This could be useful to get an idea of what tables or columns could be used to further enhance the application.
Code Snippet
123456789101112131415
-- List all tables and their columns SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?table ?tableLabel ?column ?columnLabel FROM <kg_metadata_{placeholder|userid}> WHERE { ?table a :Table ; rdfs:label ?tableLabel ; :hasColumn ?column . ?column rdfs:label ?columnLabel . } ORDER BY ?table ?column ');

  1. Let’s find out some more details about the GX_SALES table:
Code Snippet
12345678910111213141516
-- Get basic details of the GX_SALES table SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?table ?label ?schema ?system ?createdOn FROM <kg_metadata_{placeholder|userid}> WHERE { ?table a :Table ; rdfs:label "GX_SALES Table" ; rdfs:label ?label ; :schema ?schema ; :system ?system ; :createdOn ?createdOn . } ');

  1. The following query will return the names of all the columns or fields in the GX_SALES table, along with their data types. This could be useful when deciding on a key field to use in an application, and what operations can be performed on that field:
Code Snippet
1234567891011121314
--Get column names and their data types in GX_SALES SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?column ?columnLabel ?dataType FROM <kg_metadata_{placeholder|userid}> WHERE { <http://kg.sap.com/db/tables/HC_DEV.GX_SALES> :hasColumn ?column . ?column rdfs:label ?columnLabel ; :dataType ?dataType . } ORDER BY ?columnLabel ');

  1. Sometimes it may be useful to determine which columns use a particular data type or refer to a particular value that a developer would need to consider in developing applications. The following query will return all the columns which refer to Discount in their label:
Code Snippet
12345678910111213
-- Find all columns containing "DISCOUNT" in their label SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?column ?label ?table FROM <kg_metadata_{placeholder|userid}> WHERE { ?table :hasColumn ?column . ?column rdfs:label ?label . FILTER(CONTAINS(LCASE(STR(?label)), "discount")) } ');

  1. It’s also possible to add a filter on the data. Let’s say we want to get a list of the metadata which was created in 2024. We can do that with the following query:
Code Snippet
1234567891011121314
-- Find all metadata created in 2024 SELECT * FROM SPARQL_TABLE(' PREFIX : <http://kg.sap.com/ontology/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?object ?type ?createdOn FROM <kg_metadata_{placeholder|userid}> WHERE { ?object a ?type ; :createdOn ?createdOn . FILTER (STRSTARTS(STR(?createdOn), "2024")) } ORDER BY ?createdOn ');

This is just a high-level overview of the possibilities available to unlock value from company-wide data. Here are some other ways in which the knowledge graph engine can be leveraged:

  • Add extensibility & flexibility to handle growing data needs​
  • Enable data consistency with standard vocabulary & defined schemas​
  • Leverage open and external data​
  • Improve data discovery and insights​
  • Enhance extensive search and query capabilities​
  • Provide structured data that enhances the accuracy and relevance of AI/ML models

Overall, knowledge graphs empower businesses to leverage their data more effectively, leading to smarter decisions and enhanced operational performance.