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.
- 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.
- 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
Prerequisites
Verify all of the following before you start:- Cognite Toolkit version 0.8 or later is installed. See Setting up.
- A
cdf.tomlfile exists in your project root. If it is missing, runcdf modules initand select Create toml file (required). - Authentication is configured and verified — run
cdf auth initandcdf auth verifyusing a local.envfile. 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 thefiles.processing.groupsaccess 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 to an existing project
- Start a new project
Add the module from your project directory:
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
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
3
Deploy to CDF
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.
Verify the deployment
After deploying, confirm success with these checks:- The
cdf deploycommand finishes without errors and reports successful deployment of Functions, Workflows, Transformations, Extraction Pipelines, RAW, the data set, and the access group. - In CDF, navigate to Integrate > Data Workflows and verify that the annotation workflow is listed (external ID
p_and_id_annotationby default). - 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.
- Navigate to Build Solutions > Functions, open
fn_dm_context_files_annotation, select View logs, and verify that files were processed without errors. - Navigate to Integrate > Staging (RAW) and verify that
documents_tags,documents_docs, andfiles_state_storehave been created and populated. - Use CDF Search in Industrial Tools to confirm annotations on P&ID documents — purple boxes link to assets, orange boxes link to files.
Configuration reference
Module variables are set per environment inconfig.<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.
Runtime parameters (extraction pipeline)
Annotation behavior is controlled byextraction_pipelines/ctx_files-pandid_annotation.config.yaml (ep_ctx_files_pandid_annotation), not config.<env>.yaml.
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:- Tagging —
asset_tagging_trandfile_tagging_tradd aPIDtag to qualifying assets and files. These are customizable examples that control which records thefilterProperty/filterValuessettings admit into matching. - 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. - Annotation creation — matches at or above
autoApprovalThresholdare approved and those at or aboveautoSuggestThresholdare suggested; both are written asCogniteDiagramAnnotationinstances (diagrams.AssetLinkfor assets,diagrams.FileLinkfor files). Document-to-tag and document-to-document matches are also written to thedocuments_tagsanddocuments_docsRAW tables.
Run modes
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
For issues not covered here, contact Cognite support.