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
It creates a `demo_flow` object in `cocoindex.Flow` type.
32
+
To enable CLI, you also need to make sure you have a main function decorated with `@cocoindex.main_fn()`:
33
+
33
34
35
+
```python title="main.py"
36
+
@cocoindex.main_fn()
37
+
defmain():
38
+
...
39
+
40
+
if__name__=="__main__":
41
+
main()
42
+
```
34
43
</TabItem>
35
44
</Tabs>
36
45
@@ -61,19 +70,24 @@ This is to achieve best efficiency.
61
70
62
71
### One time update
63
72
64
-
:::tip
73
+
<Tabs>
74
+
<TabItemvalue="shell"label="Shell"default>
65
75
66
-
CLI equivalence: `cocoindex update`
76
+
The `cocoindex update` subcommand creates/updates data in the target storage.
67
77
68
-
:::
78
+
Once it's done, the target data is fresh up to the moment when the function is called.
79
+
80
+
```sh
81
+
python main.py cocoindex update
82
+
```
83
+
84
+
</TabItem>
85
+
<TabItemvalue="python"label="Python">
69
86
70
87
The `update()` async method creates/updates data in the target storage.
71
88
72
89
Once the function returns, the target data is fresh up to the moment when the function is called.
73
90
74
-
<Tabs>
75
-
<TabItemvalue="python"label="Python"default>
76
-
77
91
```python
78
92
stats =await demo_flow.update()
79
93
print(stats)
@@ -84,12 +98,6 @@ print(stats)
84
98
85
99
### Live update
86
100
87
-
:::tip
88
-
89
-
CLI equivalence: `cocoindex update -L`
90
-
91
-
:::
92
-
93
101
A data source may enable one or multiple *change capture mechanisms*:
94
102
95
103
* Configured with a [refresh interval](flow_def#refresh-interval), which is generally applicable to all data sources.
@@ -100,6 +108,21 @@ A data source may enable one or multiple *change capture mechanisms*:
100
108
101
109
Change capture mechanisms enable CocoIndex to continuously capture changes from the source data and update the target data accordingly, under live update mode.
102
110
111
+
<Tabs>
112
+
<TabItemvalue="shell"label="Shell"default>
113
+
114
+
To perform live update, run the `cocoindex update` subcommand with `-L` option:
115
+
116
+
```sh
117
+
python main.py cocoindex update -L
118
+
```
119
+
120
+
If there's at least one data source with change capture mechanism enabled, it will keep running until the aborted (e.g. by `Ctrl-C`).
121
+
Otherwise, it falls back to the same behavior as one time update, and will finish after a one-time update is done.
122
+
123
+
</TabItem>
124
+
<TabItemvalue="python"label="Python">
125
+
103
126
To perform live update, you need to create a `cocoindex.FlowLiveUpdater` object using the `cocoindex.Flow` object.
104
127
It takes an optional `cocoindex.FlowLiveUpdaterOptions` option, with the following fields:
105
128
@@ -113,19 +136,13 @@ Note that `cocoindex.FlowLiveUpdater` provides a unified interface for both one-
113
136
It only performs live update when `live_mode` is `True`, and only for sources with change capture mechanisms enabled.
114
137
If a source has multiple change capture mechanisms enabled, all will take effect to trigger updates.
115
138
116
-
<Tabs>
117
-
<TabItemvalue="python"label="Python"default>
118
-
119
139
This creates a `cocoindex.FlowLiveUpdater` object, with an optional `cocoindex.FlowLiveUpdaterOptions` option:
0 commit comments