@mailwoman/resolver 10.0.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +9 -7
  2. package/lib/admin/coherence-passes.ts +31 -172
  3. package/lib/admin/containment.ts +15 -33
  4. package/lib/admin/jp-municipality.ts +21 -14
  5. package/lib/admin/winner.ts +37 -69
  6. package/lib/backend-capabilities.ts +28 -27
  7. package/lib/bare-toponym-race.ts +69 -37
  8. package/lib/decorate-node.ts +25 -49
  9. package/lib/fold-name.ts +5 -18
  10. package/lib/index.ts +5 -9
  11. package/lib/plausibility.ts +41 -68
  12. package/lib/postcode/country-coherence.ts +92 -296
  13. package/lib/postcode/prefix.ts +24 -86
  14. package/lib/postcode/shape-coherence.ts +26 -116
  15. package/lib/remote-resolver.ts +38 -33
  16. package/lib/rerank.ts +41 -54
  17. package/lib/resolve/passes.ts +188 -177
  18. package/lib/resolve.ts +744 -0
  19. package/lib/span-rescore.ts +219 -175
  20. package/lib/street/evidence.ts +65 -73
  21. package/lib/street/tier.ts +51 -194
  22. package/lib/toponym-prior.ts +54 -180
  23. package/out/admin/coherence-passes.d.ts +18 -69
  24. package/out/admin/coherence-passes.d.ts.map +1 -1
  25. package/out/admin/coherence-passes.js +24 -166
  26. package/out/admin/coherence-passes.js.map +1 -1
  27. package/out/admin/containment.d.ts +13 -31
  28. package/out/admin/containment.d.ts.map +1 -1
  29. package/out/admin/containment.js +13 -31
  30. package/out/admin/containment.js.map +1 -1
  31. package/out/admin/jp-municipality.d.ts +21 -14
  32. package/out/admin/jp-municipality.d.ts.map +1 -1
  33. package/out/admin/jp-municipality.js +18 -12
  34. package/out/admin/jp-municipality.js.map +1 -1
  35. package/out/admin/winner.d.ts +32 -64
  36. package/out/admin/winner.d.ts.map +1 -1
  37. package/out/admin/winner.js +23 -56
  38. package/out/admin/winner.js.map +1 -1
  39. package/out/{admin/index.d.ts → admin.d.ts} +1 -1
  40. package/out/admin.d.ts.map +1 -0
  41. package/out/{admin/index.js → admin.js} +1 -1
  42. package/out/admin.js.map +1 -0
  43. package/out/backend-capabilities.d.ts +19 -20
  44. package/out/backend-capabilities.d.ts.map +1 -1
  45. package/out/backend-capabilities.js +28 -26
  46. package/out/backend-capabilities.js.map +1 -1
  47. package/out/bare-toponym-race.d.ts +54 -27
  48. package/out/bare-toponym-race.d.ts.map +1 -1
  49. package/out/bare-toponym-race.js +69 -37
  50. package/out/bare-toponym-race.js.map +1 -1
  51. package/out/decorate-node.d.ts +6 -8
  52. package/out/decorate-node.d.ts.map +1 -1
  53. package/out/decorate-node.js +25 -49
  54. package/out/decorate-node.js.map +1 -1
  55. package/out/fold-name.d.ts +5 -18
  56. package/out/fold-name.d.ts.map +1 -1
  57. package/out/fold-name.js +5 -18
  58. package/out/fold-name.js.map +1 -1
  59. package/out/index.d.ts +5 -6
  60. package/out/index.d.ts.map +1 -1
  61. package/out/index.js +5 -8
  62. package/out/index.js.map +1 -1
  63. package/out/plausibility.d.ts +30 -60
  64. package/out/plausibility.d.ts.map +1 -1
  65. package/out/plausibility.js +19 -52
  66. package/out/plausibility.js.map +1 -1
  67. package/out/postcode/country-coherence.d.ts +53 -167
  68. package/out/postcode/country-coherence.d.ts.map +1 -1
  69. package/out/postcode/country-coherence.js +42 -259
  70. package/out/postcode/country-coherence.js.map +1 -1
  71. package/out/postcode/prefix.d.ts +18 -69
  72. package/out/postcode/prefix.d.ts.map +1 -1
  73. package/out/postcode/prefix.js +11 -78
  74. package/out/postcode/prefix.js.map +1 -1
  75. package/out/postcode/shape-coherence.d.ts +18 -85
  76. package/out/postcode/shape-coherence.d.ts.map +1 -1
  77. package/out/postcode/shape-coherence.js +11 -107
  78. package/out/postcode/shape-coherence.js.map +1 -1
  79. package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
  80. package/out/postcode.d.ts.map +1 -0
  81. package/out/{postcode/index.js → postcode.js} +1 -1
  82. package/out/postcode.js.map +1 -0
  83. package/out/remote-resolver.d.ts +32 -31
  84. package/out/remote-resolver.d.ts.map +1 -1
  85. package/out/remote-resolver.js +12 -20
  86. package/out/remote-resolver.js.map +1 -1
  87. package/out/rerank.d.ts +32 -46
  88. package/out/rerank.d.ts.map +1 -1
  89. package/out/rerank.js +16 -41
  90. package/out/rerank.js.map +1 -1
  91. package/out/resolve/passes.d.ts +108 -95
  92. package/out/resolve/passes.d.ts.map +1 -1
  93. package/out/resolve/passes.js +67 -126
  94. package/out/resolve/passes.js.map +1 -1
  95. package/out/resolve.d.ts +15 -0
  96. package/out/resolve.d.ts.map +1 -0
  97. package/out/resolve.js +557 -0
  98. package/out/resolve.js.map +1 -0
  99. package/out/span-rescore.d.ts +56 -65
  100. package/out/span-rescore.d.ts.map +1 -1
  101. package/out/span-rescore.js +134 -132
  102. package/out/span-rescore.js.map +1 -1
  103. package/out/street/evidence.d.ts +56 -61
  104. package/out/street/evidence.d.ts.map +1 -1
  105. package/out/street/evidence.js +22 -46
  106. package/out/street/evidence.js.map +1 -1
  107. package/out/street/tier.d.ts +18 -30
  108. package/out/street/tier.d.ts.map +1 -1
  109. package/out/street/tier.js +43 -191
  110. package/out/street/tier.js.map +1 -1
  111. package/out/{street/index.d.ts → street.d.ts} +1 -1
  112. package/out/street.d.ts.map +1 -0
  113. package/out/{street/index.js → street.js} +1 -1
  114. package/out/street.js.map +1 -0
  115. package/out/toponym-prior.d.ts +22 -110
  116. package/out/toponym-prior.d.ts.map +1 -1
  117. package/out/toponym-prior.js +41 -170
  118. package/out/toponym-prior.js.map +1 -1
  119. package/package.json +44 -147
  120. package/lib/resolve/index.ts +0 -989
  121. package/out/admin/index.d.ts.map +0 -1
  122. package/out/admin/index.js.map +0 -1
  123. package/out/postcode/index.d.ts.map +0 -1
  124. package/out/postcode/index.js.map +0 -1
  125. package/out/resolve/index.d.ts +0 -20
  126. package/out/resolve/index.d.ts.map +0 -1
  127. package/out/resolve/index.js +0 -808
  128. package/out/resolve/index.js.map +0 -1
  129. package/out/street/index.d.ts.map +0 -1
  130. package/out/street/index.js.map +0 -1
  131. package/vitest.config.ts +0 -38
  132. /package/lib/{admin/index.ts → admin.ts} +0 -0
  133. /package/lib/{postcode/index.ts → postcode.ts} +0 -0
  134. /package/lib/{street/index.ts → street.ts} +0 -0
@@ -2,38 +2,30 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * `RemoteResolver` — the `Resolver` interface (`resolveTree`) over HTTP. The adapter the interface
7
- * docstring anticipated (Phase 4.4): a client POSTs a parsed `AddressTree` + the serializable
8
- * `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation extracts,
9
- * runs the cascade, and returns the resolved tree. Two payoffs:
10
- *
11
- * 1. **Multi-instance** — stateless parser nodes (the ~30 MB ONNX model) talk to ONE resolver service
12
- * (the multi-GB gazetteer + extracts). `parse` locally, `new RemoteResolver(...).resolveTree`
13
- * remotely — same interface the in-process `WOFResolver` satisfies, so it's a drop-in.
14
- * 2. **Canary** — point it at a second resolver build (or an adapter fronting Pelias/Nominatim/BAN)
15
- * and diff the resolved trees through the identical contract.
16
- *
17
- * Pure transport: `fetch` only, no node-specific deps (runs in the browser too). The
18
- * `addressPoints` / `interpolation` opts are LIVE SQLite handles — not serializable — so they're
19
- * stripped before the POST; the resolver service supplies its own from the tree's region (the
20
- * data lives server-side, which is the whole point). All other opts (defaultCountry, calibration,
21
- * hierarchyCompletion, …) ride along.
22
5
  */
6
+ import { stringifyJSON } from "@mailwoman/core/json";
23
7
  /**
24
- * Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over HTTP.
8
+ * Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over http.
25
9
  */
26
10
  export function serializableResolveOpts(opts) {
27
11
  if (!opts)
28
- return undefined;
12
+ return null;
29
13
  const { addressPoints: _ap, interpolation: _ip, ...rest } = opts;
30
14
  return rest;
31
15
  }
16
+ /**
17
+ * Resolves address trees by POSTing them to a remote resolver endpoint, so a client
18
+ * can resolve without loading gazetteer databases itself.
19
+ *
20
+ * Live lookup handles in `ResolveOpts` are dropped before sending, so the server resolves with its own.
21
+ */
32
22
  export class RemoteResolver {
33
23
  #endpoint;
34
24
  #fetch;
35
25
  #timeoutMs;
36
26
  #headers;
27
+ artifactCoverage = null;
28
+ capabilityGaps = null;
37
29
  constructor(opts) {
38
30
  if (!opts.endpoint)
39
31
  throw new Error("RemoteResolver: `endpoint` is required");
@@ -50,7 +42,7 @@ export class RemoteResolver {
50
42
  const res = await this.#fetch(this.#endpoint, {
51
43
  method: "POST",
52
44
  headers: { "Content-Type": "application/json", ...this.#headers },
53
- body: JSON.stringify(body),
45
+ body: stringifyJSON(body),
54
46
  signal: controller.signal,
55
47
  });
56
48
  if (!res.ok) {
@@ -1 +1 @@
1
- {"version":3,"file":"remote-resolver.js","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAkB;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAC3B,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;IAEhE,OAAO,IAAI,CAAA;AACZ,CAAC;AA6CD,MAAM,OAAO,cAAc;IACjB,SAAS,CAAQ;IACjB,MAAM,CAAqB;IAC3B,UAAU,CAAQ;IAClB,QAAQ,CAAwB;IAEzC,YAAY,IAAwB;QACnC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;QAC7E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;QAC5C,IAAI,CAAC,UAAU,GA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E,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAEnE,IAAI,CAAC;YACJ,MAAM,IAAI,GAAuB,EAAE,IAAI,EAAE,IAAI,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAA;YAE9E,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE;gBAC7C,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;gBACjE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC;gBACzB,MAAM,EAAE,UAAU,CAAC,MAAM;aACzB,CAAC,CAAA;YAEF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,SAAS,WAAW,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,CAAA;YAC5F,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAiC,CAAA;YAE/D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5D,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;YAC7E,CAAC;YAED,OAAO,IAAI,CAAC,IAAI,CAAA;QACjB,CAAC;gBAAS,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACF,CAAC;CACD"}
package/out/rerank.d.ts CHANGED
@@ -3,47 +3,26 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * #727 stage-2 Phase 4a — reranking a k-best parse list on RESOLUTION EVIDENCE.
7
- *
8
- * The arc's thesis, stated by the operator (2026-07-15): the arbiter for a k-best list is the
9
- * resolver, not hand-weights. A rank-2 parse that resolves to a real place beats a rank-1 that
10
- * resolves to a country centroid.
11
- *
12
- * The measured case for this existing at all: on the triaged parity corpus the shipped decode gets
13
- * street 0.573 while the span decode's top-10 CONTAINS the right answer 0.775 of the time
14
- * (oracle@5 0.723). Rank-1 cannot reach that headroom; only a reranker can.
15
- *
16
- * ## Why this is deliberately, almost embarrassingly small
17
- *
18
- * The failure mode we are avoiding is Pelias's: a ladder of per-class hand-tuned weights that
19
- * nobody can re-derive (see `docs/articles/evals/competitive-parity/2026-07-15-pelias-dictionary-overrides.md`
20
- * — 94 of 276 dictionary lines are hand-written deletions, each resolving a collision in favour of
21
- * whoever complained loudest). The moment this file grows a per-hypothesis score blend, we have
22
- * rebuilt that with extra steps.
23
- *
24
- * So the rule is ONE bit of evidence, not a score: **drop hypotheses whose resolution is
25
- * implausible; otherwise keep the model's own ranking.** The parse scores already share a partition
26
- * function and are comparable within an input — the reranker's job is not to re-score them, it is to
27
- * veto the ones the world says are wrong.
28
- *
29
- * Adding a second signal here requires the same bar the first one cleared: a MEASURED win on the
30
- * parity + Paris fixtures, stated in a verdict doc. Not a plausible story.
6
+ * Rerank a k-best parse list on resolution evidence with one bit — drop hypotheses whose resolution
7
+ * is implausible, otherwise keep the model's own ranking — because a second signal here needs a
8
+ * measured win on the parity + Paris fixtures.
31
9
  */
32
10
  import type { AddressTree } from "@mailwoman/core/decoder";
11
+ import type { CountryBBoxFact } from "@mailwoman/core/resolver";
33
12
  /**
34
13
  * One candidate parse from the k-best decode, with its (within-input comparable) score.
35
14
  */
36
15
  export interface RerankCandidate<T = unknown> {
37
16
  /**
38
- * The parse's own score. Comparable to its siblings from the SAME input; not across inputs.
17
+ * The parse's own score, comparable to its siblings from the same input and not across inputs.
39
18
  */
40
19
  score: number;
41
20
  /**
42
- * The parse tree, UNRESOLVED — `rerankByResolution` resolves it via the injected resolver.
21
+ * The parse tree, unresolved — `rerankByResolution` resolves it via the injected resolver.
43
22
  */
44
23
  tree: AddressTree;
45
24
  /**
46
- * Opaque caller payload carried through to the result (the segmentation, a surface string, …).
25
+ * Opaque caller payload passed through to the result (the segmentation, a surface string, …).
47
26
  */
48
27
  payload?: T;
49
28
  }
@@ -59,46 +38,53 @@ export interface RerankedCandidate<T = unknown> extends RerankCandidate<T> {
59
38
  /**
60
39
  * Why it was vetoed, when it was.
61
40
  */
62
- reason?: string;
41
+ reason: string | null;
63
42
  }
64
43
  export interface RerankResult<T = unknown> {
65
44
  /**
66
- * Candidates in FINAL order: plausible ones first (model order preserved), vetoed ones after.
45
+ * Candidates in final order: plausible ones first (model order preserved), vetoed ones after.
67
46
  */
68
47
  ranked: Array<RerankedCandidate<T>>;
69
48
  /**
70
- * The winner — the first plausible candidate, or the model's rank-1 when ALL were vetoed.
49
+ * The winner — the first plausible candidate, or the model's rank-1 when all were vetoed.
71
50
  */
72
51
  best: RerankedCandidate<T>;
73
52
  /**
74
- * True when the winner is NOT the model's rank-1 — i.e. resolution evidence actually changed the answer. This is the
75
- * metric the arc is judged on (`rank-2-beats-rank-1 rate`); log it, because a rerank that never fires is a rerank
76
- * that is not earning its resolver calls.
53
+ * True when resolution evidence actually changed the answer from the model's rank-1.
77
54
  */
78
55
  changed: boolean;
79
56
  }
80
57
  /**
81
- * Resolve a tree. Structural — any `Resolver`-shaped thing satisfies it.
58
+ * Resolve a tree.
59
+ * Structural, so any `Resolver`-shaped thing satisfies it.
82
60
  */
83
61
  export type ResolveTree = (tree: AddressTree) => Promise<AddressTree>;
84
62
  export interface RerankOpts {
85
63
  /**
86
- * Resolve at most this many candidates (default 5). Each costs a resolver round-trip, so this is the latency knob.
87
- * oracle@5 (0.723) captures nearly all the measured headroom of oracle@10 (0.775), so 5 is the default rather than 10
88
- * — the last 5 candidates cost 2x the resolves for ~5pp of ceiling.
64
+ * Resolve at most this many candidates.
65
+ *
66
+ * Each costs a resolver round-trip, so this is the latency knob.
67
+ *
68
+ * @defaultValue `5`
89
69
  */
90
70
  maxResolve?: number;
71
+ /**
72
+ * ISO-2 country the resolutions are expected to land in, threaded to {@link isImplausibleResolution}
73
+ * as guard B so a coordinate outside that country's coarse box is vetoed.
74
+ * Omitted, only the bare-country-centroid guard runs.
75
+ */
76
+ expectedCountry?: string;
77
+ /**
78
+ * The loaded artifact's own guard-B boxes, replacing the built-in table wholesale when supplied.
79
+ */
80
+ countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>;
91
81
  }
92
82
  /**
93
- * Rerank a k-best parse list on resolution evidence.
94
- *
95
- * Resolves up to `maxResolve` candidates IN MODEL ORDER and returns the first whose resolution is plausible. Candidates
96
- * beyond `maxResolve` are never resolved (and never vetoed — they simply keep their model rank behind the resolved
97
- * ones).
83
+ * Rerank a k-best parse list on resolution evidence: resolve up to `maxResolve`
84
+ * candidates in model order and return the first plausible one.
98
85
  *
99
- * **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
100
- * than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
101
- * grounds to flag low confidence (the Phase-4b ambiguity check).
86
+ * Candidates beyond `maxResolve` are never resolved or vetoed. when every resolved
87
+ * candidate is implausible the model's rank-1 wins.
102
88
  */
103
89
  export declare function rerankByResolution<T>(candidates: ReadonlyArray<RerankCandidate<T>>, resolveTree: ResolveTree, opts?: RerankOpts): Promise<RerankResult<T>>;
104
90
  //# sourceMappingURL=rerank.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rerank.d.ts","sourceRoot":"","sources":["../lib/rerank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAI1D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC3C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,EAAE,WAAW,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC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EAAE,WAAW,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAA;CACX;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACzE;;OAEG;IACH,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAA;IAC5B;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACxC;;OAEG;IACH,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC;;OAEG;IACH,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;IAC1B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;CAChB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;AAErE,MAAM,WAAW,UAAU;IAC1B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CACpD;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACzC,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,WAAW,EAAE,WAAW,EACxB,IAAI,GAAE,UAAe,GACnB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CA6C1B"}
package/out/rerank.js CHANGED
@@ -3,43 +3,17 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * #727 stage-2 Phase 4a — reranking a k-best parse list on RESOLUTION EVIDENCE.
7
- *
8
- * The arc's thesis, stated by the operator (2026-07-15): the arbiter for a k-best list is the
9
- * resolver, not hand-weights. A rank-2 parse that resolves to a real place beats a rank-1 that
10
- * resolves to a country centroid.
11
- *
12
- * The measured case for this existing at all: on the triaged parity corpus the shipped decode gets
13
- * street 0.573 while the span decode's top-10 CONTAINS the right answer 0.775 of the time
14
- * (oracle@5 0.723). Rank-1 cannot reach that headroom; only a reranker can.
15
- *
16
- * ## Why this is deliberately, almost embarrassingly small
17
- *
18
- * The failure mode we are avoiding is Pelias's: a ladder of per-class hand-tuned weights that
19
- * nobody can re-derive (see `docs/articles/evals/competitive-parity/2026-07-15-pelias-dictionary-overrides.md`
20
- * — 94 of 276 dictionary lines are hand-written deletions, each resolving a collision in favour of
21
- * whoever complained loudest). The moment this file grows a per-hypothesis score blend, we have
22
- * rebuilt that with extra steps.
23
- *
24
- * So the rule is ONE bit of evidence, not a score: **drop hypotheses whose resolution is
25
- * implausible; otherwise keep the model's own ranking.** The parse scores already share a partition
26
- * function and are comparable within an input — the reranker's job is not to re-score them, it is to
27
- * veto the ones the world says are wrong.
28
- *
29
- * Adding a second signal here requires the same bar the first one cleared: a MEASURED win on the
30
- * parity + Paris fixtures, stated in a verdict doc. Not a plausible story.
6
+ * Rerank a k-best parse list on resolution evidence with one bit — drop hypotheses whose resolution
7
+ * is implausible, otherwise keep the model's own ranking — because a second signal here needs a
8
+ * measured win on the parity + Paris fixtures.
31
9
  */
32
10
  import { isImplausibleResolution } from "#plausibility";
33
11
  /**
34
- * Rerank a k-best parse list on resolution evidence.
12
+ * Rerank a k-best parse list on resolution evidence: resolve up to `maxResolve`
13
+ * candidates in model order and return the first plausible one.
35
14
  *
36
- * Resolves up to `maxResolve` candidates IN MODEL ORDER and returns the first whose resolution is plausible. Candidates
37
- * beyond `maxResolve` are never resolved (and never vetoed — they simply keep their model rank behind the resolved
38
- * ones).
39
- *
40
- * **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
41
- * than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
42
- * grounds to flag low confidence (the Phase-4b ambiguity check).
15
+ * Candidates beyond `maxResolve` are never resolved or vetoed. when every resolved
16
+ * candidate is implausible the model's rank-1 wins.
43
17
  */
44
18
  export async function rerankByResolution(candidates, resolveTree, opts = {}) {
45
19
  if (!candidates.length)
@@ -49,8 +23,7 @@ export async function rerankByResolution(candidates, resolveTree, opts = {}) {
49
23
  for (let i = 0; i < candidates.length; i++) {
50
24
  const candidate = candidates[i];
51
25
  if (i >= maxResolve) {
52
- // Beyond the resolve budget: carried through unresolved, never vetoed.
53
- ranked.push({ ...candidate, resolved: null, implausible: false });
26
+ ranked.push({ ...candidate, resolved: null, implausible: false, reason: null });
54
27
  continue;
55
28
  }
56
29
  let resolved;
@@ -58,20 +31,22 @@ export async function rerankByResolution(candidates, resolveTree, opts = {}) {
58
31
  resolved = await resolveTree(candidate.tree);
59
32
  }
60
33
  catch {
61
- // A resolver failure is NOT evidence against the parse — treat it as "no evidence" and let
62
- // the model's rank stand, rather than vetoing a possibly-correct hypothesis on an outage.
63
- ranked.push({ ...candidate, resolved: null, implausible: false });
34
+ // A resolver failure is not evidence against the parse, so the model's rank stands
35
+ // rather than vetoing a possibly-correct hypothesis on an outage.
36
+ ranked.push({ ...candidate, resolved: null, implausible: false, reason: null });
64
37
  continue;
65
38
  }
66
- const verdict = isImplausibleResolution(resolved);
39
+ const verdict = isImplausibleResolution(resolved, {
40
+ ...(opts.expectedCountry ? { expectedCountry: opts.expectedCountry } : {}),
41
+ ...(opts.countryBBoxes ? { countryBBoxes: opts.countryBBoxes } : {}),
42
+ });
67
43
  ranked.push({
68
44
  ...candidate,
69
45
  resolved,
70
46
  implausible: verdict.implausible,
71
- ...(verdict.reason ? { reason: verdict.reason } : {}),
47
+ reason: verdict.reason,
72
48
  });
73
49
  }
74
- // Stable partition: plausible first (model order preserved within each group), vetoed after.
75
50
  const plausible = ranked.filter((r) => !r.implausible);
76
51
  const vetoed = ranked.filter((r) => r.implausible);
77
52
  const finalOrder = [...plausible, ...vetoed];
package/out/rerank.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rerank.js","sourceRoot":"","sources":["../lib/rerank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAkEvD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,UAA6C,EAC7C,WAAwB,EACxB,IAAI,GAAe,EAAE;IAErB,IAAI,CAAC,UAAU,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;IAC3F,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;IACjF,MAAM,MAAM,GAAgC,EAAE,CAAA;IAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAE,CAAA;QAEhC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;YACrB,uEAAuE;YACvE,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAA;YAEjE,SAAQ;QACT,CAAC;QAED,IAAI,QAA4B,CAAA;QAEhC,IAAI,CAAC;YACJ,QAAQ,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAC7C,CAAC;QAAC,MAAM,CAAC;YACR,2FAA2F;YAC3F,0FAA0F;YAC1F,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,Q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