54147 Session PPT - ComplexRelationshipsMadeSimple.pdf

dumian 91 views 44 slides Oct 08, 2024
Slide 1
Slide 1 of 44
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44

About This Presentation

graph technology


Slide Content

MelliAnnamalai and Denise Myrick
Graph Product Management
Oracle Database
July 25, 2024
Complex Relationships Made
Simple with Graphs
In Oracle Database 23ai

Are you connected to someone you meet here?
Copyright © 2024, Oracle and/or its affiliates2
Olivia
Emily
Harper
Ethan
Liam
Ava
Lucas
Amelia
Alex Henry
Mia

Are you connected to someone you meet here?
Copyright © 2024, Oracle and/or its affiliates3
Olivia
Emily
Harper
Ethan
Liam
Ava
Lucas
Amelia
Alex Henry
Mia

Is Bank Account 1Connected to Bank Account 833?
ACCT:
484
ACCT:
730
ACCT:
1
ACCT:
609
ACCT:
484
ACCT:
703
ACCT:
457
ACCT:
333
ACCT:
673
ACCT:
964
ACCT:
833
Copyright © 2024, Oracle and/or its affiliates4

Is Bank Account 1Connected to Bank Account 833?
ACCT:
484
ACCT:
730
ACCT:
1
ACCT:
609
ACCT:
484
ACCT:
703
ACCT:
457
ACCT:
333
ACCT:
673
ACCT:
964
ACCT:
833
Copyright © 2024, Oracle and/or its affiliates5

Is ID 1 Connected to ID 833?
Copyright © 2024, Oracle and/or its affiliates6
BANK_ACCOUNTS BANK_TRANSFERS
Is ID 1connected to ID 833,when using
information in these tables?
?
ID NAME
1
2
3

672
673
674

831
832
833

SRC_ACCT_IDDST_ACCT_IDAMOUNT
1 672 1000
1 584 1000
1 259 100000
2 833 5001
2 840 7050
2 493 4363
… … …
672 831 5425
… … …
831 833 256
… … …

Is ID 1 Connected to ID 833?
Copyright © 2024, Oracle and/or its affiliates7
BANK_ACCOUNTS BANK_TRANSFERS
Is ID1connected to ID833,when using
information in these tables?
?
ID NAME
1
2
3

672
673
674

831
832
833

SRC_ACCT_IDDST_ACCT_IDAMOUNT
1 672 1000
1 584 1000
1 259 100000
2 833 5001
2 840 7050
2 493 4363
… … …
672 831 5425
… … …
831 833 256
… … …

Is ID 1Connected to ID 833?
Copyright © 2024, Oracle and/or its affiliates8
BANK_ACCOUNTS BANK_TRANSFERS
?
ID NAME
1
2
3

672
673
674

831
832
833

SRC_ACCT_IDDST_ACCT_IDAMOUNT
1 672 1000
1 584 1000
1 259 100000
2 833 5001
2 840 7050
2 493 4363
… … …
672 831 5425
… … …
831 833 256
… … …
831
1
672
601
584
833
493960
840
2
Graph view of data
Edges
Nodes

Is ID <src> connected to ID <dst> in 1 to 3 hops?
Copyright © 2024, Oracle and/or its affiliates9
--With new GRAPH_TABLE and MATCH syntax
SELECTaccount_id
FROMGRAPH_TABLE(bank_graph
MATCH (src)-[is bank_transfers]->{1,3}(dst)
COLUMNS(src.id as account_id) );
--SQL without new syntax (12 joins and 3 UNION ALLs)
SELECTv1.id as account_id1 , v2.id as account_id2
FROM bank_accountsv1 ,
bank_transfersbtx,
bank_accountsv2
WHERE(v1.id = btx.src_acct_id ANDv2.id = btx.dst_acct_id)
AND v1.id=<src> ANDv2.id=<dst>
UNION ALL
SELECTv1.id as account_id1 , v2.id as account_id2
FROM bank_accountsv1 ,
bank_transfersbtx,
bank_accountsbc2,
bank_transfersbtx2 ,
bank_accountsv2
WHERE(v1.id = btx.src_acct_id ANDbc2.id = btx.dst_acct_id AND
bc2.id = btx2.src_acct_id AND v2.id = btx2.dst_acct_id )
AND v1.id=<src> AND v2.id= <dst>
UNION ALL
SELECTv1.id as account_id1 ,v2.id as account_id2
FROM bank_accountsv1 ,
bank_transfersbtx,
bank_accountsbc2,
bank_transfersbtx2 ,
bank_accountsbac4,
bank_transfersbtx5 ,
bank_accountsv2
WHERE(v1.id = btx.src_acct_id ANDbc2.id = btx.dst_acct_id AND
bc2.id = btx2.src_acct_id ANDbac4.id = btx2.dst_acct_id AND
bac4.id = btx5.src_acct_id ANDv2.id = btx5.dst_acct_id )
AND v1.id=<src> ANDv2.id= <dst>
;
831
1
672
601
584
833
493960
840
2

More Graph Queries
Copyright © 2024, Oracle and/or its affiliates10
960
Which nodes are directly
connected to node
Which nodes are indirectly
connected to node with
1 or 2 hops
960
831
1
672
601
584
833
493960
840
2
831
1
672
601
584
833
493960
840
2
831
1
672
601
584
833
493960
840
2
What are all the paths from
node to
960
1

11 Copyright © 2024, Oracle and/or its affiliates
A Language for Property Graphs
Adding syntax to SQL

SQL/PGQ in SQL:2023
Copyright © 2024, Oracle and/or its affiliates12
SQL syntax for DDL
operations

Create property graph

Drop property graph
SQL syntax for DML
operations

Queries

Graph is like a Viewon Relational Tables

No data copy –graph is a view on relational tables

Insert/update/delete in underlying tables instantly available in a graph

Fast, concurrent updates

Well suited for operational workloads
13 Copyright © 2024, Oracle and/or its affiliates

Operational Workflowswith Property Graphs
Copyright © 2024, Oracle and/or its affiliates14
High degree of concurrency Transactional consistency High availability
Maintain same TPC-C
throughput with graphs
Integrate with JSON and
other types in the database
Flashback for historical
view of graphs

FastExecution

Extreme scalability of SQL engine for graph queries

Sub-millisecond response times for billions of nodes and edges

Concurrency

Millions of users can concurrently run graph queries and update graph data
15 Copyright © 2024, Oracle and/or its affiliates

Oracle Database 23ai
16 Copyright © 2024, Oracle and/or its affiliates
Unification of
JSON and Relational
Unification of
Graph and Relational
Unification of
AI and Databases
AI
One part of an app can treat data as relational, while other parts treat the samedata as a
document, and others treat it as a graph, and unify with AI

17 Copyright © 2024, Oracle and/or its affiliates
Demo

Creating the GraphView
Copyright © 2024, Oracle and/or its affiliates18
ID NAME
1
2
3

672
673
674

831
832
833

SRC_ACCT_IDDST_ACCT_IDAMOUNT
1 672 1000
1 584 1000
1 259 100000
2 833 5001
2 840 7050
2 493 4363
… … …
672 831 5425
… … …
831 833 256
… … …
1000
5001
CREATE PROPERTY GRAPH BANK_GRAPH
VERTEX TABLES (
BANK_ACCOUNTS
KEY (ID)
PROPERTIES (ID, Name, Balance)
)
EDGE TABLES (
BANK_TRANSFERS
KEY (TXN_ID)
SOURCE KEY (src_acct_id) REFERENCES BANK_ACCOUNTS(ID)
DESTINATION KEY (dst_acct_id) REFERENCES BANK_ACCOUNTS(ID)
PROPERTIES (src_acct_id, dst_acct_id, amount)
);
Graph name
Table holding vertex
data
Column values
become properties
Table holding edge
data (connections
you want to traverse)
Column values
become properties
SOURCE and
DESTINATION KEYS link
vertices with the edge

Query a Graph
Copyright © 2024, Oracle and/or its affiliates19
select account_idfrom GRAPH_TABLE(bank_graph
MATCH(src)-[is bank_transfers]->(dst)
COLUMNS(src.id as account_id) );
Vertices are in (), edges are in []
Columns to return
bank_transfers
src dst
List all accounts that have transferred money to another account

Query a Graph
Copyright © 2024, Oracle and/or its affiliates20
select account_idfrom GRAPH_TABLE(bank_graph
MATCH(src)-[is bank_transfers]->(dst)
COLUMNS(src.id as account_id) );
Vertices are in (), edges are in []
Columns to return
select account_idfrom GRAPH_TABLE(bank_graph
MATCH(src)-[is bank_transfers]->{1,3}(dst)
COLUMNS(src.id as account_id) );
bank_transfers
src dst
bank_transfers bank_transfers
List all accounts that have transferred money to another account
List all accounts that have transferred money through intermediate accounts

Query a Graph
Copyright © 2024, Oracle and/or its affiliates21
SELECT acct_id, COUNT(1) AS Num_5hop_Chains
FROM GRAPH_TABLE(BANK_GRAPH
MATCH(src) -[]->{5} (src)
COLUMNS(src.id AS acct_id)
) GROUP BY acct_idORDER BY Num_5hop_Chains DESC;
Starting vertex and ending vertex are
the same
bank_transfers
src
bank_transfers
bank_transfers
bank_transfers
List all accounts that have 5 hop transfers that start and end with
the same account, and order by number of such cycles

22 Copyright © 2024, Oracle and/or its affiliates
RAG and LLMs

Large Language Models

Powerful AI models that can
process and generate human
language text

Model created by training
on massive volumes of data

Researchers and practitioners
are racing to learn how LLMs
can help their products and
their business
23 Copyright © 2024, Oracle and/or its affiliates

Some Challenges Faced by LLMs

LLMs only as good
as the data they are
trained on

They can get out-of-date

They can have bias

They are expensive to re-train

Sometimes answers are misleading
and incorrect –“hallucination”

Because they generate output
based on patterns in data
they have been trained on
rather than from a deep
understanding of facts
24 Copyright © 2024, Oracle and/or its affiliates
Not True

Improved Responses by Adding Context in the Prompt
25 Copyright © 2024, Oracle and/or its affiliates
query
context
This is correct

RAG: Retrieval Augmented Generation
26 Copyright © 2024, Oracle and/or its affiliates
User query
(prompt)
Encode and use
to retrieve
context
from vector
database
Retrieve
context
Context-
enhanced
prompt
LLMs
Vector database
optimized for
fast search
Regular
updates

Use latest data to provide
context to LLM

Create encodings (referred to
as embeddings) that are stored
as vectors in a vector database

User query is encoded and
matched with stored vectors

Top matches are retrieved and
provided as context with the
prompt

Vector Search in SQL for a RAG Pipeline
27 Copyright © 2024, Oracle and/or its affiliates

Get context from latest data,
using vector search in SQL

28 Copyright © 2024, Oracle and/or its affiliates
Graph-RAG and LLMs

Knowledge Graphs
Copyright © 2024, Oracle and/or its affiliates29

Knowledge graphs
capture facts about a
domain and relationships
between them
Melli
Redwood Shores
CA
Roadshow

Knowledge Graphs
Copyright © 2024, Oracle and/or its affiliates30

Knowledge graphs
capture facts about a
domain and relationships
between them
Melli
Redwood Shores
CA
Roadshow
New York City

Knowledge Graphs
Copyright © 2024, Oracle and/or its affiliates31

Knowledge graphs
capture facts about a
domain and relationships
between them
New York City
Melli
Redwood Shores
CA
Marouane
Jayant
Nashua
NH
Casablanca
Morocco

Knowledge Graphs
Copyright © 2024, Oracle and/or its affiliates32

Knowledge graphs
capture facts about a
domain and relationships
between them
Melli
Redwood Shores
CA
Marouane
Jayant
Nashua
NH
Casablanca
Morocco
New York City
OCI GenAIService

Is Mellilikely to use the GenAIservice?
Copyright © 2024, Oracle and/or its affiliates33

Knowledge graphs
capture facts about a
domain and relationships
between them
Melli
Redwood Shores
CA
Marouane
Jayant
Nashua
NH
Casablanca
Morocco
New York City
AI/ML
?
OCI GenAIService

Enhance Retrieval Augmented Generation with Knowledge Graphs
Copyright © 2024, Oracle and/or its affiliates34
User query
(prompt)
Encode and use
to retrieve
context
from vector
database
Retrieve
context
Context-
enhanced
prompt
LLMs
Vector database with vectors created
from node and edge embeddings
from knowledge graphs

Create encodings from
the knowledge graph
and use for semantic
search to enhance
prompts

Using Graph RAG to Enhance the Prompt with New Information
35 Copyright © 2024, Oracle and/or its affiliates
Query
Context
(as a graph)
The art of the possible
Output

Graph and Vector Search in SQL for a RAG Pipeline
36 Copyright © 2024, Oracle and/or its affiliates

Get context from latest data,
using graph and vector
search in SQL

37 Copyright © 2024, Oracle and/or its affiliates
Creating Encodings Using
Graph Machine Learning Algorithms
Capture the structure of data in the encoding

What are Graph Machine Learning Algorithms?
Copyright © 2024, Oracle and/or its affiliates38
DeepWalk: Follow all paths from each node and
create a vector of ids
Use case: Find patterns similar to the pattern
around a known fraudulent account (nature of
pattern is not known)

Graphs and Machine Learning
Copyright © 2024, Oracle and/or its affiliates39
Hop 1
Hop 2
DeepWalk: Follow all paths from each node and
create a vector of ids
Use case: Find patterns similar to the pattern
around a known fraudulent account (nature of
pattern is not known)
GraphWise: Sample neighbors recursively
to learn a function (a graph convolutional
network)
Use case: Recommender systems

Graph-RAG and LLMs
Copyright © 2024, Oracle and/or its affiliates40
User query
(prompt)
Encode and use
to retrieve
context
from vector
database
Retrieve
context
Context-
enhanced
prompt
LLMs
Vector database with vectors created
by running graph ML algorithms on
knowledge graphs

Use encodings from
executing graph machine
learning algorithms on
knowledge graphs

Key Takeaways
New SQL syntax in Oracle Database 23ai makes it easy to write queries that traverse connections in data
Graphs provide new insights by analyzing the structure of data connections
Graph feature of Oracle Database has comprehensive support to create, query, and analyze data as a
graph
Graphs add value to machine learning algorithms and retrieval-augmented generation for gen AI
41 Copyright © 2024, Oracle and/or its affiliates

Resources
42 Copyright © 2024, Oracle and/or its affiliates
oracle.com/database/graph/
oracle.com/livelabssearch for ‘graph’
YouTube search for ‘oracle spatial and graph’
blogs.oracle.com/database/category/db-graph
medium.com/tag/oracle-graph/latest

Thank you
@AnnamalaiMelli
[email protected]
43 Copyright © 2024, Oracle and/or its affiliates
Tags