Skip to content

Commit e623e17

Browse files
Docs: Update relationships
1 parent 6f8b019 commit e623e17

File tree

1 file changed

+26
-106
lines changed

1 file changed

+26
-106
lines changed

docs/metadata/relationship.mdx

Lines changed: 26 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -10,142 +10,62 @@ keywords:
1010
- llm
1111
---
1212

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
1814

1915
## Introduction
2016

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.
5620

5721
Relationships are defined in metadata from an
5822
[object type](/reference/metadata-reference/types.mdx#objecttype-objecttype), to a
5923
[model](/reference/metadata-reference/models.mdx) or [command](/reference/metadata-reference/commands.mdx). But since
6024
models and commands are also defined with object types, you can think of relationships as being between models and/or
6125
commands.
6226

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
6528

66-
### Using the CLI
29+
## Lifecycle
6730

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
7032

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.
7435

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> "*"
7838
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>
8140
```
8241

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:
8446

8547
```ddn
86-
ddn relationship add <connector_link_name> "*"
48+
ddn connector show-resources <connector_name>
8749
```
8850

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-
9551
:::
9652

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.
13654

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.
13858

139-
## Update a relationship
59+
### Update a relationship
14060

14161
Your underlying data source may change over time. You can update your relationship to reflect these changes.
14262

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
14464
the relationship to reflect this change.
14565

14666
First, update your connector configuration and models.
14767

148-
```ddn title="Update your source introspection:"
68+
```ddn title="Re-introspect your source:"
14969
ddn connector introspect <connector_name>
15070
```
15171

@@ -162,12 +82,12 @@ ddn relationship add <connector_link_name> <collection_name>
16282
Or you can update the `Relationship` object manually. Learn more about the
16383
[Relationship](/reference/metadata-reference/relationships.mdx) object.
16484

165-
## Delete a relationship
85+
### Delete a relationship
16686

16787
If you no longer need a relationship, simply delete the `Relationship` metadata object manually. It is fully
16888
self-contained.
16989

170-
## Reference
90+
## Next steps
17191

17292
You can learn more about relationships in the metadata reference
17393
[docs](/reference/metadata-reference/relationships.mdx).

0 commit comments

Comments
 (0)