Skip to content

World's first open-source enterprise world model.

Recall does not pair two names that carry different numbers (#1134)

WaylandYangb05d85fca492
diff --git a/crates/utopia-store/src/names.rs b/crates/utopia-store/src/names.rs
index 40192c17..687e9694 100644
--- a/crates/utopia-store/src/names.rs
+++ b/crates/utopia-store/src/names.rs
@@ -228,6 +228,54 @@ pub async fn pair_shared_name(
Ok(others.len())
}
+/// 两个名字都带数字、而数字不一样:召回不把它们配成一对。
+///
+/// 名字相近、只差一个数的东西几乎从来不是同一个:`migration 394` 与 `migration 395`、
+/// `#440` 与 `#441`、`海洋探测器1号` 与 `2号`。名字向量分不开它们——只差一个数的两个
+/// 名字在任何嵌入模型下余弦都在 0.9 以上——包含关系也分不开(`migration 39` 是
+/// `migration 395` 的子串)。一个工程文档库上,这类候选裁决了 1,663 对、只合并 3 对,
+/// 却占了队列的四成(#1104)。
+///
+/// **只在两边都有数字时才拦。** 一边没有数字的照常提议:`沧海` 与 `沧海分布式推理平台 2.0`
+/// 是简称对全称,正是包含关系要接住的那一种。
+///
+/// 比的是排过序的数字串,前导零不算(`0106` 就是 `106`),全角数字当半角。中文数字
+/// 不认:`一号` 的「一」和 `一个` 的「一」这里分不出来,宁可照常提议。
+pub fn numbers_differ(a: &str, b: &str) -> bool {
+ let (a, b) = (digit_runs(a), digit_runs(b));
+ !a.is_empty() && !b.is_empty() && a != b
+}
+
+fn digit_runs(name: &str) -> Vec<String> {
+ let mut runs: Vec<String> = Vec::new();
+ let mut open = false;
+ for c in name.chars() {
+ let digit = match c {
+ '0'..='9' => Some(c),
+ '\u{FF10}'..='\u{FF19}' => char::from_u32(c as u32 - 0xFEE0),
+ _ => None,
+ };
+ match digit {
+ Some(d) if open => runs.last_mut().expect("an open run").push(d),
+ Some(d) => {
+ runs.push(d.to_string());
+ open = true;
+ }
+ None => open = false,
+ }
+ }
+ for run in &mut runs {
+ let trimmed = run.trim_start_matches('0');
+ *run = if trimmed.is_empty() {
+ "0".into()
+ } else {
+ trimmed.into()
+ };
+ }
+ runs.sort();
+ runs
+}
+
/// 本名以外的现行名字,按首次记下的先后。给裁决器与审阅卡的「又名」那一行
pub async fn other_names(pool: &PgPool, entity_id: Uuid) -> AppResult<Vec<String>> {
Ok(other_names_many(pool, &[entity_id])
@@ -268,3 +316,36 @@ pub(crate) async fn other_names_many(
}
Ok(names)
}
+
+#[cfg(test)]
+mod tests {
+ use super::numbers_differ;
+
+ #[test]
+ fn names_with_different_numbers_are_not_a_pair() {
+ for (a, b) in [
+ ("migration 394", "migration 395"),
+ ("#440", "#441"),
+ ("海洋探测器1号", "海洋探测器2号"),
+ ("api/main.py:84-142", "api/main.py:145-169"),
+ ("migration 39", "migration 395"),
+ ("v1.2", "v1.3"),
+ ] {
+ assert!(numbers_differ(a, b), "{a} / {b}");
+ }
+ }
+
+ #[test]
+ fn the_same_numbers_or_none_on_one_side_still_pair() {
+ for (a, b) in [
+ ("海洋探测器1号", "海探1"),
+ ("沧海", "沧海分布式推理平台 2.0"),
+ ("migration 0106", "migration 106"),
+ ("Q3 2024", "2024 Q3"),
+ ("sección 01010101", "Sección 01010101 (Distrito Nacional)"),
+ ("Sherlock Holmes", "Mr. Holmes"),
+ ] {
+ assert!(!numbers_differ(a, b), "{a} / {b}");
+ }
+ }
+}
diff --git a/crates/utopia-store/src/resolution.rs b/crates/utopia-store/src/resolution.rs
index 660ba2ef..9af51e4d 100644
--- a/crates/utopia-store/src/resolution.rs
+++ b/crates/utopia-store/src/resolution.rs
@@ -318,6 +318,10 @@ async fn propose_by_name_vector(
if near.name.to_lowercase() == mention_name || !seen.insert(near.entity_id) {
continue;
}
+ // 只差一个数的名字向量上几乎重合,却几乎从不是同一个(见 `numbers_differ`)
+ if crate::names::numbers_differ(raw_name, &near.name) {
+ continue;
+ }
let near_family = near
.type_label
.as_deref()
@@ -784,10 +788,13 @@ async fn containment_reviews(
// 哪些类型对可能指同一个东西,既有规则已经想清楚了,别另发明一套:
// 本体声明互斥的永不合并,person vs organization 永不合并,
// concept 兜底与谁都可能是一个
- .filter(|(_, _, type_key, other_type, _)| {
+ .filter(|(_, other_name, type_key, other_type, _)| {
!other_type.is_some_and(|t| disjoint.contains(&t))
&& classify_type_drift(mention_key.as_deref(), type_key.as_deref())
!= TypeDrift::Disjoint
+ // `migration 39` 是 `migration 395` 的子串,但不是它的简称(见 `numbers_differ`)。
+ // 筛在 take 之前:带别的数的兄弟不该占掉真候选的名额
+ && !crate::names::numbers_differ(name, other_name)
})
.take(MAX_CONTAIN_REVIEWS)
.map(|(id, other_name, _, _, emb)| {
diff --git a/crates/utopia-store/tests/store/a_similar_name_is_proposed_not_merged.rs b/crates/utopia-store/tests/store/a_similar_name_is_proposed_not_merged.rs
index 42f32f55..b2c6dd36 100644
--- a/crates/utopia-store/tests/store/a_similar_name_is_proposed_not_merged.rs
+++ b/crates/utopia-store/tests/store/a_similar_name_is_proposed_not_merged.rs
@@ -406,3 +406,73 @@ async fn a_pair_kept_apart_is_not_proposed_again() -> anyhow::Result<()> {
teardown(&pool, &f).await?;
run
}
+
+/// 只差一个数的名字不配对(#1104):向量上几乎重合、字面上互相包含,却不是同一个东西。
+/// 两条通道各守一次;一边没有数字的简称照常提议
+#[tokio::test]
+async fn names_that_carry_different_numbers_are_not_proposed() -> anyhow::Result<()> {
+ let Some(url) = utopia_store::test_db::url() else {
+ return Ok(());
+ };
+ let pool = PgPool::connect(&url).await?;
+ let f = seed(&pool, "name-vector-numbers").await?;
+ let run = async {
+ let resolve = |name: &'static str, vector: Option<&'static [f32]>| {
+ utopia_store::resolution::resolve_mention(
+ &pool,
+ f.kb,
+ Some(f.device),
+ name,
+ None,
+ vector,
+ None,
+ &[],
+ )
+ };
+ // 名字向量:2号 的向量跟 1号 一模一样,照样不提议;没有数字的 队长 不受影响
+ let second = resolve("海洋探测器2号", Some(&[1.0, 0.0, 0.0])).await?;
+ let proposed: Vec<Uuid> = vector_reviews(&second)
+ .into_iter()
+ .map(|(id, _)| id)
+ .collect();
+ assert!(
+ !proposed.contains(&f.probe),
+ "1号 与 2号 不该配对:{:?}",
+ second.reviews
+ );
+ assert!(
+ proposed.contains(&f.captain),
+ "没有数字的名字照常提议:{:?}",
+ second.reviews
+ );
+
+ // 包含关系:`migration 39` 是 `migration 395` 的子串,但不是它的简称
+ let contained = |r: &utopia_store::resolution::Resolution| {
+ r.reviews
+ .iter()
+ .filter(|v| v.reason.starts_with("contains|"))
+ .map(|v| v.other_id)
+ .collect::<Vec<_>>()
+ };
+ let long = resolve("migration 395", None).await?;
+ let short = resolve("migration 39", None).await?;
+ assert!(short.created);
+ assert!(
+ !contained(&short).contains(&long.entity_id),
+ "数字不同的包含不配对:{:?}",
+ short.reviews
+ );
+ // 一边没有数字:简称对全称,正是这条通道要接住的
+ let full = resolve("星云推理平台 2.0", None).await?;
+ let brief = resolve("星云推理平台", None).await?;
+ assert!(
+ contained(&brief).contains(&full.entity_id),
+ "简称照常配到带版本号的全称上:{:?}",
+ brief.reviews
+ );
+ Ok::<_, anyhow::Error>(())
+ }
+ .await;
+ teardown(&pool, &f).await?;
+ run
+}
diff --git a/docs/decisions/0041-a-name-is-a-claim-about-an-entity.md b/docs/decisions/0041-a-name-is-a-claim-about-an-entity.md
index 7050dbbc..d72d53c6 100644
--- a/docs/decisions/0041-a-name-is-a-claim-about-an-entity.md
+++ b/docs/decisions/0041-a-name-is-a-claim-about-an-entity.md
@@ -63,6 +63,8 @@ Candidates for a mention come from:
Recall only proposes. `recall_keys`, `GENERIC_SUFFIXES_CJK` and `GENERIC_WORDS_EN` leave once the bench shows channel 2 finds what they found.
+**Revised 2026-10-10 (#1104).** Channel 2 and containment do not pair two names that both carry numbers when the numbers differ (`names::numbers_differ`): `migration 394` and `migration 395` sit at cosine 0.94 and are never the same thing. A name without a number still pairs with one that has it. On a deployment's 1,663 decided pairs of this kind, 3 were merges.
+
### 4. Evidence decides, read from the ontology and both clocks
For each candidate, evidence is read from the chunk's resolved facts against the candidate's current facts: