Skip to content

Commit 408af77

Browse files
authored
Add documents for UUID automatic generation. (#215)
1 parent b09af0d commit 408af77

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

docs/docs/core/flow_def.mdx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,22 @@ If the data slice has `Struct` type, you can obtain a data slice on a specific s
167167

168168
## Data Collector
169169

170-
A **data collector** can be added from a specific data scope, and it collects multiple entries of data, represented by data slices in the same or children scope.
170+
A **data collector** can be added from a specific data scope, and it collects multiple entries of data from the same or children scope.
171+
172+
### Collect
173+
171174
Call its `collect()` method to collect a specific entry, which can have multiple fields.
175+
Each field has a name as specified by the argument name, and a value in one of the following representations:
176+
177+
* A `DataSlice`.
178+
* An enum `cocoindex.GeneratedField.UUID` indicating its value is an UUID automatically generated by the engine.
179+
The uuid will remain stable when other collected input values are unchanged.
180+
181+
:::note
182+
183+
An automatically generated UUID field is allowed to appear at most once.
184+
185+
:::
172186

173187
For example,
174188

@@ -182,17 +196,18 @@ def demo_flow(flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataSco
182196
demo_collector = data_scope.add_collector()
183197
with data_scope["documents"].row() as document:
184198
...
185-
demo_collector.collect(filename=document["filename"], summary=document["summary"])
186-
199+
demo_collector.collect(id=cocoindex.GeneratedField.UUID,
200+
filename=document["filename"],
201+
summary=document["summary"])
187202
...
188203
```
189204

190205
</TabItem>
191206
</Tabs>
192207

193-
Here the collector is in the top-level data scope, and it collects `filename` and `summary` fields from each row of `documents` field.
194-
195-
To specify what to do with the collected data, call a specific method on the collector.
208+
Here the collector is in the top-level data scope.
209+
It collects `filename` and `summary` fields from each row of `documents`,
210+
and generates a `id` field with UUID and remains stable when `filename` and `summary` are unchanged.
196211

197212
### Export
198213

0 commit comments

Comments
 (0)