diff --git a/packages/client/hmi-client/src/services/calibrate-workflow.ts b/packages/client/hmi-client/src/services/calibrate-workflow.ts index f0e2233526..3a4a5256a2 100644 --- a/packages/client/hmi-client/src/services/calibrate-workflow.ts +++ b/packages/client/hmi-client/src/services/calibrate-workflow.ts @@ -124,7 +124,7 @@ export const autoCalibrationMapping = async ( const result = [] as CalibrateMap[]; const allModelGroundings: string[] = []; const allDataGroundings: string[] = []; - const acceptableDistance = 0.7; + const acceptableDistance = 0.5; // Get all model groundings modelOptions.forEach((state) => { if (state.grounding?.identifiers) { @@ -135,8 +135,11 @@ export const autoCalibrationMapping = async ( }); // Get all data column groundings datasetOptions.forEach((col) => { - const dataGroundingList = Object.keys(col.metadata?.groundings?.identifiers); - dataGroundingList.forEach((ele) => allDataGroundings.push(ele)); + if (col.metadata?.groundings?.identifiers) { + Object.entries(col.metadata?.groundings?.identifiers) + .map((ele) => ele.join(':')) + .forEach((ele) => allDataGroundings.push(ele)); + } }); // take out duplicates: @@ -144,22 +147,28 @@ export const autoCalibrationMapping = async ( const distinctDataGroundings = [...new Set(allDataGroundings)]; const allSimilarity = await getEntitySimilarity(distinctModelGroundings, distinctDataGroundings); if (!allSimilarity) return result; - - const filteredSim = allSimilarity.filter((ele) => ele.distance < acceptableDistance); + // normalized cosine similarities + const filteredSim = allSimilarity.filter((ele) => ele.similarity > acceptableDistance); filteredSim.forEach((sim) => { // Find all states assosiated with this sim const validStates = modelOptions.filter((state) => { if (state.grounding?.identifiers) { - const modelTemp = Object.entries(state.grounding?.identifiers); - const modelGroundingList = modelTemp.map((ele) => ele.join(':')); + const modelGroundingList = Object.entries(state.grounding?.identifiers).map((ele) => + ele.join(':') + ); return modelGroundingList.includes(sim.source); } return false; }); // Find all columns assosiated with this sim const validCols = datasetOptions.filter((col) => { - const dataGroundingList = Object.keys(col.metadata?.groundings?.identifiers); - return dataGroundingList.includes(sim.target); + if (col.metadata?.groundings?.identifiers) { + const dataGroundingList = Object.entries(col.metadata?.groundings?.identifiers).map((ele) => + ele.join(':') + ); + return dataGroundingList.includes(sim.target); + } + return false; }); // For all states and columns that have short distances throw them into results validStates.forEach((state) => { diff --git a/packages/client/hmi-client/src/types/Types.ts b/packages/client/hmi-client/src/types/Types.ts index e2e716bfd7..4ccbdbfd8c 100644 --- a/packages/client/hmi-client/src/types/Types.ts +++ b/packages/client/hmi-client/src/types/Types.ts @@ -677,7 +677,7 @@ export interface DKG { export interface EntitySimilarityResult { source: string; target: string; - distance: number; + similarity: number; } export interface PermissionGroup { diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/mira/EntitySimilarityResult.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/mira/EntitySimilarityResult.java index ec411f762b..57b4455c57 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/mira/EntitySimilarityResult.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/mira/EntitySimilarityResult.java @@ -10,5 +10,5 @@ public class EntitySimilarityResult { private String source; private String target; - private Float distance; + private Float similarity; }