Skip to content

feat: add EntityMemory backend with structured key-value fact extraction#17

Merged
Neal006 merged 1 commit into
Neal006:mainfrom
Priyanshu-byte-coder:feat/entity-memory-backend
May 24, 2026
Merged

feat: add EntityMemory backend with structured key-value fact extraction#17
Neal006 merged 1 commit into
Neal006:mainfrom
Priyanshu-byte-coder:feat/entity-memory-backend

Conversation

@Priyanshu-byte-coder
Copy link
Copy Markdown
Contributor

Summary

Adds the EntityMemory backend requested in issue #12.

Instead of storing raw conversation history, EntityMemory maintains a key-value dictionary of extracted facts and returns them as a single compact context block on retrieval.

Implementation (memory/entity.py)

  • Extraction — two regex patterns match the benchmark's canonical message templates:
    • Injection: "My <key> is <value>."
    • Update: "My <key> has changed to <new_value>."
  • Storagedict[key_name → current_value]; updates overwrite in place, so the stale value is gone immediately.
  • Retrieval — serialises all entities into one system message: "[Known facts about the user] my city is Mumbai; my age is 28; ...".

Properties vs other backends

Naive RAG Entity
Token cost O(turns) O(turns) O(unique facts)
Stale value after update yes (until evicted) yes (in index) never
Filler retention yes semantic none
LLM calls 0 0 0

Wiring

  • VALID_BACKENDS in evaluation/benchmark.py — added "entity"
  • _make_memory() — dispatches to EntityMemory()
  • main.py--backends help text updated

Usage

python main.py --backends naive rag cascading entity

Closes #12

EntityMemory extracts (key, value) pairs from messages using regex patterns
matching the benchmark's injection/update templates. Facts are stored in a
dict and returned as a single system-context block on retrieval.

Key properties:
- Fact updates overwrite the stored value immediately (no stale value survives)
- Token cost scales with unique-fact count, not conversation length
- Zero LLM calls, fully deterministic and reproducible

Wired into VALID_BACKENDS, _make_memory(), and the CLI --backends flag.

Closes Neal006#12
@Neal006 Neal006 merged commit fd942b9 into Neal006:main May 24, 2026
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.

Add EntityMemory backend — structured named-entity extraction for LLM memory benchmark

2 participants