Path 1 negative signal + Path 2 pattern discovery + name validation

New:
- /vectors/playbook_memory/patterns: meta-index pattern discovery.
  Given a query, finds top-K similar playbooks, pulls each endorsed
  worker's full workers_500k profile, aggregates shared traits (cert
  frequencies, skill frequencies, modal archetype, reliability
  distribution), returns a human-readable discovered_pattern. Surfaces
  signals operators didn't explicitly query — the original PRD's
  "identify things we didn't know" dimension.
- /vectors/playbook_memory/mark_failed: records worker failures per
  (city, state, name). compute_boost_for applies 0.5^n penalty per
  recorded failure, so 3 failures quarter a worker's positive boost and
  5 effectively zero it. Path 1 negative signal — recruiter trust
  depends on the system NOT recommending people who no-showed.
- Bun /log_failure: validates failed_names against workers_500k
  (same ghost-guard as /log), forwards to /mark_failed.

Improved:
- /log now validates endorsed_names against workers_500k for the
  contract's city+state before seeding. Ghost names (names that don't
  correspond to real workers) are rejected in the response and excluded
  from the seed, preventing silent boost failures.
- Bun /search auto-appends `CAST(availability AS DOUBLE) > 0.5` to
  sql_filter when the caller didn't constrain availability. Opt out
  with `include_unavailable: true`. Recruiter trust bug: surfacing
  already-placed workers breaks the first call.
- DEFAULT_TOP_K_PLAYBOOKS 25 → 100. Direct cosine measurement showed
  similarities cluster 0.55-0.67 across all playbooks regardless of
  geo, so k=25 missed relevant geo-matched playbooks. Brute-force is
  still sub-ms at this size.

Verified end-to-end on live data:
- Ghost names rejected on /log + /log_failure
- Availability filter drops unavailable workers from candidate pool
- Pattern discovery on unseen Cleveland OH Welder query returned
  recurring skills (first aid 43%, grinder 43%, blueprint 43%) and
  modal archetype (specialist) across 20 semantically similar past
  playbooks in 0.24s
- Negative signal: Helen Sanchez boost dropped +0.250 → +0.163 after
  3 failures recorded via /log_failure (34% reduction)
This commit is contained in:
root
2026-04-20 14:55:46 -05:00
parent 20b0289aa9
commit 95c26f04f8
3 changed files with 149 additions and 7 deletions
+42
View File
@@ -514,6 +514,48 @@ async function main() {
});
}
// Tool: log FAILED fill — negative signal for Phase 19 boost.
// Workers named here get a 0.5^n penalty on future positive
// boosts in the same (city, state). Three failures effectively
// zero the boost; five make the worker invisible to the re-rank.
// Names are validated against workers_500k same as /log.
if (url.pathname === "/log_failure") {
const b = await json();
const opMatch = String(b.operation || "").match(/ in ([^,]+),\s*([A-Za-z]+)/);
const city = opMatch ? opMatch[1].trim() : "";
const state = opMatch ? opMatch[2].trim() : "";
const rawNames: string[] = Array.isArray(b.failed_names) ? b.failed_names : [];
if (!city || !state) {
return err("operation must be 'fill: Role xN in City, ST'", 400);
}
if (rawNames.length === 0) return err("failed_names must be a non-empty array", 400);
const quoted = rawNames.map((n: string) => `'${n.replace(/'/g, "''")}'`).join(",");
const sql = `SELECT DISTINCT name FROM workers_500k `
+ `WHERE name IN (${quoted}) AND city = '${city.replace(/'/g,"''")}' `
+ `AND state = '${state.replace(/'/g,"''")}'`;
const vr = await api("POST", "/query/sql", { sql }).catch(() => ({ rows: [] as any[] })) as any;
const found = new Set((vr.rows ?? []).map((r: any) => r.name));
const failed_names = rawNames.filter((n: string) => found.has(n));
const rejected = rawNames.filter((n: string) => !found.has(n));
if (failed_names.length === 0) {
return ok({ marked: 0, rejected_ghost_names: rejected,
note: "no failed_names matched workers_500k for this geo" });
}
const mr = await api("POST", "/vectors/playbook_memory/mark_failed", {
operation: b.operation,
failed_names,
reason: b.reason || "",
});
return ok({
marked: mr?.added ?? 0,
rejected_ghost_names: rejected,
city, state,
note: `Each marked worker's positive boost in ${city}, ${state} is halved per recorded failure.`,
});
}
// Tool: get playbooks
if (url.pathname === "/playbooks") {
const kw = url.searchParams.get("keyword");