Skip to content

Commit 2378f69

Browse files
authored
Merge pull request #359 from AreevAI/fix/354-followups
Close the #354 follow-ups
2 parents 9445d26 + 86ed30e commit 2378f69

41 files changed

Lines changed: 847 additions & 370 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,65 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
88

9+
The follow-ups #354 left open.
10+
11+
### Changed
12+
13+
- **The builtin saved ASSEMBLE queries no longer set `min_score`.** Recall
14+
scores are relative: rank-normalized RRF, where a hit only one of L legs
15+
found scores ≤ 1/L, or a reranker's scores min-max normalized over its
16+
pool. A fixed floor is therefore a rank cut whose depth depends on how many
17+
legs fired. Measured on LoCoMo (`areev-bench --bin min_score_sweep`,
18+
1,982 QAs, `RESULTS.md` §10), the 0.4–0.55 floors on `agent_context`,
19+
Account 360, Meeting Cross Query, Support CoPilot, Sales Playbook, Policy
20+
Library and RFP Questionnaire removed nothing keyless. With a vector leg,
21+
0.5+ cost 4–7 points of gold-evidence recall. `min_score` itself is
22+
unchanged; `cal-reference.md` now says what it cuts.
23+
- **`Decision` carries the provider-reported cost.** `usage.cost` (USD, as
24+
OpenRouter-style gateways report it) becomes `Decision::usd_micros`,
25+
rounded up, and `to_json()` prints it as `usage.usd_micros`. A decision
26+
node now charges it to the run's USD budget; it was hard-coded 0, so a
27+
decision node was free under any `max_usd`. `DecisionRerankStats` sums it,
28+
and the `accuracy` / `decide_calibrate` benches print it. It is never
29+
estimated from tokens. Rust callers building a `Decision` literal add
30+
`usd_micros: None`.
31+
32+
### Added
33+
34+
- **`failure_detail` on `record_tool_call`**, on every surface: MCP
35+
`areev_record_tool_call` (tool count unchanged), CLI `record-tool-call
36+
--failure-detail`, Python `failure_detail=`, Node `failureDetail`. It is
37+
the free text the loop's tool-cause classifier reads when `failure_cause`
38+
is absent; before this, only Rust could set it, so the classifier rarely
39+
fired from MCP. The bindings take it LAST so existing positional callers
40+
keep their meaning; the Rust facade takes it after `failure_cause`.
41+
- `areev-bench --bin min_score_sweep`, plus the LoCoMo parser and TF-IDF
42+
embedder shared with `accuracy` as `areev_bench::locomo`.
43+
44+
### Fixed
45+
46+
- **Timeline mode rendered retracted grains.** It ran its own selection and
47+
skipped the withheld filter, so a `verification_status: retracted` grain
48+
appeared as a dated event. Every mode (single pass, census, timeline) now
49+
shares one selection.
50+
- **Census counts disagreed with the census text.** The section rendered a
51+
prefix of its hits sized by the inner pass's count. Any grain that pass
52+
dropped (withheld, superseded, overridden) shifted the window: a dropped
53+
grain was shown, a kept one vanished, and the count described neither. The
54+
section now renders exactly what the selection admitted, at the disclosure
55+
the allocator chose.
56+
- **`anonymize scan|test` resolved a default memory.** A duplicated
57+
`resolve_db` block ran ahead of their dispatch, creating `~/.areev/` and
58+
printing a "using default memory" line for commands that open nothing.
59+
- **Release dylibs would not load on macOS 27 with Xcode 27.** Cargo's
60+
default release strip runs rustc's bundled `rust-objcopy`. Over a dylib
61+
linked by ld-27037, its output is refused by dyld (`mis-aligned LINKEDIT
62+
string pool`), so a locally built Node addon failed `require()` and a
63+
locally built Python wheel failed `import`. `areev-js` and `areev-py`
64+
now build with `strip = false` (~1.4 MB of std debuginfo). The 1.10.0
65+
artifacts CI published load fine, but CI would hit this once its runners
66+
move to Xcode 27. Executables are unaffected.
67+
968
## [1.10.0] — 2026-09-25
1069

1170
### Added

‎Cargo.toml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ rust-version = "1.90.0"
2323
[profile.release]
2424
lto = "thin"
2525
codegen-units = 1
26+
27+
# The Python extension is a cdylib, and Cargo's default release strip
28+
# (`strip = "debuginfo"`) runs rustc's bundled `rust-objcopy` over it. Linked
29+
# by Xcode 27's ld (ld-27037), that output is refused by macOS 27's dyld —
30+
# `mis-aligned LINKEDIT string pool` — so the wheel will not import. Apple's
31+
# own `strip` output of the same dylib loads, and executables are unaffected.
32+
# Not stripping costs ~1.4 MB of std debuginfo; a wheel that loads is worth it.
33+
[profile.release.package.areev-py]
34+
strip = false

‎crates/areev-bench/RESULTS.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,47 @@ Brier per provider and question type, plus a noul F1 threshold and the 5%
680680
two-band suggestion); `crates/areev-bench/data/decide_calibrate_sample.jsonl`
681681
is a 12-row synthetic smoke set — it proves the plumbing, not calibration.
682682

683+
## 10. `min_score` floors against real recall scores — LoCoMo sweep
684+
685+
`cargo run --release -p areev-bench --bin min_score_sweep -- locomo10.json 10`
686+
(`AREEV_TOPK`, default 20; `AREEV_EMBED_CACHE` swaps in real embeddings)
687+
688+
Since #354 a recall score is real, but it is **relative**: rank-normalized
689+
RRF (each leg adds `1/(60 + rank)`, the pool is divided by its best hit) or,
690+
under `WITH rerank`, the reranker's scores min-max normalized over its pool.
691+
A hit only one of L legs found scores at most 1/L, so a fixed `min_score`
692+
floor is a rank cut whose depth depends on how many legs fired. This sweep
693+
measures that on full LoCoMo (10 conversations, 1,982 answerable QAs): every
694+
turn is an Event, each question recalls the top-k, and each floor reports
695+
whether a gold-evidence turn survives. No LLM, no key. Measured 2026-09-26.
696+
697+
| floor | lexical (BM25, one leg) k=20 | hybrid (BM25 + TF-IDF vector) k=20 | hybrid k=8 | hybrid hits kept / question, k=20 |
698+
|---|---|---|---|---|
699+
| none (0.0) | 65.4% | 62.9% | 52.5% | 20.0 |
700+
| 0.40 | 65.4% | 62.9% | 52.5% | 20.0 |
701+
| 0.45 | 65.4% | 62.0% | 52.5% | 18.3 |
702+
| 0.50 | 65.4% | 57.8% | 48.8% | 12.6 |
703+
| 0.55 | 65.4% | 55.4% | 45.6% | 11.1 |
704+
| 0.75 | 65.4% | 53.6% | 45.3% | 8.6 |
705+
706+
The 0.0 row is the positive control: the path reaches the metric, so a drop
707+
below it is the floor's doing. **Keyless, every floor from 0.2 to 0.75 is a
708+
no-op** — one leg's rank-normalized scores stay above 0.75 through rank 20.
709+
**With a second leg the same floors cut 4–7 points of gold-evidence recall
710+
at 0.5+**, because they drop exactly the hits only one leg found, which is
711+
what a second leg is for. The floor raises the gold share of what is kept
712+
(3.4% → 5.3% at 0.55, k=20) by keeping fewer hits, not better ones. Under a
713+
reranker the pool's worst candidate scores 0.0 however relevant it is, so a
714+
floor there is relative too.
715+
716+
**Consequence:** the seven builtin ASSEMBLE queries (`agent_context`,
717+
Account 360, Meeting Cross Query, Support CoPilot, Sales Playbook, Policy
718+
Library, RFP Questionnaire) carried floors of 0.4–0.55 chosen when every
719+
score was 1.0; they no longer set one. `min_score` stays available as a rank
720+
cut. The relevance floor with an absolute meaning is the calibrated decision
721+
judgment (`drop_below`, CAL-W019 when it drops), which only a calibrated
722+
backend may apply.
723+
683724
## Governed self-improvement on real, public data
684725

685726
Two harnesses measure the same claim as the A/B/A/B bench below, on

‎crates/areev-bench/src/bin/accuracy.rs‎

Lines changed: 2 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
4242
use areev_core::error::Result;
4343
use areev_core::types::Event;
44+
use areev_bench::locomo::{parse_locomo, Conv, TfidfEmbed};
4445
use areev_store::{Areev, AreevOptions, DecisionRerank, DecisionRerankStats, EmbedBackend, RecallTuning, RerankBackend};
4546
use std::collections::{BTreeMap, HashMap, HashSet};
4647
use std::sync::{Arc, Mutex};
@@ -90,159 +91,6 @@ impl EmbedBackend for CachedEmbed {
9091
}
9192
}
9293

93-
// ---------- local TF-IDF (+bigram) embedder (no-API fallback) ----------
94-
struct TfidfEmbed {
95-
dim: usize,
96-
idf: HashMap<String, f32>,
97-
default_idf: f32,
98-
}
99-
impl TfidfEmbed {
100-
fn build(dim: usize, docs: &[String]) -> Self {
101-
let n = docs.len().max(1);
102-
let mut df: HashMap<String, usize> = HashMap::new();
103-
for d in docs {
104-
for t in features(d).into_iter().collect::<HashSet<_>>() {
105-
*df.entry(t).or_insert(0) += 1;
106-
}
107-
}
108-
let idf = df
109-
.iter()
110-
.map(|(t, &c)| (t.clone(), ((n as f32 + 1.0) / (c as f32 + 1.0)).ln() + 1.0))
111-
.collect();
112-
Self { dim, idf, default_idf: (n as f32 + 1.0).ln() + 1.0 }
113-
}
114-
}
115-
fn tokenize(s: &str) -> Vec<String> {
116-
s.chars()
117-
.map(|c| if c.is_alphanumeric() { c.to_ascii_lowercase() } else { ' ' })
118-
.collect::<String>()
119-
.split_whitespace()
120-
.filter(|w| w.len() > 1)
121-
.map(|w| w.to_string())
122-
.collect()
123-
}
124-
/// unigrams + adjacent bigrams
125-
fn features(s: &str) -> Vec<String> {
126-
let toks = tokenize(s);
127-
let mut f = toks.clone();
128-
for w in toks.windows(2) {
129-
f.push(format!("{}_{}", w[0], w[1]));
130-
}
131-
f
132-
}
133-
fn fnv1a(t: &str) -> u64 {
134-
let mut h = 0xcbf29ce484222325u64;
135-
for b in t.bytes() {
136-
h ^= b as u64;
137-
h = h.wrapping_mul(0x100000001b3);
138-
}
139-
h
140-
}
141-
impl EmbedBackend for TfidfEmbed {
142-
fn dim(&self) -> usize {
143-
self.dim
144-
}
145-
fn embed(&self, text: &str) -> Result<Vec<f32>> {
146-
let mut tf: HashMap<String, f32> = HashMap::new();
147-
for t in features(text) {
148-
*tf.entry(t).or_insert(0.0) += 1.0;
149-
}
150-
let mut v = vec![0f32; self.dim];
151-
for (t, c) in tf {
152-
let w = c * self.idf.get(&t).copied().unwrap_or(self.default_idf);
153-
v[(fnv1a(&t) % self.dim as u64) as usize] += w;
154-
}
155-
let norm = v.iter().map(|x| x * x).sum::<f32>().sqrt();
156-
if norm > 0.0 {
157-
for x in &mut v {
158-
*x /= norm;
159-
}
160-
}
161-
Ok(v)
162-
}
163-
fn model(&self) -> &str {
164-
"tfidf-bigram-2048"
165-
}
166-
}
167-
168-
// ---------- LoCoMo records ----------
169-
struct Turn {
170-
dia_id: String,
171-
text: String,
172-
}
173-
struct Qa {
174-
question: String,
175-
answer: String,
176-
evidence: Vec<String>,
177-
category: i64,
178-
}
179-
struct Conv {
180-
turns: Vec<Turn>,
181-
qa: Vec<Qa>,
182-
dates: HashMap<String, String>, // dia_id -> session date (for temporal resolution)
183-
}
184-
185-
fn parse_locomo(v: &serde_json::Value, limit: usize) -> Vec<Conv> {
186-
let mut out = Vec::new();
187-
for sample in v.as_array().unwrap_or(&vec![]).iter().take(limit) {
188-
let mut turns = Vec::new();
189-
let mut dates: HashMap<String, String> = HashMap::new();
190-
if let Some(conv) = sample.get("conversation").and_then(|c| c.as_object()) {
191-
// keys like session_1, session_2, … (skip session_N_date_time)
192-
let mut skeys: Vec<&String> = conv
193-
.keys()
194-
.filter(|k| k.strip_prefix("session_").map(|r| !r.is_empty() && r.chars().all(|c| c.is_ascii_digit())).unwrap_or(false))
195-
.collect();
196-
skeys.sort_by_key(|k| k.strip_prefix("session_").and_then(|r| r.parse::<i64>().ok()).unwrap_or(0));
197-
for sk in skeys {
198-
let date = conv
199-
.get(&format!("{sk}_date_time"))
200-
.and_then(|d| d.as_str())
201-
.unwrap_or("")
202-
.to_string();
203-
if let Some(arr) = conv.get(sk).and_then(|s| s.as_array()) {
204-
for t in arr {
205-
let speaker = t.get("speaker").and_then(|s| s.as_str()).unwrap_or("");
206-
let text = t.get("text").and_then(|s| s.as_str()).unwrap_or("");
207-
let dia = t.get("dia_id").and_then(|s| s.as_str()).unwrap_or("");
208-
if !dia.is_empty() && !text.is_empty() {
209-
dates.insert(dia.to_string(), date.clone());
210-
turns.push(Turn { dia_id: dia.to_string(), text: format!("{speaker}: {text}") });
211-
}
212-
}
213-
}
214-
}
215-
}
216-
let mut qa = Vec::new();
217-
if let Some(arr) = sample.get("qa").and_then(|q| q.as_array()) {
218-
for q in arr {
219-
let evidence: Vec<String> = q
220-
.get("evidence")
221-
.and_then(|e| e.as_array())
222-
.map(|a| a.iter().filter_map(|x| x.as_str().map(str::to_string)).collect())
223-
.unwrap_or_default();
224-
if evidence.is_empty() {
225-
continue; // no gold turn to hit — skip (adversarial abstentions)
226-
}
227-
let answer = q
228-
.get("answer")
229-
.and_then(|a| a.as_str())
230-
.or_else(|| q.get("adversarial_answer").and_then(|a| a.as_str()))
231-
.unwrap_or("")
232-
.to_string();
233-
qa.push(Qa {
234-
question: q.get("question").and_then(|s| s.as_str()).unwrap_or("").to_string(),
235-
answer,
236-
evidence,
237-
category: q.get("category").and_then(|c| c.as_i64()).unwrap_or(0),
238-
});
239-
}
240-
}
241-
out.push(Conv { turns, qa, dates });
242-
}
243-
out
244-
}
245-
24694
// one end-to-end task: retrieval is done, only the (parallelizable) LLM
24795
// reader+judge remain.
24896
#[derive(Clone)]
@@ -603,6 +451,7 @@ fn main() {
603451
println!("| failed requests (fell back to fusion) | {} {} |", sum(DecisionRerankStats::failures), if codes.is_empty() { String::new() } else { format!("({codes})") });
604452
println!("| candidates sent / cache hits | {} / {} |", sum(DecisionRerankStats::candidates_sent), sum(DecisionRerankStats::cache_hits));
605453
println!("| input / output tokens (provider-reported) | {} / {} |", sum(DecisionRerankStats::input_tokens), sum(DecisionRerankStats::output_tokens));
454+
println!("| cost (provider-reported) | ${:.4} |", sum(DecisionRerankStats::usd_micros) as f64 / 1e6);
606455
println!("| summed request latency | {:.1} s |", sum(DecisionRerankStats::latency_ms) as f64 / 1000.0);
607456
let samples: Vec<String> = stats.iter().flat_map(|s| s.failure_samples()).take(3).collect();
608457
for m in samples {

‎crates/areev-bench/src/bin/decide_calibrate.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn main() {
195195
// provider -> (model, calibrated, rows)
196196
let mut by_provider: BTreeMap<String, (String, bool, Vec<Scored>)> = BTreeMap::new();
197197
let (mut total, mut failed) = (0usize, 0usize);
198-
let (mut tok_in, mut tok_out) = (0u64, 0u64);
198+
let (mut tok_in, mut tok_out, mut usd_micros) = (0u64, 0u64, 0u64);
199199
for (ln, line) in raw.lines().enumerate().filter(|(_, l)| !l.trim().is_empty()) {
200200
total += 1;
201201
let fail = |m: String| {
@@ -228,6 +228,7 @@ fn main() {
228228
};
229229
tok_in += d.input_tokens.unwrap_or(0);
230230
tok_out += d.output_tokens.unwrap_or(0);
231+
usd_micros += d.usd_micros.unwrap_or(0);
231232
match score_row(&q, &d.answers["q"], &row["label"]) {
232233
Ok(s) => by_provider
233234
.entry(d.provider.clone())
@@ -286,7 +287,7 @@ fn main() {
286287
println!(" NOTE: uncalibrated backend — these bands may REORDER but never OMIT (proposal §2 rule 2)");
287288
}
288289
}
289-
println!("\nprovider-reported tokens: {tok_in} in / {tok_out} out");
290+
println!("\nprovider-reported tokens: {tok_in} in / {tok_out} out, cost ${:.4}", usd_micros as f64 / 1e6);
290291
println!("total latency: {:.2} s", started.elapsed().as_secs_f64());
291292
if failed > 0 {
292293
println!("\nREFUSED: {failed} of {total} rows failed — a calibration over a partial denominator is not reported");

0 commit comments

Comments
 (0)