Skip to main content
The P&ID Annotation deployment pack (dp:contextualization:cdf_p_and_id_annotation) automates the annotation of Piping and Instrumentation Diagrams (P&IDs) in Cognite Data Fusion. It deploys as a Cognite Toolkit module and uses a CDF Workflow to run two tagging transformations followed by a CDF Function that detects tags in each diagram and links them to assets and files as CogniteDiagramAnnotation instances in the data model. The pack ships production-tested code drawn from real customer implementations, with incremental processing via the Data Modeling Sync API, threshold-based approval and suggestion, and batch-level resilience for large P&ID volumes.
P&ID Annotation is a cherry-pickable module (dp:contextualization:cdf_p_and_id_annotation) inside the Contextualization deployment pack (dp:contextualization). You can add it on its own or alongside the other contextualization modules.

Who it’s for

Target personas:
  • Data engineers — deploy, configure, and tune the annotation pipeline.
  • Subject matter experts — engineers who validate P&ID-to-asset annotations.
Use this pack when:
  • You need to contextualize P&ID documents by linking them to assets and other files in your CDF data model.
  • You want a production-ready annotation pipeline without building one from scratch.
  • Your project ingests P&ID files from sources such as SharePoint and needs to match them to asset hierarchies from systems such as SAP.
  • You need incremental processing — only new or updated files should be annotated on each run.
When not to use this pack:
  • If your P&ID documents require a fundamentally different annotation engine — this pack covers standard diagram detection and CDF annotation.
  • If P&ID files have not yet been ingested into the CDF file store — the pack requires files to be present before it can annotate them.
  • If you need to match time series to assets rather than annotate documents, use the CDF Entity Matching deployment pack instead.

What’s included

ComponentDescriptionOptional?
Asset tagging transformation (asset_tagging_tr)Adds a PID tag to qualifying assets to control which assets enter the annotation matching process. Provided as a customizable example.No
File tagging transformation (file_tagging_tr)Adds a PID tag to qualifying files to control which files enter the annotation process. Provided as a customizable example.No
Annotation function (fn_dm_context_files_annotation)Reads new or updated files via the Data Modeling Sync API, detects tags in each P&ID, matches them to assets and files, applies threshold logic, and writes CogniteDiagramAnnotation instances.No
WorkflowRuns the asset and file tagging transformations, then the annotation function (dependsOn both), each with 3 retries and abortWorkflow on failure.No
Scheduled triggerCron trigger that runs the workflow daily at 04:00 UTC using the configured credentials.Yes
Extraction pipeline (ep_ctx_files_pandid_annotation)Holds the runtime parameters, view configuration, and thresholds the annotation function reads.No
RAW database and tablesdocuments_tags (document→tag), documents_docs (document→document), and files_state_store (incremental cursor).No
Access group and datasetA files.processing.groups access group bound to a configured IdP group source ID, and a files dataset for lineage.No
Location filterAn example location filter for scoping data by location.Yes

Prerequisites

Verify all of the following before you start:
  • Cognite Toolkit version 0.8 or later is installed. See Setting up.
  • A cdf.toml file exists in your project root. If it is missing, run cdf modules init and select Create toml file (required).
  • Authentication is configured and verified — run cdf auth init and cdf auth verify using a local .env file. See Authentication and authorization.
  • P&ID files are already ingested into the CDF file store, and an asset hierarchy exists in the data model for matching.
  • You have an IdP application for the function and scheduled workflow (IDP_CLIENT_ID / IDP_CLIENT_SECRET) and the IdP group source ID for the files.processing.groups access group.

Install and deploy

You can add the P&ID Annotation module to an existing Toolkit project or start a new project from scratch.
Add the module from your project directory:
cdf modules add -d cdf_p_and_id_annotation
The Toolkit creates the module under modules/contextualization/cdf_p_and_id_annotation/ and updates your config.<env>.yaml files. Before building, open config.dev.yaml and set at minimum project, organization, location_name, source_name, the schema and instance spaces, and the credentials (functionClientId / functionClientSecret and files_location_processing_group_source_id) — see Configuration reference. Then build and deploy:
1

Build deployment artifacts

cdf build
The Toolkit substitutes template variables and writes artifacts to the build/ directory. If you need to change the project name or any variables marked <change_me>, edit config.<env>.yaml first — see Configure, build, and deploy modules.
2

Dry-run the deployment

cdf deploy --dry-run
Inspect the output and confirm that configurations look correct before deploying.
3

Deploy to CDF

cdf deploy
The Toolkit deploys only configurations that have changed since the last run.
4

Set up CI/CD (optional)

For governed production deployments, automate build, dry-run, and deploy in a pipeline. See Set up CI/CD pipelines.
After deployment, your project should include:
modules/
└── contextualization/
    └── cdf_p_and_id_annotation/

Verify the deployment

After deploying, confirm success with these checks:
  1. The cdf deploy command finishes without errors and reports successful deployment of Functions, Workflows, Transformations, Extraction Pipelines, RAW, the data set, and the access group.
  2. In CDF, navigate to Integrate > Data Workflows and verify that the annotation workflow is listed (external ID p_and_id_annotation by default).
  3. Trigger the workflow with Run (or wait for the daily trigger). Confirm that both tagging transformations complete before the annotation function, and that all tasks finish without errors.
  4. Navigate to Build Solutions > Functions, open fn_dm_context_files_annotation, select View logs, and verify that files were processed without errors.
  5. Navigate to Integrate > Staging (RAW) and verify that documents_tags, documents_docs, and files_state_store have been created and populated.
  6. Use CDF Search in Industrial Tools to confirm annotations on P&ID documents — purple boxes link to assets, orange boxes link to files.
The deployment is successful when the workflow completes without errors, the RAW match tables are populated, and annotations appear on the P&ID documents.

Configuration reference

Module variables are set per environment in config.<env>.yaml. Update these before running cdf build. Each variable takes its default unless you override it. Where the default is , a placeholder (for example YourOrg, LOC, SOURCE, <not set>), or a ${...} value read from .env, you must provide your own value before deploying.
VariableDescriptionDefault
projectCDF project external ID to deploy to.
organizationOrganization prefix used in the target view external IDs (for example, YourOrgFile, YourOrgAsset).YourOrg
location_nameLocation or asset name used in resource naming (replaces LOC).LOC
source_nameSource system the P&ID files come from (replaces SOURCE).SOURCE
files_datasetData set for lineage and the function code bundle.ds_files_LOC
schemaSpaceSchema space containing the file and asset views.sp_enterprise_process_industry
annotationSchemaSpaceSchema space for the annotation view.cdf_cdm
viewVersionVersion of the file and asset views.v1.0
fileInstanceSpaceInstance space for file instances.springfield_instances
assetInstanceSpaceInstance space for asset instances.springfield_instances
functionClientId / functionClientSecretIdP credentials used by the function and scheduled trigger.${IDP_CLIENT_ID} / ${IDP_CLIENT_SECRET}
workflowWorkflow external ID (also used by the scheduled trigger).p_and_id_annotation
files_location_processing_group_source_idIdP group source ID for the files.processing.groups access group.<not set>

Runtime parameters (extraction pipeline)

Annotation behavior is controlled by extraction_pipelines/ctx_files-pandid_annotation.config.yaml (ep_ctx_files_pandid_annotation), not config.<env>.yaml.
ParameterDescriptionDefault
autoApprovalThresholdConfidence at or above this value creates an approved annotation.0.85
autoSuggestThresholdConfidence at or above this value creates a suggested annotation.0.50
runAllAnnotate all files (true) or only files updated since the last run (false).true (shipped config)
cleanOldAnnotationsDelete annotations created by previous runs before annotating.false
debug / debugFileProcess a single named file with verbose logging.false
rawDb, rawTableState, rawTableDocTag, rawTableDocDocRAW database and tables for state and results.ds_files_<location>_<source>, files_state_store, documents_tags, documents_docs
The data section configures the views to annotate — the file view (type: diagrams.FileLink) and one or more entity views such as the asset view (type: diagrams.AssetLink) — each with a searchProperty (default name) and an optional filterProperty / filterValues (for example, tags: ["PID"]) to scope matching.
If you change autoApprovalThreshold or autoSuggestThreshold, set cleanOldAnnotations: true for one run to remove the annotations created by previous runs before re-annotating. Only annotations created by this process are removed; manually created annotations are preserved.

Architecture

The pack deploys a CDF Function, two tagging transformations, a workflow with a daily trigger, an extraction pipeline holding the runtime parameters, RAW tables, an access group, and a dataset.

Data flow

The workflow tags qualifying assets and files, then runs the annotation function. The function detects tags in each P&ID, matches them to assets and files, and creates annotations classified by the two confidence thresholds.

Annotation pipeline

The workflow runs in three stages:
  1. Taggingasset_tagging_tr and file_tagging_tr add a PID tag to qualifying assets and files. These are customizable examples that control which records the filterProperty / filterValues settings admit into matching.
  2. Detection and matching — the annotation function reads new or updated files via the Sync API, detects tags in each diagram, and matches them against the configured file and asset views using each view’s searchProperty.
  3. Annotation creation — matches at or above autoApprovalThreshold are approved and those at or above autoSuggestThreshold are suggested; both are written as CogniteDiagramAnnotation instances (diagrams.AssetLink for assets, diagrams.FileLink for files). Document-to-tag and document-to-document matches are also written to the documents_tags and documents_docs RAW tables.

Run modes

ModeBehavior
Incremental (runAll: false)Processes only new or updated files using the files_state_store cursor; unchanged files are skipped.
ALL (runAll: true)Clears cursor and per-run progress in RAW and reprocesses every matching P&ID file.
Full cleanup (cleanOldAnnotations: true)Also deletes annotations created by previous runs before reprocessing. Only annotations created by this process are removed.

Resilience

The annotation function processes files in batches with up to three retries per batch, then falls back to processing files individually. Failed individual files are logged and skipped without blocking the run. Annotation external IDs prevent duplicate annotations across runs when cleanup is disabled, and each successful batch persists its cursor so a failed run resumes without reprocessing.

Troubleshooting

SymptomLikely causeResolution
Workflow fails with an access errorThe files.processing.groups group or function credentials are misconfigured.Verify functionClientId / functionClientSecret and files_location_processing_group_source_id in config.<env>.yaml point at the correct IdP application and group source ID. See Access management.
No annotations created after the workflow runAssets or files are missing the PID tag, or search properties do not match the data model.Confirm asset_tagging_tr and file_tagging_tr completed, and that the searchProperty and filterValues in the extraction pipeline config align with your schema.
No annotations created after the workflow runFilter criteria in the configuration do not match any data.Check the extraction pipeline configuration and edit the filters to match your data, or remove the filterProperty and filterValues config lines.
No annotations created after the workflow runThe test data’s views, schema space, instance space, or version do not match the configuration.Check the extraction pipeline configuration and make sure it matches your data in CDF.
Duplicate annotations on re-runcleanOldAnnotations is disabled and annotation state changed.Set cleanOldAnnotations: true for one run, or ensure external ID generation is consistent across runs.
Workflow processes all files on every runrunAll is true, or the state table was cleared.Set runAll: false for incremental runs and confirm files_state_store exists and is being updated.
Too many low-quality annotationsThresholds are too low for your data.Raise autoApprovalThreshold / autoSuggestThreshold, then run once with cleanOldAnnotations: true to remove prior annotations.
cdf deploy fails with “Insufficient permissions”Toolkit service account is missing required CDF capabilities.Grant capabilities to deploy Functions, Workflows, Transformations, Extraction Pipelines, RAW, Data Sets, and groups.
For issues not covered here, contact Cognite support.

Support

FieldDetails
TeamCognite Value Delivery Team
DocumentationCognite product documentation
Questions and feedbackDeployment Packs group on Cognite Hub
Version1.0.0
Last updated2026
Last modified on July 6, 2026