diff --git a/docs/docs/core/flow_def.mdx b/docs/docs/core/flow_def.mdx index 60a2b551..5aaf6d54 100644 --- a/docs/docs/core/flow_def.mdx +++ b/docs/docs/core/flow_def.mdx @@ -311,6 +311,38 @@ Following metrics are supported: ## Miscellaneous +### Getting App Namespace + +You can use the [`app_namespace` setting](initialization#app-namespace) or `COCOINDEX_APP_NAMESPACE` environment variable to specify the app namespace, +to organize flows across different environments (e.g., dev, staging, production), team members, etc. + +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: + +* `trailing_delimiter` (optional): a string to append to the app namespace when it's not empty. + +e.g. when the current app namespace is `Staging`, `flow.get_app_namespace(trailing_delimiter='.')` will return `Staging.`. + +For example, + + + + +```python +doc_embeddings.export( + "doc_embeddings", + cocoindex.storages.Qdrant( + collection_name=cocoindex.get_app_namespace(trailing_delimiter='__') + "doc_embeddings", + ... + ), + ... +) +``` + + + + +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. + ### Target Declarations 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. diff --git a/docs/docs/core/initialization.mdx b/docs/docs/core/initialization.mdx index e2194be3..d2384d58 100644 --- a/docs/docs/core/initialization.mdx +++ b/docs/docs/core/initialization.mdx @@ -88,9 +88,10 @@ if __name__ == "__main__": ### App Namespace -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. +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. -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`. +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`. +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). If not set, all flows are in a default unnamed namespace. diff --git a/docs/docs/ops/storages.md b/docs/docs/ops/storages.md index effe69de..89a7196e 100644 --- a/docs/docs/ops/storages.md +++ b/docs/docs/ops/storages.md @@ -40,7 +40,7 @@ The spec takes the following fields: See [DatabaseConnectionSpec](../core/initialization#databaseconnectionspec) for its specific fields. If not provided, will use the same database as the [internal storage](/docs/core/basics#internal-storage). -* `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. +* `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`. ### Qdrant