Skip to content

Commit 3f12262

Browse files
authored
docs(app-namespace): document using app namespace for backend name (#505)
* docs(app-namespace): document using app namespace for backend name * docs: add cross link
1 parent 8385a21 commit 3f12262

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

docs/docs/core/flow_def.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,38 @@ Following metrics are supported:
311311

312312
## Miscellaneous
313313

314+
### Getting App Namespace
315+
316+
You can use the [`app_namespace` setting](initialization#app-namespace) or `COCOINDEX_APP_NAMESPACE` environment variable to specify the app namespace,
317+
to organize flows across different environments (e.g., dev, staging, production), team members, etc.
318+
319+
In the code, You can call `flow.get_app_namespace()` to get the app namespace, and use it to name certain backends. It takes the following arguments:
320+
321+
* `trailing_delimiter` (optional): a string to append to the app namespace when it's not empty.
322+
323+
e.g. when the current app namespace is `Staging`, `flow.get_app_namespace(trailing_delimiter='.')` will return `Staging.`.
324+
325+
For example,
326+
327+
<Tabs>
328+
<TabItem value="python" label="Python" default>
329+
330+
```python
331+
doc_embeddings.export(
332+
"doc_embeddings",
333+
cocoindex.storages.Qdrant(
334+
collection_name=cocoindex.get_app_namespace(trailing_delimiter='__') + "doc_embeddings",
335+
...
336+
),
337+
...
338+
)
339+
```
340+
341+
</TabItem>
342+
</Tabs>
343+
344+
It will use `Staging__doc_embeddings` as the collection name if the current app namespace is `Staging`, and use `doc_embeddings` if the app namespace is empty.
345+
314346
### Target Declarations
315347

316348
Most time a target storage is created by calling `export()` method on a collector, and this `export()` call comes with configurations needed for the target storage, e.g. options for storage indexes.

docs/docs/core/initialization.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ if __name__ == "__main__":
8888

8989
### App Namespace
9090

91-
The `app_namespace` field helps organize flows across different environments (e.g., testing, production) or teams. When set, it prefixes flow names with the namespace.
91+
The `app_namespace` field helps organize flows across different environments (e.g., dev, staging, production), team members, etc. When set, it prefixes flow names with the namespace.
9292

93-
For example, if the namespace is "Staging", for a flow with name specified as `Flow1` in code, the full name of the flow will be `Staging.Flow1`.
93+
For example, if the namespace is `Staging`, for a flow with name specified as `Flow1` in code, the full name of the flow will be `Staging.Flow1`.
94+
You can also get the current app namespace by calling `cocoindex.get_app_namespace()` (see [Getting App Namespace](flow_def#getting-app-namespace) for more details).
9495

9596
If not set, all flows are in a default unnamed namespace.
9697

docs/docs/ops/storages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The spec takes the following fields:
4040
See [DatabaseConnectionSpec](../core/initialization#databaseconnectionspec) for its specific fields.
4141
If not provided, will use the same database as the [internal storage](/docs/core/basics#internal-storage).
4242

43-
* `table_name` (type: `str`, optional): The name of the table to store to. If unspecified, will generate a new automatically. We recommend specifying a name explicitly if you want to directly query the table. It can be omitted if you want to use CocoIndex's query handlers to query the table.
43+
* `table_name` (type: `str`, optional): The name of the table to store to. If unspecified, will use the table name `[${AppNamespace}__]${FlowName}__${TargetName}`, e.g. `DemoFlow__doc_embeddings` or `Staging__DemoFlow__doc_embeddings`.
4444

4545
### Qdrant
4646

0 commit comments

Comments
 (0)