Skip to content

Avoid redundant work when resolving entity names - #1060

Merged
zlareb1 merged 3 commits into
mainfrom
perf/entity-ascii-normalization
Nov 20, 2026
Merged

zlareb1 merged 3 commits into
mainfrom
perf/entity-ascii-normalization

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

Entity resolution avoids redundant normalization and stops scoring once ambiguity already prevents a merge, while preserving canonical names and resolution decisions.

Why

A new mention can make the resolver score many near-identical candidates even when two qualifying scores already guarantee that entropy will refuse the merge. Candidate preparation and overlap checks also repeat character work for every write.

The resolver can refuse once two scores qualify and the entropy cutoff is safely below their entropy floor. For n qualifying scores in [m, 1], their total is at most n, so each normalized probability is at least m/n. The probability distribution contains a uniform component of weight m; entropy concavity therefore gives normalized entropy at least m.

The shortcut reserves 64 * ulp(1) * N, where N is the full prepared-candidate count. This covers both sums, probability division and weighted-log evaluation. The guard also keeps positive probabilities away from underflow. Cutoffs near the floor use the original scoring and entropy calculation, preserving floating-point boundary decisions. Exact names still return first, and the existing gap shortcut remains in place.

ASCII names also avoid redundant Unicode folding and use a constant translation table for compaction. Character overlap accumulates integer minima directly, avoiding a Python call for every shared character.

Scope and risk

The change touches entity normalization, compaction, overlap computation and the existing ambiguous-candidate refusal. It retains no per-input cache or private text beyond existing request-local structures.

Canonical text, IDs, aliases, input bounds, candidate limits, thresholds, tie behavior, store queries and inserted rows remain equivalent. The main risks are an incorrectly admitted ASCII character or an entropy shortcut too close to a floating-point boundary. Tests cover the ASCII alphabet, Unicode fallback, exact-name precedence, computed-entropy thresholds and adjacent floats, including score-one compact ties at zero gap.

Compatibility, rollout and rollback

  • Wire: no operations, fields, defaults, ranking thresholds or limits change.
  • Operator steps: none.
  • Rollback: reverting restores the previous computation paths. There are no migrations, retained cache entries or generated-file changes.

Tests

  • LOOM_ENV_FILE= make format-check, make lint, and make typecheck pass.
  • LOOM_ENV_FILE= .venv/bin/python -m pytest tests/unit/test_graph_quality.py tests/unit/test_memory_entities_canonical.py tests/unit/test_point_write_relation_names.py tests/unit/test_entity_resolution.py tests/unit/test_entity_resolution_prefilter.py tests/unit/test_entity_stopwords_and_embed_batch.py -q: 461 passed.
  • The work-budget regression fails on the baseline at 255 and 346 comparisons for two 2,100-name lists. The new source preserves the same refusal with four and three comparisons, within the test budget of eight.
  • Differential checks against two immutable baselines cover 3,000 varied-parameter decisions, 6,420 computed-entropy and rounding-boundary decisions, 200 complete resolver cases, and 5,000-row candidate subsets. Decisions, complete queries and inserted rows match. Additional numerical stress covers up to 5,000 compact-equal candidates.
  • The earlier independent normalization comparison covered 131,001 cases across text, IDs, aliases and length acceptance, with no differences.
  • Hosted unit shards, coverage, floors, benchmark harness checks, integration shards, both authority versions, isolation, mixed-version checks and quickstarts pass on the published commit. The translation checker worker exited during the first unit shard run. An isolated seeded reproduction passed, and one same-commit job retry passed; the original worker exit remains unexplained.
  • Cell acceptance failed its latency guard: the p99 delta is 22.350138 ms against a 10 ms limit. The throughput guard passes. All workload arms completed, and independent provenance verified all 45,500 receipt rows with matching hashes; retirement and cleanup completed. The latency check is still failing at merge.
  • Fresh independent source review of the published commit reports no findings.

This bounded offline command reproduces the comparison count without providers or a database:

.venv/bin/python - <<'PY'
import subprocess
import sys
import types
from server.memory.app import entity_resolution as after
before = types.ModuleType('baseline_entity_resolver')
sys.modules[before.__name__] = before
exec(subprocess.check_output(['git', 'show', '0fcee34187d9ad509c00c8748558b3f2337d504d:server/memory/app/entity_resolution.py'], text=True), before.__dict__)
for prefix in ('record-abcdefghijklmnopqrstuvwxyz', 'catalog-0123456789abcdef0123456789abcdef'):
    names = [f'{prefix}-{arm}-{i}' for arm in range(3) for i in range(700)]
    for module in (before, after):
        count = [0]
        original = module._prepared_similarity
        def measured(*args):
            count[0] += 1
            return original(*args)
        module._prepared_similarity = measured
        decision = module.choose_canonical_candidate(f'{prefix}-3-1800', names)
        module._prepared_similarity = original
        print(module.__name__, decision.strategy, count[0])
PY

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: Codex wrote the change and checked mathematical and floating-point boundaries, affected callers, complete resolver operations, focused tests and static gates. A fresh independent source review of the published head reports no findings.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: no generated interfaces change.
  • A new migration is additive and numbered after the latest on main; no migration changes.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version; no plugin changes.
  • The frontend builds and its tests pass, if frontend/ changed; no frontend changes.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes; behavior and interfaces are unchanged.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 20, 2026 6:33pm UTC

Request Review

Candidate names often already survive normalization unchanged. Recognize that subset before Unicode and punctuation folding while keeping the final entity rules shared.

Signed-off-by: Lareb Zafar <[email protected]>
Two qualifying scores already exceed the entropy limit when its threshold is below a conservative entropy floor. Keep uncertain numerical boundaries on the full scoring path and preserve the existing gap shortcut.

Signed-off-by: Lareb Zafar <[email protected]>
Candidate preparation and rejected overlap checks still dominate writes with few qualifying matches. Use a constant ASCII deletion table and direct integer overlap accumulation while preserving Unicode and multiset behavior.

Signed-off-by: Lareb Zafar <[email protected]>
@zlareb1 zlareb1 changed the title Skip Unicode folding for plain ASCII entity names Avoid redundant work when resolving entity names Nov 20, 2026
@zlareb1
zlareb1 force-pushed the perf/entity-ascii-normalization branch from 0fcee34 to e0482d3 Compare November 20, 2026 18:31
@zlareb1
zlareb1 merged commit 17bc84a into main Nov 20, 2026
92 of 94 checks passed
@zlareb1
zlareb1 deleted the perf/entity-ascii-normalization branch November 20, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant