@@ -10,142 +10,62 @@ keywords:
10
10
- llm
11
11
---
12
12
13
- import Tabs from " @theme/Tabs" ;
14
- import TabItem from " @theme/TabItem" ;
15
- import Thumbnail from " @site/src/components/Thumbnail" ;
16
-
17
- # Relationships Connect Data
13
+ # Relate Data
18
14
19
15
## Introduction
20
16
21
- Relationships allow you to connect your data, enabling PromptQL to understand the semantic connections between your data
22
- entities and accurately talk to all your data. By defining these relationships, PromptQL can generate intelligent query
23
- plans that navigate complex data structures to provide meaningful insights.
24
-
25
- Examples of how PromptQL uses relationships to deliver powerful insights:
26
-
27
- - When asking PromptQL about a customer's purchasing patterns, it can understand the relationship between ` Customer ` ,
28
- their ` Orders ` , and each ` Product ` item in those orders, delivering comprehensive purchasing analysis. (Model to
29
- Model)
30
- - When requesting customer behavior analytics, PromptQL can correlate a ` Customer ` with their app usage metrics from
31
- another data source, providing cross-data-source insights. (Model to Model in another subgraph or data connector)
32
- - When analyzing international sales performance, PromptQL can combine ` Order ` data with live currency conversions from
33
- an external API through a lambda data connector, delivering real-time financial analysis. (Model to Command)
34
-
35
- Relationships can be added between _ any_ kind of semantically related models and/or commands. They do not need to be
36
- related in the data source by, for example, a foreign key. They also do not need to be backed by the same data source or
37
- be in the same subgraph.
38
-
39
- ## Lifecycle
40
-
41
- Many relationships can be created automatically by the CLI from detected underlying connections such as foreign keys. In
42
- such cases the lifecycle in creating a relationship in your metadata is as follows:
43
-
44
- 1 . Introspect your data source using the CLI with the relevant data connector to fetch the entity resources.
45
- 2 . Add the detected relationships to your metadata with the CLI.
46
- 3 . Create a build with the CLI.
47
- 4 . Serve your build via the packaged distributed query engine, either locally or in the cloud.
48
- 5 . Iterate on your PromptQL experience by repeating this process or by editing your metadata manually as needed.
49
-
50
- <Thumbnail src = " /img/metadata/ddn-cli-process.png" alt = " Data modeling lifecycle" width = " 1000px" />
51
-
52
- If the relationship cannot be detected automatically, you can easily manually create a relationship in your metadata and
53
- then perform lifecycle steps 3-5 from above as needed.
54
-
55
- ## Create a relationship
17
+ ** Relationships** allow you to connect your data, enabling PromptQL to understand the semantic connections between your
18
+ data entities and accurately talk to all your data. By defining these relationships, PromptQL can generate intelligent
19
+ query plans that navigate complex data structures to provide meaningful insights.
56
20
57
21
Relationships are defined in metadata from an
58
22
[ object type] ( /reference/metadata-reference/types.mdx#objecttype-objecttype ) , to a
59
23
[ model] ( /reference/metadata-reference/models.mdx ) or [ command] ( /reference/metadata-reference/commands.mdx ) . But since
60
24
models and commands are also defined with object types, you can think of relationships as being between models and/or
61
25
commands.
62
26
63
- The target command can be enabled with a custom piece of business logic on a lambda data connector, or a native mutation
64
- operation.
27
+ TODO: Example
65
28
66
- ### Using the CLI
29
+ ## Lifecycle
67
30
68
- The CLI and your data connectors will detect many relationships in your data sources automatically, for instance from
69
- foreign keys in a relational database, and once introspected, you can add them to your metadata.
31
+ ### Create a relationship
70
32
71
- ``` ddn title="Introspect your data source:"
72
- ddn connector introspect <connector_name>
73
- ```
33
+ To add a relationship you will need to have a data connector which has already introspected the data source. Follow the
34
+ relevant tutorial in [ How to Build with PromptQL] ( /how-to-build-with-promptql/index.mdx ) to get to that point.
74
35
75
- ``` ddn title="Show the found relationships:"
76
- ddn connector show-resources <connector_name>
77
- ```
36
+ ``` ddn title="Add your relationship by passing the connector's and relationship's names:"
37
+ # Alternatively, you can add all relationships: ddn relationship add <connector_link_name> "*"
78
38
79
- ``` ddn title="Add a relationship to your metadata:"
80
- ddn relationship add <connector_link_name> <collection_name>
39
+ ddn relationship add <connector_link_name> <relationship_name>
81
40
```
82
41
83
- Or optionally add all relationships found for a connector at once:
42
+ :::tip Not sure which relationships you have?
43
+
44
+ Relationships are generally available for any foreign-key values defined in your data source. You can see a list of all
45
+ available resources using the CLI:
84
46
85
47
``` ddn
86
- ddn relationship add <connector_link_name> "*"
48
+ ddn connector show-resources <connector_name>
87
49
```
88
50
89
- :::info Context for CLI commands
90
-
91
- Note that the above CLI commands work without also adding the relevant subgraph to the command with the ` --subgraph `
92
- flag because this has been set in the CLI context. You can learn more about creating and switching contexts in the
93
- [ CLI context] ( /project-configuration/project-management/manage-contexts.mdx ) section.
94
-
95
51
:::
96
52
97
- ### Manually creating a relationship
98
-
99
- Relationships can also be manually added to your metadata.
100
-
101
- The [ VS Code extension] ( https://marketplace.visualstudio.com/items?itemName=HasuraHQ.hasura ) can help you to author
102
- relationships.
103
-
104
- For example, you can configure a relationship so that when a user asks PromptQL about a Customer's purchasing history,
105
- it can also access their Orders data.
106
-
107
- ``` yaml title="Create a relationship in your metadata:"
108
- ---
109
- kind : Relationship
110
- version : v1
111
- definition :
112
- sourceType : Customers # The existing source object type which also defines the model
113
- name : orders # A name we want to use when we query the Orders from the Customer
114
- description : |
115
- Links customers to their purchase orders.
116
- One customer can have multiple orders.
117
- This is a critical business relationship that supports order history lookups,
118
- customer purchase analysis, and revenue attribution.
119
- Historical orders are retained even if customer becomes inactive.
120
- target :
121
- model : # The target can be a model or a command
122
- name : Orders # The existing model that we want to access when we query the Orders from the Customer
123
- relationshipType : Array # The relationship type which can be Object or Array. Since a customer can have many orders, we use an Array.
124
- mapping : # The mapping defines which field on the source object type maps to which field on the target model
125
- - source :
126
- fieldPath :
127
- - fieldName : customerId # The existing field on the source object type that we want to map to the target model
128
- target :
129
- modelField :
130
- - fieldName : customerId # The existing field on the target model that we want to map to the source object type
131
- ` ` `
132
-
133
- By defining this ` Relationship` object, PromptQL will understand that customers and orders are connected, allowing it to
134
- generate accurate query plans that can navigate from customer data to their associated orders when responding to user
135
- queries about customer purchasing behavior.
53
+ For each relationship, you'll find a metadata object added in the relevant parent model's HML file.
136
54
137
- Learn more about the [Relationship](/reference/metadata-reference/relationships.mdx) object.
55
+ You can now [ create a build] ( /reference/cli/commands/ddn_supergraph_build.mdx ) , serve it, and begin having meaningful
56
+ conversations with the related data through PromptQL. With explicitly defined relationships in place, PromptQL can
57
+ create dynamic query plans that accurately address your requests and provide deep insights into and across your data.
138
58
139
- # # Update a relationship
59
+ ### Update a relationship
140
60
141
61
Your underlying data source may change over time. You can update your relationship to reflect these changes.
142
62
143
- If you have an automatically detected relationship and a property on the source object type has changed, you can update
63
+ If you have an automatically- detected relationship and a property on the source object type has changed, you can update
144
64
the relationship to reflect this change.
145
65
146
66
First, update your connector configuration and models.
147
67
148
- ` ` ` ddn title="Update your source introspection :"
68
+ ``` ddn title="Re-introspect your source:"
149
69
ddn connector introspect <connector_name>
150
70
```
151
71
@@ -162,12 +82,12 @@ ddn relationship add <connector_link_name> <collection_name>
162
82
Or you can update the ` Relationship ` object manually. Learn more about the
163
83
[ Relationship] ( /reference/metadata-reference/relationships.mdx ) object.
164
84
165
- # # Delete a relationship
85
+ ### Delete a relationship
166
86
167
87
If you no longer need a relationship, simply delete the ` Relationship ` metadata object manually. It is fully
168
88
self-contained.
169
89
170
- # # Reference
90
+ ## Next steps
171
91
172
92
You can learn more about relationships in the metadata reference
173
93
[ docs] ( /reference/metadata-reference/relationships.mdx ) .
0 commit comments