# Knowledge Catalog integration

Google Cloud Cortex Framework integrates with
[Knowledge Catalog](https://cloud.google.com/products/knowledge-catalog)
to govern, classify, and catalog enterprise data products across your
organization. Running the
[`uv run cortex-create-kc-data-products` CLI tool](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-kc-data-products.md.txt)
registers your deployed Cortex Framework data products---including
display names, business descriptions, standardized governance labels, and linked
BigQuery tables---directly in Knowledge Catalog.

## Key benefits

Integrating Cortex Framework with
Knowledge Catalog provides the following benefits:

- **Automated discoverability** : Business analysts, data stewards, and AI agents can search and filter standardized enterprise data products by domain, line of business, or source module (`sap_module`, `salesforce_module`) in the Knowledge Catalog UI.
- **Enriched business context** : Imports `displayName`, `description`, `category`, and domain `labels` directly from each module's `manifest.yaml` file (along with the owner address passed with `--owner-email`) to populate the Knowledge Catalog resource, while `documentation` in `manifest.yaml` records reference URLs for the module manifest.
- **Unified asset linking**: Links materialized BigQuery tables and views to their parent Knowledge Catalog data products so consumers can inspect physical schemas and lineage immediately.
- **Automated drift reconciliation**: Adds newly deployed tables, updates modified descriptions or labels, preserves customer-added labels across re-syncs, and removes obsolete asset links on each sync run.
- **Managed-resource safety** : Uses the `cortex_framework_created: "true"` ownership label (and recognizes the legacy `cortex-framework-created: "true"` label from earlier releases) to manage only resources created by Cortex Framework, skipping customer-created catalog items.

## How the integration works

[![Cortex Framework Knowledge Catalog publishing process](https://docs.cloud.google.com/static/cortex/docs/images/CortexFramework-knowledge-catalog-publishing-process.png)](https://docs.cloud.google.com/static/cortex/docs/images/CortexFramework-knowledge-catalog-publishing-process.png)
**Figure 1**. Cortex Framework Knowledge Catalog publishing process.

The `uv run cortex-create-kc-data-products` tool runs a multi-stage
reconciliation workflow:

[![Cortex Framework synchronization with Knowledge Catalog](https://docs.cloud.google.com/static/cortex/docs/images/cortex7-knowledge-catalog-graph.png)](https://docs.cloud.google.com/static/cortex/docs/images/cortex7-knowledge-catalog-graph.png)
**Figure 2**. Cortex Framework synchronization with Knowledge Catalog.

### 1. Pre-flight API validation

Before extracting manifests or querying BigQuery tables, the
syncer verifies that the required Google Cloud APIs are enabled for every
eligible data product module (`enabled: true` and `syncToKc: true`):

- `bigquery.googleapis.com` on each synced module's target BigQuery dataset project.
- `dataplex.googleapis.com` on the project specified by `--kc-project-id`, or on each synced module's target BigQuery dataset project when `--kc-project-id` is omitted.

If required APIs are disabled, passing `--enable-apis` enables them
automatically without prompting (`--enable-apis` is mutually exclusive with
`--dry-run`). Without `--enable-apis`, interactive terminal sessions prompt you
to enable missing APIs, while non-interactive sessions and `--dry-run` runs exit
with an error. If your principal lacks the `serviceusage.services.get`
permission, default runs log a warning and continue, while `--dry-run` and
`--enable-apis` fail during pre-flight validation.

### 2. Configuration and manifest extraction

The syncer reads your `config/config.yaml` file to identify all data product
modules under `data.modules.products` where both `enabled: true` and
`syncToKc: true` (the defaults) are set, along with their target
BigQuery datasets (`data.datasets`).

For each eligible module, the syncer reads `manifest.yaml`, where
`documentation` records reference URLs for the module manifest while
`displayName`, `description`, `category`, `labels`, and `--owner-email` populate
the Knowledge Catalog resource:

- `displayName`: Human-readable title of the data product.
- `description`: Business summary of the data product.
- `documentation`: Optional reference URL for the module manifest. This field isn't sent to the Knowledge Catalog API. Setting a non-empty `documentation` value in `manifest.yaml` causes subsequent sync runs to evaluate as `NEEDS_UPDATE` instead of `NO_CHANGE` because the API doesn't persist that field; omit `documentation` if you want idempotent `NO_CHANGE` evaluations.
- `category`: Data product archetype (`source_aligned_product` or `consumption_product`), synced as the `module_category` label.
- `labels`: Domain governance classifications (such as `line_of_business`, `sap_module`, or `salesforce_module`).

> [!NOTE]
> **Note:** Ownership email metadata isn't stored in `manifest.yaml`. Pass the owner address at sync time with the `--owner-email` flag.

### 3. BigQuery asset discovery

Instead of relying on a static file list, `cortex-create-kc-data-products`
queries BigQuery (`list_dataset_tables`) to discover which tables
and views are materialized in your target dataset.

During `cortex-build`, Cortex Framework attaches standardized
`snake_case` tracking labels to every generated BigQuery table
and view (`module_id`, `module_category`, `module_type`, and
`namespaced_module_type`). `cortex-create-kc-data-products` matches deployed
tables to a data product when either of the following BigQuery
table labels matches:

- `namespaced_module_type`: Matches the module's `modulePath` with dots converted to underscores (for example, `cortex_sap_products_sales_documents` or `cortex_sfdc_products_opportunities`).
- `module_type`: Matches the canonical leaf module type (for example, `sales_documents` or `opportunities`).

Only materialized BigQuery tables and views carrying these module
labels are linked as assets under the corresponding data product. If a
BigQuery tracking label value exceeds 63 characters,
Cortex Framework deterministically clamps it to a 54-character
prefix plus an underscore and an 8-character SHA-256 hex suffix (63 characters
total) during build and matching.

### 4. Managed resource reconciliation and labels

The syncer calls the `dataplex_v1.DataProductServiceClient` API to reconcile
each data product in your lowercased Google Cloud location (derived from
`data.bigQueryLocation`, for example `US` becomes `us`). By default, each data
product is created in the project hosting its target BigQuery
dataset; pass `--kc-project-id` to centralize all
Knowledge Catalog data products in a dedicated
governance project while still linking BigQuery tables from their
target projects.

To comply with Dataplex API resource ID rules, non-alphanumeric characters
in `moduleId` (such as underscores) are lowercased and normalized to hyphens
with leading and trailing hyphens trimmed (for example, `sap_accounts_payable`
becomes `sap-accounts-payable`). During reconciliation, each data product
evaluates to one of four actions:

- **Creation (`NEEDS_CREATION`)** : Creates the Knowledge Catalog data product, attaches standardized `snake_case` governance labels, and links all discovered BigQuery tables.
- **Unmanaged resource protection (`NOT_MANAGED`)** : If a data product with the same ID already exists in Knowledge Catalog without `cortex_framework_created: "true"` (or legacy `cortex-framework-created: "true"`), the syncer skips it to protect user-managed catalog entries.
- **Up to date (`NO_CHANGE`)** : When display name, description, owner email addresses, merged labels, and linked `DataAsset` resources already match the target state---and `documentation` is omitted or empty in `manifest.yaml`---the syncer skips API write calls. Setting a non-empty `documentation` value in `manifest.yaml` causes subsequent runs to evaluate as `NEEDS_UPDATE` because the API doesn't persist that field.
- **Updates (`NEEDS_UPDATE`)** : Updates display names, descriptions, owner email addresses, governance labels, and `DataAsset` links whenever module metadata, `--owner-email`, or deployed tables change. During re-syncs, `uv run cortex-create-kc-data-products` merges Cortex Framework-managed labels (such as `cortex_framework_created: "true"`) with any existing user-defined labels on Knowledge Catalog data products---preserving customer-added data product labels across re-syncs---and automatically strips retired Cortex Framework label keys (`cortex_framework_version`, `cortex-framework-version`, and hyphenated `cortex-framework-created`, migrating to underscore `cortex_framework_created: "true"`). (Linked `DataAsset` resources point to your underlying BigQuery tables and don't carry separate Knowledge Catalog data product labels.)

The following table summarizes the `snake_case` labels applied to
Knowledge Catalog data products by
`cortex-create-kc-data-products`:

| Label key | Source | Example values and formatting rules |
| `cortex_framework_created` | System constant | Always set to `"true"` to mark resources managed by Cortex Framework (legacy `cortex-framework-created: "true"` remains recognized on existing resources, and retired keys `cortex_framework_version`, `cortex-framework-version`, and hyphenated `cortex-framework-created` are stripped during updates). |
| `module_category` | `manifest.yaml` (`category`) | `"source_aligned_product"` or `"consumption_product"`. |
| `line_of_business` | `manifest.yaml` (`labels.line_of_business`) | Domain classification such as `"finance"`, `"sales"`, `"supply_chain"`, or `"service"`. Multi-value lists are deduplicated, sorted alphabetically, joined with hyphens (for example, `"sales-supply_chain"`), truncated to 63 characters, and stripped of trailing underscores or hyphens (unlike BigQuery table labels, which clamp values over 63 characters with an 8-character SHA-256 suffix). |
| `sap_module` / `salesforce_module` (or custom keys) | `manifest.yaml` (`labels.*`) | Source module tags such as `"sap_fi"`, `"sap_co-sap_fi"`, or `"sales_cloud"`. Any additional `snake_case` keys declared under `labels:` follow the same 63-character truncation rule. |
|---|---|---|

## Setup and configuration

Complete the following prerequisites and configuration steps before running
`uv run cortex-create-kc-data-products`.

### Prerequisites

Ensure your target project and deployed pipelines meet these requirements:

#### Enable Google Cloud services

Enable the BigQuery API (`bigquery.googleapis.com`) and the
Dataplex API (`dataplex.googleapis.com`) in your target Google Cloud
project, or pass `--enable-apis` when running
`uv run cortex-create-kc-data-products` to enable missing APIs automatically
(`--enable-apis` is mutually exclusive with `--dry-run`):

```bash
gcloud services enable bigquery.googleapis.com \
    dataplex.googleapis.com \
    --project=PROJECT_ID
```

Replace the following:

- `PROJECT_ID`: the Google Cloud project ID hosting your target BigQuery datasets and Knowledge Catalog data products, for example: `my-cortex-project`.

#### Roles for target project


To get the permissions that
you need to synchronize Knowledge Catalog,

ask your administrator to grant you the
following IAM roles on your target project:

- [Dataplex Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/dataplex.md.txt#dataplex.editor) (`roles/dataplex.editor`)
- [Dataplex Data Products Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/dataplex.md.txt#dataplex.dataProductsEditor) (`roles/dataplex.dataProductsEditor`)
- [Dataplex Entry and EntryLink Owner](https://docs.cloud.google.com/iam/docs/roles-permissions/dataplex.md.txt#dataplex.entryOwner) (`roles/dataplex.entryOwner`)
- [BigQuery Metadata Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.metadataViewer) (`roles/bigquery.metadataViewer`)
- [BigQuery Data Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) (`roles/bigquery.dataViewer`)
- Verify enabled APIs strictly with `--dry-run` (default runs log a warning and continue if absent): [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) (`roles/serviceusage.serviceUsageConsumer`)
- Enable missing APIs automatically with `--enable-apis`: [Service Usage Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageAdmin) (`roles/serviceusage.serviceUsageAdmin`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


These predefined roles contain

the permissions required to synchronize Knowledge Catalog. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to synchronize Knowledge Catalog:

- `dataplex.dataProducts.get`
- `dataplex.dataProducts.create`
- `dataplex.dataProducts.update`
- `dataplex.dataAssets.list`
- `dataplex.dataAssets.create`
- `dataplex.dataAssets.delete`
- `bigquery.tables.list`
- `bigquery.tables.get`
- Verify enabled APIs strictly with `--dry-run`: `serviceusage.services.get`
- Enable missing APIs automatically with `--enable-apis`:
  - `serviceusage.services.get`
  - `serviceusage.services.enable`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).

Grant these roles to the principal running
`uv run cortex-create-kc-data-products`:

```bash
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/dataplex.editor"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/dataplex.dataProductsEditor"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/dataplex.entryOwner"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/bigquery.metadataViewer"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/bigquery.dataViewer"
```

If you run `--dry-run` for strict API verification, also grant
`roles/serviceusage.serviceUsageConsumer`. If you pass `--enable-apis` to enable
missing APIs automatically, grant `roles/serviceusage.serviceUsageAdmin`
instead:

```bash
# Optional: Required for strict API verification with --dry-run
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/serviceusage.serviceUsageConsumer"

# Optional: Required only when passing --enable-apis
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/serviceusage.serviceUsageAdmin"
```

Replace the following:

- `PROJECT_ID`: your target Google Cloud project ID, for example: `my-cortex-project`.
- `USER_EMAIL`: the email address of the user or service account running `uv run cortex-create-kc-data-products`, for example: `data-owner@example.com`.

> [!NOTE]
> **Note:** If you centralize catalog resources in a separate governance project with `--kc-project-id`, enable `dataplex.googleapis.com` and grant the Dataplex roles on that governance project while enabling `bigquery.googleapis.com` and granting the BigQuery viewer roles on each project hosting your deployed data product datasets. If you pass `--dry-run` or `--enable-apis`, grant the corresponding Service Usage role on both the governance project and each target dataset project.

#### Executed Dataform pipeline

Run `cortex-build-and-deploy` or `cortex-deploy` as described in the
[Deployment guide](https://docs.cloud.google.com/cortex/docs/deployment.md.txt#execute_deployment) and **execute
your Dataform workflow actions** to materialize the target
BigQuery tables and views before running
`uv run cortex-create-kc-data-products`. For execution instructions, see
[Post-deployment steps](https://docs.cloud.google.com/cortex/docs/post-deployment-steps.md.txt).

This guide covers production deployments that use `config/config.yaml`. To
register and clean up Knowledge Catalog data products
from a demo deployment, see
[Optional: Register demo data products in
Knowledge Catalog](https://docs.cloud.google.com/cortex/docs/demo-deployment#register-knowledge-catalog)
and
[Optional: Clean up Knowledge Catalog demo data
products](https://docs.cloud.google.com/cortex/docs/demo-deployment#cleanup-knowledge-catalog).

> [!NOTE]
> **Note:** Each Knowledge Catalog data product is validated during live creation and updates to contain at most 50 BigQuery table assets (this cap isn't evaluated during `--dry-run`). If a data product resolves more than 50 tables during live synchronization, `uv run cortex-create-kc-data-products` records a per-product sync failure, continues processing remaining data products, and exits with an error listing all failed data products.

### Configuring data product metadata

Customize the metadata and governance labels synchronized to
Knowledge Catalog in each data product's `manifest.yaml`
file (for example, within your custom namespace). The module type is derived
automatically from the module directory leaf name (such as `accounts_payable`)
and doesn't need a `type` key:

```yaml
displayName: "SAP Accounts Payable"
description: >
  SAP data product for Accounts Payable containing conformed vendor invoices,
  payment aging schedules, and financial accounting documents.
category: source_aligned_product
dependencies:
  sapModule:
    supportedVersions:
      - ecc
      - s4
    tables:
      ecc:
        - bsik
        - bsak
      s4:
        - acdoca
        - bseg
      common:
        - bkpf
        - tcurx
    modulePath: cortex.sap.foundations.sap
builder: sap_product
labels:
  line_of_business: finance
  sap_module: sap_fi
```

### Running the synchronization command

After your data products are materialized in BigQuery, preview
pre-flight validation and planned sync actions with `--dry-run` before applying
changes:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-create-kc-data-products \
    --config $CORTEX_CONFIG_FILE \
    --owner-email OWNER_EMAIL \
    --dry-run
```

`--dry-run` runs strict read-only pre-flight API checks, resolves deployed
BigQuery tables, and evaluates each data product's sync status
(`NEEDS_CREATION`, `NEEDS_UPDATE`, `NO_CHANGE`, or `NOT_MANAGED`) without
creating or updating Knowledge Catalog resources or
emitting telemetry. `--dry-run` is mutually exclusive with `--enable-apis`, and
the 50-table asset cap per data product is enforced during live creation and
updates rather than during `--dry-run`.

To create or update enabled data products in
Knowledge Catalog, run
`uv run cortex-create-kc-data-products` (you can also use the `-c` short alias
for `--config`):

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-create-kc-data-products \
    --config $CORTEX_CONFIG_FILE \
    --owner-email OWNER_EMAIL
```

To automatically enable any missing required Google Cloud APIs
(`bigquery.googleapis.com` and `dataplex.googleapis.com`) without prompting, add
`--enable-apis` (mutually exclusive with `--dry-run`):

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-create-kc-data-products \
    --config $CORTEX_CONFIG_FILE \
    --owner-email OWNER_EMAIL \
    --enable-apis
```

To register all data products in a dedicated cross-project governance project
instead of each data product's target BigQuery dataset project,
add `--kc-project-id`:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-create-kc-data-products \
    --config $CORTEX_CONFIG_FILE \
    --kc-project-id KC_PROJECT_ID \
    --owner-email OWNER_EMAIL
```

Replace the following:

- `OWNER_EMAIL`: email address assigned as the data product owner in Knowledge Catalog, for example: `data-owner@example.com`.
- `KC_PROJECT_ID`: optional Google Cloud project ID for centralizing Knowledge Catalog data products across projects, for example: `my-governance-project`.

For all supported CLI flags, see the
[`uv run cortex-create-kc-data-products` reference](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-kc-data-products.md.txt).

## Verify catalog synchronization

Verify that your data products and governance labels appear in
Knowledge Catalog:

1. In the Google Cloud console, open [Knowledge Catalog](https://console.cloud.google.com/dataplex).
2. Optional: Select the **Data Products** quick filter in the search bar.
3. Click **Filters** , and then select your target project from the **Project** list.
4. Select a synchronized data product to inspect its business description, `snake_case` governance labels (`module_category`, `line_of_business`, `sap_module`), and linked BigQuery tables.

## Automating the workflow

In production environments, run `uv run cortex-create-kc-data-products` as a
post-transformation step in your CI/CD or orchestration pipeline after
Dataform finishes materializing tables:

1. Run `uv run cortex-deploy --config
   CONFIG_PATH` to stage compiled Dataform assets.
2. Trigger a Dataform workflow invocation to materialize foundation and data product tables in BigQuery.
3. Run `uv run cortex-create-kc-data-products` with `--config CONFIG_PATH` and `--owner-email OWNER_EMAIL` to reconcile data products, labels, and asset links in Knowledge Catalog.

Replace the following:

- `CONFIG_PATH`: path to your `config.yaml` file, for example: `config/config.yaml`.
- `OWNER_EMAIL`: owner email address registered on synced data products, for example: `data-owner@example.com`.

## Next steps

- [Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt): Create custom data products and configure `manifest.yaml` labels.
- [`uv run cortex-create-kc-data-products` CLI reference](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-kc-data-products.md.txt): Review command-line options for catalog synchronization.