Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:24kchengYe MemoMind spaCy NER

From Leeroopedia
Knowledge Sources
Domains Infrastructure, NLP
Last Updated 2026-10-28 14:45 GMT

Overview

spaCy NLP library for named entity recognition (NER) used by the entity resolution pipeline to extract and disambiguate entities across memory units.

Description

This environment provides the spaCy NLP library used by the `EntityResolver` for entity extraction. The module loads a spaCy model (singleton pattern via `_nlp` global) to perform named entity recognition on memory text. Extracted entities are then resolved to canonical IDs using either a full lookup strategy (load all bank entities, match in Python) or a trigram strategy (use PostgreSQL `pg_trgm` GIN index for faster fuzzy matching on large banks). Entity resolution also tracks co-occurrence counts for graph link creation.

Note: In the current MemoMind architecture, entities are primarily extracted by the LLM during fact extraction (not spaCy). The spaCy model is loaded as a singleton but the LLM-provided entities are the primary input to the resolution pipeline. spaCy may be used for supplementary NER.

Usage

Use this environment for entity resolution during the retain pipeline — extracting named entities from text and resolving them to canonical IDs, building the entity graph used for link-based retrieval.

System Requirements

Category Requirement Notes
OS Linux / macOS / Windows Pure Python + compiled extensions
Hardware 4GB+ RAM spaCy model loading is memory-intensive
Disk ~500MB for model en_core_web_md ~50MB; en_core_web_lg ~560MB

Dependencies

Python Packages

  • `spacy` >= 3.5 — NLP library for NER
  • `asyncpg` — Used by EntityResolver for DB queries (shared with PostgreSQL env)

spaCy Models

  • `en_core_web_sm` — Small model (~12MB, basic NER)
  • `en_core_web_md` — Medium model (~50MB, better accuracy)
  • `en_core_web_lg` — Large model (~560MB, best accuracy)

Credentials

No credentials required. spaCy models are downloaded locally.

Model installation:

python -m spacy download en_core_web_sm

Quick Install

pip install spacy
python -m spacy download en_core_web_sm

Code Evidence

spaCy singleton loader from `entity_resolver.py:57-58`:

# Load spaCy model (singleton)
_nlp = None

Entity lookup strategy from `entity_resolver.py:66-77`:

def __init__(self, pool: asyncpg.Pool, entity_lookup: str = "full"):
    """
    Args:
        pool: asyncpg connection pool
        entity_lookup: Lookup strategy — "full" loads all bank entities then
            matches in Python; "trigram" uses pg_trgm GIN index to fetch only
            similar candidates per entity name (much faster for large banks).
    """
    self.pool = pool
    self.entity_lookup = entity_lookup

Entity resolution dispatch from `entity_resolver.py:204-206`:

if self.entity_lookup == "trigram":
    return await self._resolve_entities_batch_trigram(conn, bank_id, entities_data, unit_event_date)
return await self._resolve_entities_batch_full(conn, bank_id, entities_data, unit_event_date)

Module docstring from `entity_resolver.py:4-5`:

"""Uses spaCy for entity extraction and implements resolution logic
to disambiguate entities across memory units."""

Common Errors

Error Message Cause Solution
`Can't find model 'en_core_web_sm'` spaCy model not downloaded `python -m spacy download en_core_web_sm`
`ImportError: spacy` Package not installed `pip install spacy`
Slow entity resolution on large banks `full` strategy loads all entities Set `HINDSIGHT_API_RETAIN_ENTITY_LOOKUP=trigram` for pg_trgm index

Compatibility Notes

  • LLM-extracted entities: In the current architecture, the LLM extracts entities during fact extraction. spaCy's role is supplementary; the `_nlp` singleton is loaded but the primary entity input comes from the LLM.
  • Trigram strategy: Set `HINDSIGHT_API_RETAIN_ENTITY_LOOKUP=trigram` to use PostgreSQL `pg_trgm` GIN index for faster fuzzy matching — significantly faster for large memory banks.
  • Full strategy: Default; loads all bank entities into memory and matches in Python. Simpler but O(n) per bank.
  • Deadlock prevention: Entity stat updates are sorted by entity_id before batch UPDATE to ensure consistent lock ordering across concurrent workers.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment