Labels: bug
Description
When a palace contains a large number of drawers (~180k+), the MCP tools mempalace_list_wings, mempalace_list_rooms, and mempalace_get_taxonomy all return empty {} results. The same issue affects the wings and rooms fields in mempalace_status.
Meanwhile, mempalace_search works correctly and returns drawers with valid wing and room metadata.
Root Cause
All three functions (and the wings/rooms portion of tool_status) use the same pattern in mcp_server.py:
def tool_list_wings():
col = _get_collection()
wings = {}
try:
all_meta = col.get(include=["metadatas"])["metadatas"] # loads ALL records at once
for m in all_meta:
w = m.get("wing", "unknown")
wings[w] = wings.get(w, 0) + 1
except Exception:
pass # silently swallows any error
return {"wings": wings}
Two problems:
-
col.get() without a limit attempts to load all records into memory at once. On large collections (180k+ drawers), this either triggers a ChromaDB HNSW internal error or causes excessive memory usage / timeout.
-
except Exception: pass silently swallows the error, making it appear as if the palace simply has no wings/rooms, with no indication that an error occurred.
Steps to Reproduce
- Mine a large codebase into the palace (e.g.,
mempalace mine ~/large-project resulting in 100k+ drawers)
- Call
mempalace_list_wings via MCP → returns {"wings": {}}
- Call
mempalace_list_rooms via MCP → returns {"wing": "all", "rooms": {}}
- Call
mempalace_get_taxonomy via MCP → returns {"taxonomy": {}}
- Call
mempalace_status via MCP → returns total_drawers: 183895 but wings: {} and rooms: {}
- Call
mempalace_search with any query → returns results with correct wing and room metadata
Environment
- mempalace version: 3.0.0
- chromadb version: latest via pip
- OS: macOS (Darwin arm64)
- Python: 3.9
- Collection size: ~183,895 drawers
Observed Error (when running manually outside the try/except)
chromadb.errors.InternalError: Error executing plan: Error sending backfill request
to compactor: Failed to apply logs to the hnsw segment writer
This error is completely hidden by the except Exception: pass in the current code.
Suggested Fix
Option A — Pagination: Use col.get() with limit and offset to paginate through records in batches:
def tool_list_wings():
col = _get_collection()
if not col:
return _no_palace()
wings = {}
batch_size = 5000
offset = 0
total = col.count()
while offset < total:
try:
batch = col.get(include=["metadatas"], limit=batch_size, offset=offset)
for m in batch["metadatas"]:
w = m.get("wing", "unknown")
wings[w] = wings.get(w, 0) + 1
offset += batch_size
except Exception as e:
return {"wings": wings, "error": f"Partial result, failed at offset {offset}: {str(e)}"}
return {"wings": wings}
Option B — Metadata-only aggregation: If ChromaDB supports metadata-only queries without triggering HNSW, use that path instead of loading full records.
Additionally: Replace except Exception: pass with at minimum a logged warning, or return an "error" field in the response so callers know something went wrong (see Issue 2).
Labels:
bugDescription
When a palace contains a large number of drawers (~180k+), the MCP tools
mempalace_list_wings,mempalace_list_rooms, andmempalace_get_taxonomyall return empty{}results. The same issue affects thewingsandroomsfields inmempalace_status.Meanwhile,
mempalace_searchworks correctly and returns drawers with validwingandroommetadata.Root Cause
All three functions (and the wings/rooms portion of
tool_status) use the same pattern inmcp_server.py:Two problems:
col.get()without alimitattempts to load all records into memory at once. On large collections (180k+ drawers), this either triggers a ChromaDB HNSW internal error or causes excessive memory usage / timeout.except Exception: passsilently swallows the error, making it appear as if the palace simply has no wings/rooms, with no indication that an error occurred.Steps to Reproduce
mempalace mine ~/large-projectresulting in 100k+ drawers)mempalace_list_wingsvia MCP → returns{"wings": {}}mempalace_list_roomsvia MCP → returns{"wing": "all", "rooms": {}}mempalace_get_taxonomyvia MCP → returns{"taxonomy": {}}mempalace_statusvia MCP → returnstotal_drawers: 183895butwings: {}androoms: {}mempalace_searchwith any query → returns results with correctwingandroommetadataEnvironment
Observed Error (when running manually outside the try/except)
This error is completely hidden by the
except Exception: passin the current code.Suggested Fix
Option A — Pagination: Use
col.get()withlimitandoffsetto paginate through records in batches:Option B — Metadata-only aggregation: If ChromaDB supports metadata-only queries without triggering HNSW, use that path instead of loading full records.
Additionally: Replace
except Exception: passwith at minimum a logged warning, or return an"error"field in the response so callers know something went wrong (see Issue 2).