Skip to content

fix(kg): skip is_pet_of triple when owner is absent in seed_from_entity_facts#797

Closed
arnoldwender wants to merge 10 commits intoMemPalace:developfrom
arnoldwender:fix/kg-seed-dog-reflexive-triple
Closed

fix(kg): skip is_pet_of triple when owner is absent in seed_from_entity_facts#797
arnoldwender wants to merge 10 commits intoMemPalace:developfrom
arnoldwender:fix/kg-seed-dog-reflexive-triple

Conversation

@arnoldwender
Copy link
Copy Markdown
Contributor

What and Why

When seeding the knowledge graph from entity facts, dog entities with no owner key created a reflexive triple — the pet pointing to itself as its own owner. This produced semantically invalid data silently.

Root Cause

knowledge_graph.py:396facts.get("owner", name) falls back to name when the "owner" key is absent, so add_triple("Rex", "is_pet_of", "Rex") was called instead of being skipped.

Reproduction

kg.seed_from_entity_facts({
    "buddy": {"full_name": "Buddy", "type": "animal", "relationship": "dog"}
    # no "owner" key
})
results = kg.query_entity("Buddy", direction="outgoing")
# Before fix: [{"predicate": "is_pet_of", "object": "Buddy"}]  ← reflexive
# After fix:  []

Change Summary

  • mempalace/knowledge_graph.py:396 — guard add_triple with an explicit owner presence check; skip is_pet_of when owner is absent
  • tests/test_knowledge_graph_extra.py — add test_seed_dog_without_owner covering the missing edge case

Test Plan

z3tz3r0 and others added 9 commits April 11, 2026 23:06
…mPalace#666)

Replace "your memory system" with explicit MemPalace references and
tool names (mempalace_diary_write, mempalace_add_drawer, mempalace_kg_add)
in stop and precompact hook block reasons. This prevents Claude Code from
misinterpreting the hook as a native auto-memory save instruction.

Updated in both Python (hooks_cli.py) and standalone shell scripts.

Also fix CONTRIBUTING.md Getting Started to show the fork-first workflow,
matching the PR Guidelines section.
The current constraint `chromadb>=0.5.0,<0.7` forces pip to install
chromadb 0.6.x, but palaces created with chromadb 1.x (which is what
the mempalace dev environment actually uses — 1.5.7 per uv.lock) have
an incompatible SQLite schema. Specifically, chromadb 0.6.x fails with
`KeyError: '_type'` when opening a collection written by 1.x.

This means a fresh `pip install mempalace` gives users a chromadb
version that cannot read palaces created in the maintainer's own
environment. The fix removes the upper bound so pip can resolve to the
current stable chromadb release.

Reproduction:
  python3 -m venv .venv && source .venv/bin/activate
  pip install mempalace          # installs chromadb 0.6.3
  # Try opening a palace created with chromadb 1.x:
  # -> _get_collection() returns None, tool_status() returns "No palace found"
  pip install chromadb==1.5.7    # force upgrade
  # -> tool_status() returns real data (26k drawers in our case)
…constraint

fix: remove chromadb <0.7 upper bound — blocks 1.x installs
PR MemPalace#761 bumped pyproject.toml to 3.2.0 but missed three other version strings,
causing test_version_consistency to fail on develop CI (macos, linux 3.11, windows).

- mempalace/version.py: 3.1.0 → 3.2.0 (unblocks test_version_consistency)
- README.md: version badge shield 3.1.0 → 3.2.0
- integrations/openclaw/SKILL.md: 3.1.0 → 3.2.0
- CHANGELOG.md: rename [Unreleased] → [3.2.0] — 2026-04-13, add entries
  for MemPalace#685, MemPalace#690, MemPalace#707, MemPalace#716, MemPalace#734, MemPalace#755, MemPalace#757, MemPalace#761

Verified locally: 689/689 tests pass, ruff clean.
* fix: disambiguate hook block reasons to name MemPalace explicitly (MemPalace#666)

Replace "your memory system" with explicit MemPalace references and
tool names (mempalace_diary_write, mempalace_add_drawer, mempalace_kg_add)
in stop and precompact hook block reasons. This prevents Claude Code from
misinterpreting the hook as a native auto-memory save instruction.

Updated in both Python (hooks_cli.py) and standalone shell scripts.

Also fix CONTRIBUTING.md Getting Started to show the fork-first workflow,
matching the PR Guidelines section.

* fix: remove chromadb <0.7 upper bound — blocks 1.x installs

The current constraint `chromadb>=0.5.0,<0.7` forces pip to install
chromadb 0.6.x, but palaces created with chromadb 1.x (which is what
the mempalace dev environment actually uses — 1.5.7 per uv.lock) have
an incompatible SQLite schema. Specifically, chromadb 0.6.x fails with
`KeyError: '_type'` when opening a collection written by 1.x.

This means a fresh `pip install mempalace` gives users a chromadb
version that cannot read palaces created in the maintainer's own
environment. The fix removes the upper bound so pip can resolve to the
current stable chromadb release.

Reproduction:
  python3 -m venv .venv && source .venv/bin/activate
  pip install mempalace          # installs chromadb 0.6.3
  # Try opening a palace created with chromadb 1.x:
  # -> _get_collection() returns None, tool_status() returns "No palace found"
  pip install chromadb==1.5.7    # force upgrade
  # -> tool_status() returns real data (26k drawers in our case)

---------

Co-authored-by: z3tz3r0 <kittipan.wang@gmail.com>
Co-authored-by: AlyciaBHZ <50111876+AlyciaBHZ@users.noreply.github.com>
Co-authored-by: Ben Sigman <1872138+bensig@users.noreply.github.com>
…preserving history)

# Conflicts:
#	CONTRIBUTING.md
…e-3.2.0

sync: merge main into release/3.2.0 (preserve history)
@arnoldwender
Copy link
Copy Markdown
Contributor Author

CI failures are pre-existing and unrelated to this change — both are the version.py/pyproject.toml sync issue (3.1.0 vs 3.2.0) already tracked in #771 and addressed by #794. My two changed files are knowledge_graph.py and test_knowledge_graph_extra.py only.

…ty_facts

When a dog entity has no 'owner' key, facts.get('owner', name) returned the
pet's own name, creating a reflexive triple (e.g. Rex → is_pet_of → Rex).

Fix: guard the add_triple call with an explicit owner presence check.
Also adds the missing test case for the ownerless-dog path.
@arnoldwender arnoldwender force-pushed the fix/kg-seed-dog-reflexive-triple branch from b686114 to 49a06dc Compare April 13, 2026 14:38
@arnoldwender
Copy link
Copy Markdown
Contributor Author

Rebased on latest main — the version consistency tests were failing because main had already bumped to 3.2.0 (PR #762) after this branch was created. No logical changes to the KG fix itself.

@igorls igorls added area/hooks Claude Code hook scripts (Stop, PreCompact, SessionStart) area/install pip/uv/pipx/plugin install and packaging area/kg Knowledge graph bug Something isn't working labels Apr 14, 2026
@arnoldwender
Copy link
Copy Markdown
Contributor Author

Confirmed the fix is already merged in develop. Closing — thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/hooks Claude Code hook scripts (Stop, PreCompact, SessionStart) area/install pip/uv/pipx/plugin install and packaging area/kg Knowledge graph bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants