You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/core/flow_methods.mdx
+47-18Lines changed: 47 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
---
2
2
title: Flow Running
3
+
toc_max_heading_level: 4
3
4
description: Run a CocoIndex Flow, including build / update data in the target storage and evaluate the flow without changing the target storage.
4
5
---
5
6
@@ -70,8 +71,7 @@ This is to achieve best efficiency.
70
71
71
72
### One time update
72
73
73
-
<TabsqueryString="code_lang">
74
-
<TabItemvalue="shell"label="Shell"default>
74
+
#### CLI
75
75
76
76
The `cocoindex update` subcommand creates/updates data in the target storage.
77
77
@@ -81,7 +81,9 @@ Once it's done, the target data is fresh up to the moment when the function is c
81
81
python main.py cocoindex update
82
82
```
83
83
84
-
</TabItem>
84
+
#### Library API
85
+
86
+
<Tabs>
85
87
<TabItemvalue="python"label="Python">
86
88
87
89
The `update()` async method creates/updates data in the target storage.
@@ -108,8 +110,7 @@ A data source may enable one or multiple *change capture mechanisms*:
108
110
109
111
Change capture mechanisms enable CocoIndex to continuously capture changes from the source data and update the target data accordingly, under live update mode.
110
112
111
-
<TabsqueryString="code_lang">
112
-
<TabItemvalue="shell"label="Shell"default>
113
+
#### CLI
113
114
114
115
To perform live update, run the `cocoindex update` subcommand with `-L` option:
Python SDK also allows you to use the updater as a context manager.
170
-
It will abort and wait for the updater to finish automatically when the context is exited.
171
-
The following code is equivalent to the code above:
177
+
It will automatically start the updater during the context entry, and abort and wait for the updater to finish automatically when the context is exited.
178
+
The following code is equivalent to the code above (if no early return happens):
172
179
173
180
```python
174
-
asyncwith cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
181
+
with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
175
182
# Perform your own logic (e.g. a query loop).
176
183
...
177
184
print(my_updater.update_stats())
178
185
```
179
186
180
-
Within a synchronous function, remove `async` before `with`, like this:
187
+
CocoIndex also provides asynchronous versions of APIs for blocking operations, including:
181
188
182
-
```python
183
-
with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
189
+
*`start_async()` and `wait_async()`, e.g.
190
+
191
+
```python
192
+
my_updater = cocoindex.FlowLiveUpdater(demo_flow)
193
+
# Start the updater.
194
+
await my_updater.start_async()
195
+
196
+
# Perform your own logic (e.g. a query loop).
184
197
...
185
-
```
198
+
199
+
# Print the update stats.
200
+
print(my_updater.update_stats())
201
+
# Abort the updater.
202
+
my_updater.abort()
203
+
# Wait for the updater to finish.
204
+
await my_updater.wait_async()
205
+
```
206
+
* Async context manager, e.g.
207
+
208
+
```python
209
+
asyncwith cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
210
+
# Perform your own logic (e.g. a query loop).
211
+
...
212
+
print(my_updater.update_stats())
213
+
```
186
214
187
215
</TabItem>
188
216
</Tabs>
@@ -191,8 +219,7 @@ with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
191
219
192
220
CocoIndex allows you to run the transformations defined by the flow without updating the target storage.
193
221
194
-
<TabsqueryString="code_lang">
195
-
<TabItemvalue="shell"label="Shell"default>
222
+
### CLI
196
223
197
224
The `cocoindex evaluate` subcommand runs the transformation and dumps flow outputs.
0 commit comments