feat: introduce comparability assessment before contradiction reasoning

This commit is contained in:
2026-08-02 16:28:11 +01:00
parent b84989b96a
commit 0c7558d31f
5 changed files with 399 additions and 1 deletions
+164
View File
@@ -0,0 +1,164 @@
import { makeEdge, makeGraph, makeNode } from "@/lib/graph/schema.js";
function buildComparabilityFixture({
key,
scenario,
observationLabels,
contradictionLabel,
expectedComparabilityStatus,
expectsComparisonQuestion,
}) {
const summary = makeNode({
id: `${key}-summary`,
label: scenario,
description: "Summary of the situation from the scenario text",
kind: "state",
status: "provisional",
confidence: "medium",
});
const observations = observationLabels.map((label, index) =>
makeNode({
id: `${key}-obs-${index + 1}`,
label,
description: label,
kind: "observation",
status: "supported",
confidence: "high",
}),
);
const contradiction = contradictionLabel
? [
makeNode({
id: `${key}-contradiction`,
label: contradictionLabel,
description: contradictionLabel,
kind: "relationship",
status: "supported",
confidence: "medium",
}),
]
: [];
const unknowns = [
makeNode({
id: `${key}-unknown-a`,
label: "Possible explanation from one side of the situation.",
description: "Possible explanation from one side of the situation.",
kind: "unknown",
status: "unknown",
confidence: "high",
}),
makeNode({
id: `${key}-unknown-b`,
label: "Possible explanation from another side of the situation.",
description: "Possible explanation from another side of the situation.",
kind: "unknown",
status: "unknown",
confidence: "high",
}),
];
const edges = [
...observations.map((node) =>
makeEdge({
id: `${node.id}-supports-summary`,
fromNodeId: node.id,
toNodeId: summary.id,
relationship: "supports",
description: `${node.label} supports the summary.`,
}),
),
...unknowns.map((node) =>
makeEdge({
id: `${node.id}-depends-summary`,
fromNodeId: node.id,
toNodeId: summary.id,
relationship: "depends_on",
description: `${node.label} is an unresolved factor for this situation.`,
}),
),
];
return {
key,
scenario,
expectedComparabilityStatus,
expectsComparisonQuestion,
graph: makeGraph({
centralStatement: scenario,
nodes: [summary, ...observations, ...contradiction, ...unknowns],
edges,
activeUnknownNodeId: null,
resolvedNodeIds: [],
currentSummary: `Comparability fixture for ${key}`,
}),
};
}
export const comparabilityAssessmentFixtures = [
buildComparabilityFixture({
key: "revenue-cash",
scenario:
"Revenue increased by 18%, but cash in the bank fell over the same period.",
observationLabels: [
"Revenue increased by 18%.",
"Cash in the bank decreased over the same period.",
],
contradictionLabel:
"Contradiction between revenue improvement and lower cash reserves.",
expectedComparabilityStatus: "uncertain",
expectsComparisonQuestion: true,
}),
buildComparabilityFixture({
key: "complaints-production",
scenario: "Complaints increased. Production increased.",
observationLabels: ["Complaints increased.", "Production increased."],
contradictionLabel:
"Possible contradiction between complaints and production movement.",
expectedComparabilityStatus: "uncertain",
expectsComparisonQuestion: true,
}),
buildComparabilityFixture({
key: "delivery-cancellations",
scenario:
"Average delivery time decreased by 25%, but order cancellations increased.",
observationLabels: [
"Average delivery time decreased by 25%.",
"Order cancellations increased.",
],
contradictionLabel:
"Contradiction between faster delivery and more cancellations.",
expectedComparabilityStatus: "uncertain",
expectsComparisonQuestion: true,
}),
buildComparabilityFixture({
key: "satisfaction-complaints",
scenario: "Customer satisfaction increased, but complaints increased.",
observationLabels: [
"Customer satisfaction increased.",
"Complaints increased.",
],
contradictionLabel:
"Contradiction between satisfaction improvement and more complaints.",
expectedComparabilityStatus: "uncertain",
expectsComparisonQuestion: true,
}),
buildComparabilityFixture({
key: "temperature-ice",
scenario: "Temperature increased. Ice melted.",
observationLabels: ["Temperature increased.", "Ice melted."],
contradictionLabel: null,
expectedComparabilityStatus: "confirmed",
expectsComparisonQuestion: false,
}),
buildComparabilityFixture({
key: "sales-same",
scenario: "Sales doubled. Sales doubled.",
observationLabels: ["Sales doubled.", "Sales doubled."],
contradictionLabel: null,
expectedComparabilityStatus: "confirmed",
expectsComparisonQuestion: false,
}),
];