Honor Scattermind metric hints in ranking
This commit is contained in:
@@ -145,6 +145,33 @@ function cleanTextList(value, maxItems = 6, maxText = 180) {
|
||||
return list.map(item => cleanText(item, maxText)).filter(Boolean).slice(0, maxItems);
|
||||
}
|
||||
|
||||
function cleanMetricHints(item = {}) {
|
||||
const raw = {
|
||||
...(item.factors && typeof item.factors === 'object' ? item.factors : {}),
|
||||
...(item.scoring && typeof item.scoring === 'object' ? item.scoring : {}),
|
||||
...(item.rankerHints && typeof item.rankerHints === 'object' ? item.rankerHints : {}),
|
||||
};
|
||||
const aliases = {
|
||||
value: ['value', 'impact', 'userImpact', 'userValueScore'],
|
||||
effort: ['effort', 'buildEffort', 'complexity'],
|
||||
confidence: ['confidence', 'certainty'],
|
||||
urgency: ['urgency', 'timing'],
|
||||
revenue: ['revenue', 'commercial', 'buyerSignal'],
|
||||
novelty: ['novelty', 'differentiation', 'originality'],
|
||||
risk: ['risk', 'assumptionRisk', 'scopeRisk'],
|
||||
};
|
||||
return Object.fromEntries(Object.entries(aliases).map(([metric, keys]) => {
|
||||
const found = keys.map(key => raw[key] ?? item[key]).find(value => value !== undefined && value !== null && value !== '');
|
||||
const parsed = Number.parseFloat(found);
|
||||
return [metric, Number.isFinite(parsed) ? Math.min(10, Math.max(1, parsed)) : null];
|
||||
}).filter(([, value]) => value !== null));
|
||||
}
|
||||
|
||||
function blendMetric(heuristic, explicit, weight = 0.58) {
|
||||
if (!Number.isFinite(explicit)) return heuristic;
|
||||
return Math.max(1, Math.min(10, heuristic * (1 - weight) + explicit * weight));
|
||||
}
|
||||
|
||||
function rowsFrom(result) {
|
||||
const rows = result?.rows || result?.documents;
|
||||
if (!Array.isArray(rows)) throw new Error('Appwrite returned an invalid table response');
|
||||
@@ -397,7 +424,7 @@ function normalizeFeatureOption(item, index, fallbackId = 'feature') {
|
||||
id: cleanText(item?.id || item?.key || `${fallbackId}-${index + 1}`, 80) || `${fallbackId}-${index + 1}`,
|
||||
title,
|
||||
description: cleanText(descriptionParts.join(' '), 760),
|
||||
factors: { userValue, evidenceNeeded, risk, proofSteps, dependencies, recommendedLane },
|
||||
factors: { userValue, evidenceNeeded, risk, proofSteps, dependencies, recommendedLane, metricHints: cleanMetricHints(item) },
|
||||
provenance: {
|
||||
sourceId: cleanText(item?.sourceId || item?.sourceArtifactId || item?.id || '', 120),
|
||||
sourceSection,
|
||||
@@ -431,7 +458,7 @@ function scoreOption(option, mode, context = '') {
|
||||
const normalizedLaneHint = normalizeLaneHint(laneHint);
|
||||
const laneBoost = /do|first|now|build/.test(laneHint) ? 0.55 : /validate|test|proof/.test(laneHint) ? 0.25 : /defer|park|cut/.test(laneHint) ? -0.75 : 0;
|
||||
const lanePenalty = normalizedLaneHint === 'park' ? 18 : normalizedLaneHint === 'defer' ? 9 : 0;
|
||||
const metrics = {
|
||||
const heuristicMetrics = {
|
||||
value: Math.min(10, 4.8 + hits(text, wordSets.value) * 0.9 + coreLoopHits * 0.8 + bridgeHits * 0.75 + proofHits * 0.2 + hits(context, wordSets.value) * 0.15),
|
||||
feasibility: Math.max(1, Math.min(10, 8.2 - effortHits * 0.8 - riskHits * 0.35 - dependencyPenalty + Math.min(1.1, coreLoopHits * 0.28 + bridgeHits * 0.18 + proofHits * 0.12))),
|
||||
confidence: Math.max(1, Math.min(10, 5.8 + coreLoopHits * 0.35 + bridgeHits * 0.28 + proofHits * 0.32 + hits(text, ['manual', 'existing', 'already', 'simple', 'clear', 'known']) * 0.7 - hits(text, ['maybe', 'unknown', 'new market', 'all users']) * 0.9)),
|
||||
@@ -440,6 +467,17 @@ function scoreOption(option, mode, context = '') {
|
||||
novelty: Math.min(10, 4.1 + hits(text, wordSets.novelty) * 0.95),
|
||||
risk: Math.min(10, 2.5 + riskHits * 1.1 + Math.max(0, effortHits - 2) * 0.45 + swampHits * 0.2 + dependencyPenalty),
|
||||
};
|
||||
const hinted = factors.metricHints || {};
|
||||
const hintedFeasibility = Number.isFinite(hinted.effort) ? 11 - hinted.effort : undefined;
|
||||
const metrics = {
|
||||
value: blendMetric(heuristicMetrics.value, hinted.value),
|
||||
feasibility: blendMetric(heuristicMetrics.feasibility, hintedFeasibility),
|
||||
confidence: blendMetric(heuristicMetrics.confidence, hinted.confidence),
|
||||
urgency: blendMetric(heuristicMetrics.urgency, hinted.urgency),
|
||||
revenue: blendMetric(heuristicMetrics.revenue, hinted.revenue),
|
||||
novelty: blendMetric(heuristicMetrics.novelty, hinted.novelty),
|
||||
risk: blendMetric(heuristicMetrics.risk, hinted.risk),
|
||||
};
|
||||
const weights = mode.weights;
|
||||
const weighted = Object.entries(weights).reduce((sum, [key, weight]) => sum + metrics[key] * weight, 0);
|
||||
const possible = Object.entries(weights).reduce((sum, [_key, weight]) => sum + Math.abs(weight) * 10, 0);
|
||||
|
||||
Reference in New Issue
Block a user