Skip to content

Commit 826e3bc

Browse files
kAI Shtefanclaude
andcommitted
fix: add missing iter_all_metadatas and propagate EmbeddingModelMismatchError
- Add iter_all_metadatas() to palace.py (paginated metadata reads, needed by mismatch detection and re-mine but missing after cherry-pick) - Fix searcher.py: EmbeddingModelMismatchError was caught by generic except clauses, showing "No palace found" instead of the real error. Now re-raises properly in both search() and search_memories(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c57aca0 commit 826e3bc

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

mempalace/palace.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,27 @@ def get_collection(palace_path: str, collection_name: str = "mempalace_drawers",
9292
)
9393

9494

95+
def iter_all_metadatas(collection, where=None, page_size: int = 10000):
96+
"""Yield every metadata entry in the collection, paginating past the page cap.
97+
98+
ChromaDB's ``collection.get()`` enforces a per-call limit, so a single fetch
99+
silently truncates large palaces. This walks the collection in pages so
100+
callers see every drawer — with or without a ``where`` filter.
101+
"""
102+
offset = 0
103+
while True:
104+
kwargs = {"include": ["metadatas"], "limit": page_size, "offset": offset}
105+
if where is not None:
106+
kwargs["where"] = where
107+
page = collection.get(**kwargs)
108+
metas = page.get("metadatas") or []
109+
if not metas:
110+
break
111+
for m in metas:
112+
yield m
113+
offset += len(metas)
114+
115+
95116
def file_already_mined(collection, source_file: str, check_mtime: bool = False) -> bool:
96117
"""Check if a file has already been filed in the palace.
97118

mempalace/searcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
from pathlib import Path
1111

12+
from .config import EmbeddingModelMismatchError
1213
from .palace import get_collection as _palace_get_collection
1314

1415
logger = logging.getLogger("mempalace_mcp")
@@ -25,6 +26,8 @@ def search(query: str, palace_path: str, wing: str = None, room: str = None, n_r
2526
"""
2627
try:
2728
col = _palace_get_collection(palace_path)
29+
except EmbeddingModelMismatchError:
30+
raise
2831
except Exception:
2932
print(f"\n No palace found at {palace_path}")
3033
print(" Run: mempalace init <dir> then mempalace mine <dir>")
@@ -98,6 +101,8 @@ def search_memories(
98101
"""
99102
try:
100103
col = _palace_get_collection(palace_path)
104+
except EmbeddingModelMismatchError:
105+
raise
101106
except Exception as e:
102107
logger.error("No palace found at %s: %s", palace_path, e)
103108
return {

0 commit comments

Comments
 (0)