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:
- Onboarding — what the user explicitly told us
- Learned — what we inferred from session history with high confidence
- 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__
def __init__(self, data: dict, path: Path)load
def load(cls, config_dir: Optional[Path] = None) -> 'EntityRegistry'save
def save(self)mode
def mode(self) -> strpeople
def people(self) -> dictprojects
def projects(self) -> listambiguous_flags
def ambiguous_flags(self) -> listseed
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
def lookup(self, word: str, context: str = '') -> dictLook 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
def research(self, word: str, auto_confirm: bool = False, allow_network: bool = False) -> dictResearch 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
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
def learn_from_text(self, text: str, min_confidence: float = 0.75, languages = ('en',)) -> listScan 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
def extract_people_from_query(self, query: str) -> listExtract known person names from a query string. Returns list of canonical names found.
extract_unknown_candidates
def extract_unknown_candidates(self, query: str) -> listFind capitalized words in query that aren't in registry or common words. These are candidates for Wikipedia research.
summary
def summary(self) -> str