Skip to content

fix: use correct registry key in spellcheck entity lookup#570

Closed
arnoldwender wants to merge 1 commit intoMemPalace:developfrom
arnoldwender:fix/spellcheck-registry-key
Closed

fix: use correct registry key in spellcheck entity lookup#570
arnoldwender wants to merge 1 commit intoMemPalace:developfrom
arnoldwender:fix/spellcheck-registry-key

Conversation

@arnoldwender
Copy link
Copy Markdown
Contributor

Summary

  • Fixed _load_known_names() in spellcheck.py to read from "people" key instead of non-existent "entities" key
  • Fixed canonical name extraction: the name IS the dict key, not a "canonical" field

Problem

spellcheck.py:122 reads entity data with:

for entity in reg._data.get("entities", {}).values():
    names.add(entity.get("canonical", "").lower())

But EntityRegistry uses "people" as the key (not "entities"), and each person entry has no "canonical" field — the canonical name is the dict key itself:

{"people": {"Riley": {"source": "onboarding", "aliases": [...], ...}}}

This means _load_known_names() always returns an empty set, so the spellchecker never protects registered entity names from over-correction.

Fix

for name, entity in reg._data.get("people", {}).items():
    names.add(name.lower())
    for alias in entity.get("aliases", []):
        names.add(alias.lower())

Test plan

  • Register a person via onboarding (e.g., "Mempalace")
  • Run spellcheck on text containing that name — it should NOT be "corrected"
  • Aliases should also be protected

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple but impactful fix — _load_known_names() has been silently returning an empty set since it was written, so the spellchecker has never protected registered entity names from over-correction.

The diagnosis is correct:

  • reg._data uses "people" as the key, not "entities"
  • Each entry's canonical name is the dict key itself, not a "canonical" field

The fix handles both cases: canonical names from .items() and aliases from the "aliases" list. That matches how EntityRegistry actually stores data.

We hit a variant of this in our own integration — entity names that were close to common words (e.g. "Comet", "Iris") were getting "corrected" away in spell-check passes because the protection list was empty. This fix would have caught it.

Approved.

jphein added a commit to jphein/mempalace that referenced this pull request Apr 10, 2026
…compress keys

- Default new collections to cosine distance (hnsw:space=cosine) instead
  of L2 — fixes negative similarity scores (MemPalace#568)
- Filter unexpected MCP tool args before dispatch — prevents TypeError
  crash from extra params like top_k (MemPalace#572)
- Rotate WAL at 10 MB with one backup to prevent unbounded growth (MemPalace#573)
- Fix cmd_compress KeyError: align dict keys with compression_stats()
  return values (MemPalace#569)
- Fix spellcheck _load_known_names: read from "people" key, use dict
  keys as canonical names (MemPalace#570)
- Repair command uses cosine distance for rebuilt collection

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jphein
Copy link
Copy Markdown
Collaborator

jphein commented Apr 10, 2026

Incorporated into #562 — reads from people key, uses dict keys as canonical names, and updated the test fixture to match the actual EntityRegistry data structure.

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, narrow fix. LGTM.


[MemPalace-AGI integration — 215 tests, 710 KG entities]

jphein added a commit to jphein/mempalace that referenced this pull request Apr 11, 2026
…, MCP args, spellcheck, init docs

- Remove overly broad \*[^*]+\* from EMOTION_MARKERS (MemPalace#536)
- Replace Unicode checkmark with ASCII + for Windows cp1251/cp1252 (MemPalace#535)
- Fix spellcheck reading from wrong entity registry key (MemPalace#570)
- Add --yes flag to init instructions for non-interactive use (MemPalace#534)
- Default KG query direction to 'both' instead of 'outgoing'
- Fix KG path mismatch in MCP server (MemPalace#538)
- Filter unexpected MCP tool args before dispatch (MemPalace#572)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@bensig bensig changed the base branch from main to develop April 11, 2026 22:21
@arnoldwender
Copy link
Copy Markdown
Contributor Author

Incorporated into #562 by @jphein — closing.

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.

3 participants