dp:contextualization:cdf_file_annotation) annotates P&IDs, drawings, and other documents in Cognite Data Fusion (CDF) with Diagram Detect and pattern mode, and links them to the assets and files they mention. It deploys as a module for the Cognite Toolkit.
A data workflow calls one function in Cognite Functions, fn_file_annotation, four times, once per stage: prepare, launch, finalize, and promote. A transformation then links annotated files to assets. Progress per file is tracked on the FileAnnotationState view, and results are written to CDF RAW for reporting.
dp:contextualization). You can add it on its own or alongside the other contextualization modules.Who it’s for
Data engineers deploy and tune the pipeline. Subject matter experts review suggested annotations. Use this pack when you want a configuration-driven pipeline that:- Annotates documents against assets and files in your data model.
- Combines regular Diagram Detect with pattern-mode detection and automatic promotion of pattern hits.
- Handles large volumes, multi-page files, site and unit scoping, and several instance spaces.
- You need to match time series to assets. Use CDF Entity Matching.
- You need to populate
aliases. This pack doesn’t write them. Use the aliases update function in CDF Entity Matching. See One aliases function per project.
What’s included
Prerequisites
-
The Cognite Toolkit version 0.8 or later is installed, and
cdf.tomlexists in your project root. See Setting up. -
Authentication is configured with
cdf auth initandcdf auth verify. See Authentication and authorization. -
Files and assets are ingested, with
aliasespopulated by the aliases update function from CDF Entity Matching. Diagram Detect matches on aliases. -
You have an identity provider (IdP) application (
IDP_CLIENT_ID,IDP_CLIENT_SECRET) and the source ID of an IdP group (GROUP_SOURCE_ID). -
To upload the sample pattern catalog, the data plugin is enabled in
cdf.toml:
Install and deploy
- Add to an existing project
- Start a new project
config.<env>.yaml, set at minimum:
- The file and target entity views and instance spaces. The defaults point to
CogniteFileandCogniteAssetinsp_cdm_instances. functionClientId,functionClientSecret, andgroupSourceId.ApplicationOwner, which the Streamlit apps require, andenvironment, which is used in the group name.
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.Dry-run the deployment
Deploy to CDF
Set up CI/CD (optional)
cdf clean command deletes every resource managed by the configurations in the build, not only the four legacy functions. Review the dry-run output and continue only if you can safely delete every listed resource. Then run cdf clean, rebuild, and deploy the current module. Custom callers must now pass stage to fn_file_annotation.
cdf clean. The command deletes every resource managed by that build.Verify the deployment
cdf deployfinishes without errors.- Tag at least one file
ToAnnotateand its assetsDetectInDiagrams. - In Integrate > Data Workflows, run
wf_ctx_file_annotationand confirm that all five tasks succeed. - In Integrate > Staging (RAW), confirm that
raw_file_annotation.annotation_documents_tagshas rows. - Open the annotated file in CDF Search and confirm the annotations are visible.
How it works
stage: finalize) to increase throughput.
Tags and aliases
Tags decide which instances the pipeline processes. They’re never matched against diagram text. Aliases are the strings that Diagram Detect and promote look for.Annotated or AnnotationFailed to filesToAnnotateTags. They’re then removed from the exclude list automatically.
One aliases function per project
Use one aliases function for the whole project:fn_dm_context_aliases_update from the CDF Entity Matching module. It writes aliases on time series, assets, and files, so entity matching and file annotation match on the same strings. Don’t run a second alias pipeline for file annotation. Two pipelines with different patterns write conflicting aliases, and matches then succeed in one module and fail in the other.
The aliases update function joins tag parts with -, so the name VAL_23-KA-9101 gets the alias 23-KA-9101. Earlier versions wrote 23_KA_9101.
Keep these settings coordinated when you change either module:
Configuration reference
Set these variables inconfig.<env>.yaml before running cdf build. Required variables must be set for your project. Optional variables can keep their defaults. Diagram Detect limits, batch sizes, and RAW table names are fixed in functions/fn_file_annotation/fa_constants.py. Edit that file and redeploy to change them.
Views and spaces
Matching
Tags
Scope
ScopeWideDetect entities in the same primary scope. The property must be a text property with the same name on the file view and the target entity view. The core CogniteFile and CogniteAsset views don’t have one, so use views that extend them.
For a file with site=PlantA and unit=U100:
Multiple instance spaces
LeavefileInstanceSpace and targetEntityInstanceSpace empty ("") when each site keeps its files and assets in its own space. Prepare then picks up files from every space. Each file is matched only against entities in its own space, and annotations and state are stored next to the file. You can also set one and leave the other empty, for example one shared asset space with files in many spaces.
With an empty space, the transformations and debugFileExternalId don’t work, because they need a single space. The access group needs read and write on every space you annotate.
Text normalization
Promote usesentityNormalizationPatterns (assets) and fileNormalizationPatterns (files) to extract tag forms from detected text before searching aliases. Use the same patterns as the alias patterns in the aliases update function, so promote looks for the forms your aliases contain. See One aliases function per project.
When several patterns match, the longest form wins. An empty list turns normalization off for that source. Lookups are case-sensitive exact matches.
In the current version, promote builds its search forms by joining capture groups with _, plus the detected text as written and a form with separators removed. It doesn’t generate the - form that the aliases update function now writes. A tag detected inside longer text, such as VAL_23-KA-9101, can therefore be rejected even though the alias 23-KA-9101 exists. Check annotation_documents_patterns for rejected tags that exist as assets.
[0-9], not \d. The Cognite Toolkit rejects backslash escapes in variables. A pattern without a capture group fails when the config loads.
Data workflow and access
The variables in this table belong inconfig.<env>.yaml, except logLevel, which is set on each workflow task.
Results and reporting
Results are written to the RAW databaseraw_file_annotation.
annotation_documents_patterns for status = Rejected, or run the status report after promote. Text that Diagram Detect never associates with an entity or pattern isn’t stored.
Transformations
Troubleshooting
No files are picked up
No files are picked up
ToAnnotate and don’t carry an exclude tag such as Annotated. To reprocess annotated files, add Annotated or AnnotationFailed to filesToAnnotateTags.Files fail with No entities or pattern samples found
Files fail with No entities or pattern samples found
DetectInDiagrams, populate aliases, and check that the scope values match. The pipeline tags the failed file AnnotationFailed, which prepare excludes. Add AnnotationFailed to filesToAnnotateTags. Prepare then removes that tag from the exclude list and creates a FileAnnotationState with status New. Run the workflow again.Annotations link to assets on another site or unit
Annotations link to assets on another site or unit
primaryScopeProperty (and optionally secondaryScopeProperty), populate the scope values on files and assets, and keep filterPatternPromoteByScope: true.Diagram Detect fails with an entity length error
Diagram Detect fails with an entity length error
Too few approved annotations
Too few approved annotations
assetAuto* or fileAuto* thresholds, then run once with cleanOldAnnotations: true.The status report or tag helpers update no rows
The status report or tag helpers update no rows
cdf build. These transformations need a single instance space, so they don’t work when the space variables are empty.The workflow fails with an access error
The workflow fails with an access error
functionClientId, functionClientSecret, and groupSourceId, and that the group has access to every instance space you annotate. See Access management.logLevel to DEBUG on the workflow task. See Data workflow and access. For issues not covered here, contact Cognite support.
Further reading
- CDF Entity Matching: the aliases update function for the project, and time series to asset matching.
- Deployment packs: the other packs in the library.
- Authentication and authorization: set up the credentials the workflow uses.