From 623f0b0b4cf8358493de37e82b3ebf43a20cc08f Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 10 Nov 2026 16:25:48 -0600 Subject: [PATCH 1/4] feat(atlas-core): record embedding_model in atlas_manifest, refuse mixed-model fan-out (#7646) --- .../crates/atlas-core/src/shards/mod.rs | 44 +++++++++++- .../crates/atlas-core/src/shards/scan.rs | 15 +++++ .../crates/atlas-core/tests/shards.rs | 67 +++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/pkgs/atlas-search/crates/atlas-core/src/shards/mod.rs b/pkgs/atlas-search/crates/atlas-core/src/shards/mod.rs index eff3d3ffcb..027cf28d1a 100644 --- a/pkgs/atlas-search/crates/atlas-core/src/shards/mod.rs +++ b/pkgs/atlas-search/crates/atlas-core/src/shards/mod.rs @@ -385,6 +385,14 @@ impl ShardConnector for StdConnector { // ----------------------------------------------------------- manifest --- +/// The embedding model + pipeline identity that produced every +/// shard's vectors (#6060 decision record, contract points M1/M2, +/// #7646): one embedding model for every Atlas tier. Recorded per +/// shard in the manifest's `embedding_model` key and checked before +/// fan-out, so vectors embedded by different models are never merged +/// as if they were comparable. +pub const EMBEDDING_MODEL_ID: &str = "snowflake-arctic-embed-m-v2.0"; + /// A shard's `atlas_manifest` (key/value self-description). #[derive(Debug, Clone, PartialEq, Eq)] pub struct Manifest { @@ -394,6 +402,11 @@ pub struct Manifest { pub part: Option, pub expected_chunks: Option, pub metric: String, + /// The `embedding_model` key: model + pipeline identity of the + /// shard's vectors. `None` when the key is absent (a shard + /// written before the key existed); discovery refuses `None` + /// in strict mode (#7646). + pub embedding_model: Option, } impl Manifest { @@ -414,6 +427,7 @@ impl Manifest { part: pairs.get("part").and_then(|p| p.parse().ok()), expected_chunks: pairs.get("expected_chunks").and_then(|p| p.parse().ok()), metric: need("metric")?, + embedding_model: pairs.get("embedding_model").cloned(), }) } @@ -444,6 +458,8 @@ pub struct ShardInfo { pub topic: String, pub part: u32, pub expected_chunks: Option, + /// The shard's validated `embedding_model` identity (#7646). + pub embedding_model: String, /// `count(*)` of `chunks` at discovery time. pub chunks: u64, pub endpoint: ShardEndpoint, @@ -540,6 +556,10 @@ pub struct DiscoveryOptions { /// The service's maximum tier. Shards above it are never /// connected. pub ceiling: TierCeiling, + /// The embedding-model identity this consumer embeds queries + /// with; shards recording a different (or no) identity are + /// refused at probe (#7646). Defaults to the mandated model. + pub embedding_model: String, pub vec_table: String, /// Integrity failures (unreadable manifest, manifest disagreeing /// with the shard name, wrong metric) normally abort discovery @@ -552,6 +572,7 @@ impl DiscoveryOptions { pub fn new(ceiling: TierCeiling) -> DiscoveryOptions { DiscoveryOptions { ceiling, + embedding_model: EMBEDDING_MODEL_ID.to_string(), vec_table: crate::types::DEFAULT_VEC_TABLE.to_string(), lenient: false, } @@ -568,6 +589,7 @@ struct Candidate { fn probe( connector: &dyn ShardConnector, c: &Candidate, + expected_embedding_model: &str, ) -> Result<(ShardInfo, Arc)> { let t = connector.connect(&c.endpoint, c.tier)?; let m = Manifest::read(t.as_ref()) @@ -593,6 +615,25 @@ fn probe( c.endpoint.name, m.metric ))); } + // M1/M2 (#7646): the shard's vectors must have been embedded by + // the same model + pipeline as this consumer's query vectors. + // A missing key is a refusal too — provenance unknown is not + // provenance shared. Errors name the shard and both identities. + match &m.embedding_model { + None => { + return Err(Error::fatal(format!( + "shard {}: atlas_manifest has no `embedding_model` key; this consumer embeds with `{expected_embedding_model}` and a shard of unknown embedding provenance must not be scanned", + c.endpoint.name + ))); + } + Some(got) if got != expected_embedding_model => { + return Err(Error::fatal(format!( + "shard {}: embedding_model `{got}` does not match this consumer's `{expected_embedding_model}`; vectors from different embedding models are not comparable", + c.endpoint.name + ))); + } + _ => {} + } let n = t .pipeline(&[Stmt::new("SELECT COUNT(*) AS n FROM chunks", vec![])])? .into_iter() @@ -609,6 +650,7 @@ fn probe( topic: c.topic.clone(), part: m.part.unwrap_or(c.part), expected_chunks: m.expected_chunks, + embedding_model: m.embedding_model.clone().unwrap_or_default(), chunks: n.max(0) as u64, endpoint: c.endpoint.clone(), }, @@ -683,7 +725,7 @@ pub fn discover( let probed: Vec)>> = std::thread::scope(|scope| { let handles: Vec<_> = candidates .iter() - .map(|c| scope.spawn(move || probe(connector, c))) + .map(|c| scope.spawn(move || probe(connector, c, &opts.embedding_model))) .collect(); handles .into_iter() diff --git a/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs b/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs index 6a6dfbf079..2ffc68e74c 100644 --- a/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs +++ b/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs @@ -120,6 +120,20 @@ pub fn fanout_scan(set: &ShardSet, q: &FanoutQuery<'_>) -> Result )); } let shards = set.select(q.ceiling, q.topics)?; + // M1 (#7646): never merge across embedding models. Discovery + // already refused shards that disagree with the consumer, but + // the scanned set itself is checked here so a set assembled + // from more than one discovery still cannot mix identities. + if let Some(first) = shards.first() { + for s in &shards[1..] { + if s.embedding_model != first.embedding_model { + return Err(Error::fatal(format!( + "shard fan-out: scanned set mixes embedding models — shard {} records `{}` but shard {} records `{}`; vectors from different embedding models are not comparable, refusing to merge", + first.name, first.embedding_model, s.name, s.embedding_model + ))); + } + } + } let stmt = turso_vector_scan_stmt( set.vec_table(), q.filters, @@ -361,6 +375,7 @@ mod tests { topic: "main".into(), part: 1, expected_chunks: None, + embedding_model: super::EMBEDDING_MODEL_ID.to_string(), chunks: 0, endpoint: ShardEndpoint { name: "atlas-core-secret-main-01".into(), diff --git a/pkgs/atlas-search/crates/atlas-core/tests/shards.rs b/pkgs/atlas-search/crates/atlas-core/tests/shards.rs index 19a927fb00..934bfdcf8d 100644 --- a/pkgs/atlas-search/crates/atlas-core/tests/shards.rs +++ b/pkgs/atlas-search/crates/atlas-core/tests/shards.rs @@ -130,6 +130,7 @@ fn write_shard(dir: &Path, name: &str, chunks: &[Chunk]) { ("part", &part.to_string()), ("expected_chunks", &chunks.len().to_string()), ("metric", "cosine"), + ("embedding_model", "snowflake-arctic-embed-m-v2.0"), ("engine", "tursodb"), ], ); @@ -431,6 +432,72 @@ fn integrity_failures_abort_unless_lenient() { assert!(err.to_string().contains("not cosine"), "{err}"); } +#[test] +fn manifest_round_trip_carries_embedding_model() { + // Oracle (#7646): the manifest key round-trips — a pairs map with + // the key parses into the field, and one without it parses as + // None (refusal is discovery's job, not the parser's). + let mut pairs = std::collections::BTreeMap::new(); + for (k, v) in [ + ("shard", "atlas-core-internal-misc-01"), + ("tier", "internal"), + ("topic", "misc"), + ("metric", "cosine"), + ("embedding_model", "snowflake-arctic-embed-m-v2.0"), + ] { + pairs.insert(k.to_string(), v.to_string()); + } + let m = atlas_core::shards::Manifest::from_pairs(&pairs).unwrap(); + assert_eq!( + m.embedding_model.as_deref(), + Some(atlas_core::shards::EMBEDDING_MODEL_ID) + ); + pairs.remove("embedding_model"); + let m = atlas_core::shards::Manifest::from_pairs(&pairs).unwrap(); + assert_eq!(m.embedding_model, None); +} + +#[test] +fn discovery_refuses_missing_and_mismatched_embedding_model() { + // Oracle (#7646, M1/M2): a shard whose atlas_manifest lacks the + // embedding_model key, or records a different model, is refused + // at discovery with an error naming the shard and both model + // identities; the uniform corpus (fixture-stamped with the + // mandated id) discovers cleanly — see the other tests. + let c = corpus("embedmodel", 31); + + // Missing key. + let con = rusqlite::Connection::open(c.dir.join("atlas-core-internal-misc-01.db")).unwrap(); + con.execute("DELETE FROM atlas_manifest WHERE \"key\" = 'embedding_model'", []) + .unwrap(); + drop(con); + let err = c + .discover(&LogConnector::new(vec![]), Tier::Internal) + .err() + .unwrap(); + let msg = err.to_string(); + assert!(msg.contains("atlas-core-internal-misc-01"), "{msg}"); + assert!(msg.contains("embedding_model"), "{msg}"); + assert!(msg.contains("snowflake-arctic-embed-m-v2.0"), "{msg}"); + + // Mismatched key. + let con = rusqlite::Connection::open(c.dir.join("atlas-core-internal-misc-01.db")).unwrap(); + con.execute( + "INSERT OR REPLACE INTO atlas_manifest VALUES ('embedding_model', 'some-other-model-v9')", + [], + ) + .unwrap(); + drop(con); + let err = c + .discover(&LogConnector::new(vec![]), Tier::Internal) + .err() + .unwrap(); + let msg = err.to_string(); + assert!(msg.contains("atlas-core-internal-misc-01"), "{msg}"); + assert!(msg.contains("some-other-model-v9"), "{msg}"); + assert!(msg.contains("snowflake-arctic-embed-m-v2.0"), "{msg}"); +} + #[test] fn fanout_equals_monolith_oracle_over_random_queries() { let c = corpus("oracle", 21); From 5438d2df5b19f0504eaaddfbaafe049a66c420e6 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 10 Nov 2026 16:31:26 -0600 Subject: [PATCH 2/4] fix(atlas-core): refer to EMBEDDING_MODEL_ID by crate path in scan tests (#7646) --- pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs b/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs index 2ffc68e74c..25ecbd3204 100644 --- a/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs +++ b/pkgs/atlas-search/crates/atlas-core/src/shards/scan.rs @@ -375,7 +375,7 @@ mod tests { topic: "main".into(), part: 1, expected_chunks: None, - embedding_model: super::EMBEDDING_MODEL_ID.to_string(), + embedding_model: crate::shards::EMBEDDING_MODEL_ID.to_string(), chunks: 0, endpoint: ShardEndpoint { name: "atlas-core-secret-main-01".into(), From 948d065b85c5c8b840f9d4891a1c910c61a365a6 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 10 Nov 2026 16:34:14 -0600 Subject: [PATCH 3/4] test(atlas-core): repair stale FanoutQuery/BranchQuery initializers in shards tests (pre-existing on main) --- pkgs/atlas-search/crates/atlas-core/tests/shards.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/atlas-search/crates/atlas-core/tests/shards.rs b/pkgs/atlas-search/crates/atlas-core/tests/shards.rs index 934bfdcf8d..c70ff5c517 100644 --- a/pkgs/atlas-search/crates/atlas-core/tests/shards.rs +++ b/pkgs/atlas-search/crates/atlas-core/tests/shards.rs @@ -959,7 +959,8 @@ fn sharded_backend_routes_filtered_queries_to_the_monolith() { be.shard_set(), &FanoutQuery { qvec: &q, - k: 10, + shard_top_k: 10, + global_top_k: 10, filters: &f, topics: None, ceiling: TierCeiling(Tier::Internal), @@ -975,6 +976,8 @@ fn sharded_backend_routes_filtered_queries_to_the_monolith() { match_expr: Some("nix".into()), query_vector: Some(q.clone()), pool: 10, + shard_top_k: 10, + global_top_k: 10, vector_backend: VectorBackend::Scan, }, &f, @@ -1008,6 +1011,8 @@ fn sharded_backend_routes_filtered_queries_to_the_monolith() { match_expr: None, query_vector: Some(q), pool: 10, + shard_top_k: 10, + global_top_k: 10, vector_backend: VectorBackend::Scan, }, &f, From 81946d8820d6f2dcd529aae0e686c2f227a92285 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 10 Nov 2026 16:37:58 -0600 Subject: [PATCH 4/4] test(atlas-search): stamp embedding_model in cli_parity shard fixtures (#7646 backfill) --- pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs b/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs index d3ef0936d9..2cbdf860ac 100644 --- a/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs +++ b/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs @@ -434,6 +434,7 @@ fn build_shard_dir(db: &Path, tag: &str) -> PathBuf { ("part", part.trim_start_matches('0').to_string()), ("expected_chunks", ids.len().to_string()), ("metric", "cosine".to_string()), + ("embedding_model", "snowflake-arctic-embed-m-v2.0".to_string()), ] { con.execute( "INSERT INTO atlas_manifest VALUES (?, ?)",