Skip to content

mempalace.entity_registry

Source: mempalace/entity_registry.py

entity_registry.py — Persistent personal entity registry for MemPalace.

Knows the difference between Riley (a person) and ever (an adverb). Built from three sources, in priority order:

  1. Onboarding — what the user explicitly told us
  2. Learned — what we inferred from session history with high confidence
  3. Researched — what we looked up via Wikipedia for unknown words

Usage: from mempalace.entity_registry import EntityRegistry registry = EntityRegistry.load() result = registry.lookup("Riley", context="I went with Riley today") # → {"type": "person", "confidence": 1.0, "source": "onboarding"}

Classes

class EntityRegistry

Persistent personal entity registry.

Stored at ~/.mempalace/entity_registry.json Schema: { "mode": "personal", # work | personal | combo "version": 1, "people": { "Riley": { "source": "onboarding", "contexts": ["personal"], "aliases": [], "relationship": "daughter", "confidence": 1.0 } }, "projects": ["MemPalace", "Acme"], "ambiguous_flags": ["riley", "max"], "wiki_cache": { "Sam": {"inferred_type": "person", "confidence": 0.9, "confirmed": true, ...} } }

__init__

python
def __init__(self, data: dict, path: Path)

load

python
def load(cls, config_dir: Optional[Path] = None) -> 'EntityRegistry'

save

python
def save(self)

mode

python
def mode(self) -> str

people

python
def people(self) -> dict

projects

python
def projects(self) -> list

ambiguous_flags

python
def ambiguous_flags(self) -> list

seed

python
def seed(self, mode: str, people: list, projects: list, aliases: dict = None)

Seed the registry from onboarding data.

people: list of dicts {"name": str, "relationship": str, "context": str} projects: list of str aliases: dict {"Max": "Maxwell", ...}

lookup

python
def lookup(self, word: str, context: str = '') -> dict

Look up a word. Returns entity classification.

context: surrounding sentence (used for disambiguation of ambiguous words)

Returns: {"type": "person"|"project"|"concept"|"unknown", "confidence": float, "source": "onboarding"|"learned"|"wiki"|"inferred", "name": canonical name if found, "needs_disambiguation": bool}

research

python
def research(self, word: str, auto_confirm: bool = False, allow_network: bool = False) -> dict

Research an unknown word.

By default this is local-only: it checks the wiki cache and returns "unknown" for uncached words. Pass allow_network=True to explicitly opt in to an outbound Wikipedia lookup. This design honours the project's local-first, zero API and privacy by architecture principles — no data leaves the machine unless the caller requests it.

Caches result. If auto_confirm is False, marks the entry as unconfirmed (needs user review).

confirm_research

python
def confirm_research(self, word: str, entity_type: str, relationship: str = '', context: str = 'personal')

Mark a researched word as confirmed and add to people registry.

learn_from_text

python
def learn_from_text(self, text: str, min_confidence: float = 0.75, languages = ('en',)) -> list

Scan session text for new entity candidates. Returns list of newly discovered candidates for review.

languages is forwarded to entity detection — pass the user's configured MempalaceConfig().entity_languages to match the locales used at mempalace init time.

extract_people_from_query

python
def extract_people_from_query(self, query: str) -> list

Extract known person names from a query string. Returns list of canonical names found.

extract_unknown_candidates

python
def extract_unknown_candidates(self, query: str) -> list

Find capitalized words in query that aren't in registry or common words. These are candidates for Wikipedia research.

summary

python
def summary(self) -> str

Released under the MIT License.