Skip to content

Commit 2dd1805

Browse files
committed
More query processing stuff
1 parent 58528d5 commit 2dd1805

File tree

6 files changed

+96
-1
lines changed

6 files changed

+96
-1
lines changed

guides/structured-processing/load-doc.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ e.g. `Object extraction`.
121121

122122
## Step 3: Launch Document Processing
123123

124+
When loading the document on the workbench, it can help to decide to store
125+
the data in a particular collection for later. Click the dialog
126+
top right, and set the collection to `cities`.
127+
128+
<img src="set-collection.png" alt="Set collection option"/>
129+
124130
On the Library page, select your document containing city information,
125131
click 'Submit' at the bottom of the screen.
126132

guides/structured-processing/load-file.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ and collection load.
379379

380380
## Notes
381381

382+
- At the time of writing, the prompts work well at XML processing,
383+
but we'll be optimising to work with smaller models and provide
384+
better coverage of other data types. We recommend you stick with
385+
XML data for TrustGraph 1.3.
382386
- You may find that the prompts are sensitive to different LLMs, and
383387
that you may see hallucinations or insensitivity to different data features.
384388
- XPath expressions have some incompatibilities and edge cases with
48.7 KB
Loading

guides/structured-processing/query.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,46 @@ Before starting this guide, ensure you have:
3232
- Python 3.10 or later with the TrustGraph CLI tools installed (`pip install trustgraph-cli`)
3333
- Sample documents or structured data files to process
3434

35+
## Workbench
36+
37+
The Structured Query page on the workbench UI allows you to run the
38+
queries we'll be running here. Make sure:
39+
40+
- You have set the collection parameter correctly in the session state
41+
popover, top-right.
42+
- Be sure to set a flow which has object processing enabled e.g. the
43+
`obj-ex` flow which you created if you are following this guide.
44+
45+
<img src="nlp-query.png" alt="NLP query"/>
46+
47+
<img src="structured-query.png" alt="Structured query"/>
48+
3549
## NLP query operation
3650

3751
This operation takes a natural language query, and uses an LLM prompt
3852
to convert to a GraphQL query. This uses defined schema, so you need
39-
to have the pies schema loaded:
53+
to have the schemas loaded in the previous guide steps.
54+
55+
This is a building block for more complete functionality, but it may
56+
be useful for you to be able to look at converted queries to check that
57+
your application is performing well.
58+
59+
```bash
60+
tg-invoke-nlp-query -f obj-ex -q 'Cities with more than 22.8m people'
61+
```
62+
63+
If successful the output is something like...
64+
65+
```
66+
Generated GraphQL Query:
67+
----------------------------------------
68+
query { cities(where: {population: {gt: 22800000}}) { city country population } }
69+
----------------------------------------
70+
Detected Schemas: cities
71+
Confidence: 95.00%
72+
```
73+
74+
Querying the pies data:
4075

4176
```
4277
tg-invoke-nlp-query -f obj-ex \
@@ -59,6 +94,31 @@ Confidence: 95.00%
5994
This operation takes a GraphQL query, and executes it on the object
6095
store.
6196

97+
City example:
98+
99+
```
100+
tg-invoke-objects-query -f obj-ex --collection cities -q '
101+
{
102+
cities(where: {population: {gt: 22800000}}) { city country population }
103+
}
104+
'
105+
```
106+
107+
```
108+
+-----------+------------+------------+
109+
| city | country | population |
110+
+-----------+------------+------------+
111+
| Shanghai | China | 30482140 |
112+
| São Paulo | Brazil | 22990007 |
113+
| Delhi | India | 34665569 |
114+
| Tokyo | Japan | 37036204 |
115+
| Dhaka | Bangladesh | 24652864 |
116+
| Cairo | Egypt | 23074225 |
117+
+-----------+------------+------------+
118+
```
119+
120+
Pies example:
121+
62122
```
63123
tg-invoke-objects-query -f obj-ex \
64124
--collection uk-pies \
@@ -86,6 +146,28 @@ You can use `--format` to request CSV or JSON output.
86146

87147
This is an API which uses the above two operations in sequence.
88148

149+
Cities example:
150+
151+
```
152+
tg-invoke-structure-query -f obj-ex --collection cities \
153+
-q 'Cities with more than 22.8m people'
154+
```
155+
156+
```
157+
+-----------+------------+------------+
158+
| city | country | population |
159+
+-----------+------------+------------+
160+
| Shanghai | China | 30482140 |
161+
| São Paulo | Brazil | 22990007 |
162+
| Delhi | India | 34665569 |
163+
| Tokyo | Japan | 37036204 |
164+
| Dhaka | Bangladesh | 24652864 |
165+
| Cairo | Egypt | 23074225 |
166+
+-----------+------------+------------+
167+
```
168+
169+
Pies example:
170+
89171
```
90172
tg-invoke-structured-query -f obj-ex \
91173
--collection uk-pies \
@@ -107,6 +189,9 @@ You can use `--format` to request CSV or JSON output.
107189

108190
## With collections
109191

192+
Using the same schema with different collections allows you to group
193+
data:
194+
110195
```
111196
tg-invoke-structured-query -f obj-ex \
112197
--collection fr-pies \
27 KB
Loading
53.7 KB
Loading

0 commit comments

Comments
 (0)