Improve UMS candidate scoring and snapshot materialization for sparse data.
Lower term threshold, tune promotion scores, project candidate fallback in snapshot, and add rebuild-ums-snapshot script for production backfill. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -41,6 +41,15 @@ export async function materializeProfileAndSnapshot(pool, userId, options = {})
|
||||
[userId],
|
||||
);
|
||||
|
||||
const [projectCandidates] = await pool.query(
|
||||
`SELECT hypothesis_json, confidence, promotion_score, last_seen_at
|
||||
FROM um_candidates
|
||||
WHERE user_id = ? AND candidate_type = 'project' AND status IN ('open', 'accepted', 'observed')
|
||||
ORDER BY promotion_score DESC
|
||||
LIMIT 8`,
|
||||
[userId],
|
||||
);
|
||||
|
||||
const [versionRows] = await pool.query(
|
||||
`SELECT COALESCE(MAX(profile_version), 0) AS v FROM um_profile_versions WHERE user_id = ?`,
|
||||
[userId],
|
||||
@@ -55,6 +64,20 @@ export async function materializeProfileAndSnapshot(pool, userId, options = {})
|
||||
last_seen: row.last_seen_at,
|
||||
}));
|
||||
|
||||
if (activeProjects.length === 0 && projectCandidates.length > 0) {
|
||||
for (const row of projectCandidates) {
|
||||
const h = typeof row.hypothesis_json === 'string' ? JSON.parse(row.hypothesis_json) : row.hypothesis_json;
|
||||
const name = h.name ?? h.topic ?? 'unknown';
|
||||
activeProjects.push({
|
||||
id: `project_${String(name).toLowerCase().replace(/[^a-z0-9]+/g, '_')}`,
|
||||
name,
|
||||
status: h.status ?? 'active',
|
||||
confidence: Number(row.confidence),
|
||||
last_seen: row.last_seen_at,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const recentFocus = focusCandidates.map((row) => {
|
||||
const h = typeof row.hypothesis_json === 'string' ? JSON.parse(row.hypothesis_json) : row.hypothesis_json;
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user