// Match time series to assets, both stored as core data model instances.
const { items: timeSeries } = await client.instances.list({
instanceType: 'node',
sources: [{ source: { type: 'view', space: 'cdf_cdm', externalId: 'CogniteTimeSeries', version: 'v1' } }],
});
const { items: assets } = await client.instances.list({
instanceType: 'node',
sources: [{ source: { type: 'view', space: 'cdf_cdm', externalId: 'CogniteAsset', version: 'v1' } }],
});
// externalId is only unique within a space, so keep the space as an extra field.
const sources = timeSeries.map((node) => ({
externalId: node.externalId,
space: node.space,
name: String(node.properties?.cdf_cdm?.['CogniteTimeSeries/v1']?.name ?? ''),
}));
const targets = assets.map((node) => ({
externalId: node.externalId,
space: node.space,
name: String(node.properties?.cdf_cdm?.['CogniteAsset/v1']?.name ?? ''),
}));
const result = await client.entityMatching.create({
sources,
targets,
externalId: 'model123',
name: 'model123',
});
await client.entityMatching.delete([{ externalId: 'model123' }]);
const { items } = await client.entityMatching.list({ filter: { name: 'model123' }});
Optionalscope: EntityMatchingFilterRequest// sources and targets built from instances as in the create example:
// { externalId: node.externalId, space: node.space, name: ... }
const response = await client.entityMatching.predict({
externalId: 'model123',
sources: [{ externalId: 'pump-01-pressure', space: 'my-space', name: 'Pump 01 pressure' }],
targets: [{ externalId: 'pump-01', space: 'my-space', name: 'Pump 01' }],
});
Retrieve entity matcher predict result
const { status, items } = await client.entityMatching.predictResult(12345678);
// The space passed in with each target comes back, so a match maps to an instance id.
const best = items[0].matches[0];
const assetId = { space: String(best.matchTo.space), externalId: String(best.matchTo.externalId) };
await client.entityMatching.refit({
externalId: 'model123',
newExternalId: 'newModel123',
sources: [{ externalId: 'pump-01-pressure', space: 'my-space', name: 'Pump 01 pressure' }],
targets: [{ externalId: 'pump-01', space: 'my-space', name: 'Pump 01' }],
// Confirmed matches refer to sources and targets by externalId.
trueMatches: [{ sourceExternalId: 'pump-01-pressure', targetExternalId: 'pump-01' }],
});
Retrieve entity matching models
const [result] = await client.entityMatching.retrieve([{ externalId: 'model123' }]);
const [updated] = await client.entityMatching.update([{
externalId: 'model123',
update: { description: { set: 'ΓΈ' }}
}]);
Entity matching works on any objects with string fields, so it is not tied to asset-centric resources. To match data modeling instances, pass each node with its
spaceas an extra field:externalIdis only unique within a space, and every field of a source or target is returned in the predictions.