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/basics.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,4 +101,4 @@ As an indexing flow is long-lived, it needs to store intermediate data to keep t
101
101
CocoIndex uses internal storage for this purpose.
102
102
103
103
Currently, CocoIndex uses Postgres database as the internal storage.
104
-
See [Settings](settings#databaseconnectionspec) for configuring its location, and `cocoindex setup` CLI command (see [CocoIndex CLI](cli)) creates tables for the internal storage.
104
+
See [Settings](settings#databaseconnectionspec) for configuring its location. The internal storage is managed by CocoIndex, see [Setup / drop flow](/docs/core/flow_methods#setup--drop-flow)for more details.
Copy file name to clipboardExpand all lines: docs/docs/core/flow_def.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,7 +256,7 @@ Export must happen at the top level of a flow, i.e. not within any child scopes
256
256
*`target_spec`: the target spec as the export target.
257
257
*`setup_by_user` (optional):
258
258
whether the export target is setup by user.
259
-
By default, CocoIndex is managing the target setup (surfaced by the `cocoindex setup` CLI subcommand), e.g. create related tables/collections/etc. with compatible schema, and update them upon change.
259
+
By default, CocoIndex is managing the target setup (see [Setup / drop flow](/docs/core/flow_methods#setup--drop-flow)), e.g. create related tables/collections/etc. with compatible schema, and update them upon change.
260
260
If `True`, the export target will be managed by users, and users are responsible for creating the target and updating it upon change.
261
261
* Fields to configure [storage indexes](#storage-indexes). `primary_key_fields` is required, and all others are optional.
The target is managed by CocoIndex, i.e. it'll be created by [CocoIndex CLI](/docs/core/cli) when you run `cocoindex setup`, and the data will be automatically updated (including stale data removal) when updating the index.
281
+
The target is managed by CocoIndex, i.e. it'll be created or dropped when [setup / drop flow](/docs/core/flow_methods#setup--drop-flow), and the data will be automatically updated (including stale data removal) when updating the index.
282
282
The `name` for the same target should remain stable across different runs.
283
283
If it changes, CocoIndex will treat it as an old target removed and a new one created, and perform setup changes and reindexing accordingly.
284
284
@@ -370,11 +370,11 @@ flow_builder.declare(
370
370
371
371
CocoIndex manages an auth registry. It's an in-memory key-value store, mainly to store authentication information for a backend.
372
372
373
-
Operation spec is the default way to configure a backend. But it has the following limitations:
373
+
Operation spec is the default way to configure a persistent backend. But it has the following limitations:
374
374
375
375
* The spec isn't supposed to contain secret information, and it's frequently shown in various places, e.g. `cocoindex show`.
376
376
* Once an operation is removed after flow definition code change, the spec is also gone.
377
-
But we still need to be able to drop the backend (e.g. a table) by `cocoindex setup` or `cocoindex drop`.
377
+
But we still need to be able to drop the backend (e.g. a table) when [setup / drop flow](/docs/core/flow_methods#setup--drop-flow).
378
378
379
379
Auth registry is introduced to solve the problems above. It works as follows:
380
380
@@ -423,5 +423,5 @@ Note that CocoIndex backends use the key of an auth entry to identify the backen
423
423
* Keep the key stable.
424
424
If the key doesn't change, it's considered to be the same backend (even if the underlying way to connect/authenticate change).
425
425
426
-
* If a key is no longer referenced in any operation spec, keep it until the next `cocoindex setup` or `cocoindex drop`,
427
-
so that when cocoindex will be able to perform cleanups.
426
+
* If a key is no longer referenced in any operation spec, keep it until the next flow setup / drop action,
427
+
so that cocoindex will be able to clean up the backends.
Copy file name to clipboardExpand all lines: docs/docs/core/flow_methods.mdx
+85-1Lines changed: 85 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,71 @@ It creates a `demo_flow` object in `cocoindex.Flow` type.
34
34
</TabItem>
35
35
</Tabs>
36
36
37
+
## Setup / drop flow
38
+
39
+
For a flow, its persistent backends need to be ready before it can run, including:
40
+
41
+
*[Internal storage](/docs/core/basics#internal-storage) for CocoIndex.
42
+
* Backend entities for targets exported by the flow, e.g. a table (in relational databases), a collection (in some vector databases), etc.
43
+
44
+
The desired state of the backends for a flow is derived based on the flow definition itself.
45
+
CocoIndex supports two types of actions to manage the persistent backends automatically:
46
+
47
+
**Setup* a flow, which will change the backends owned by the flow to a state to the desired state, e.g. create new tables for new flow, drop an existing table if the corresponding target is gone, add new column to a target table if a new field is collected, etc. It's no-op if the backend states are already in the desired state.
48
+
49
+
**Drop* a flow, which will drop all backends owned by the flow. It's no-op if there's no existing backends owned by the flow (e.g. never setup or already dropped).
50
+
51
+
### CLI
52
+
53
+
`cocoindex setup` subcommand will setup all flows.
54
+
`cocoindex update` and `cocoindex server` also provide a `--setup` option to setup the flow if needed before performing the main action of updating or starting the server.
55
+
56
+
`cocoindex drop` subcommand will drop all flows.
57
+
58
+
### Library API
59
+
60
+
<Tabs>
61
+
<TabItemvalue="python"label="Python">
62
+
63
+
`Flow` provides the following APIs to setup / drop individual flows:
64
+
65
+
*`setup(report_to_stdout: bool = False)`: Setup the flow.
66
+
*`drop(report_to_stdout: bool = False)`: Drop the flow.
67
+
68
+
For example:
69
+
70
+
```python
71
+
demo_flow.setup(report_to_stdout=True)
72
+
demo_flow.drop(report_to_stdout=True)
73
+
```
74
+
75
+
We also provide the following asynchronous versions of the APIs:
76
+
77
+
*`setup_async(report_to_stdout: bool = False)`: Setup the flow asynchronously.
78
+
*`drop_async(report_to_stdout: bool = False)`: Drop the flow asynchronously.
0 commit comments