Bug
searcher.search(), searcher.search_memories(), and Layer3.search() all access results["documents"][0] without checking if the outer list is empty first.
When a query matches zero documents — e.g. a freshly initialized palace before any mining, or a wing/room filter that excludes everything — ChromaDB returns {"documents": [], ...} and the [0] indexing crashes with IndexError.
Affected locations
| File |
Function |
Line |
searcher.py |
search() |
~58 |
searcher.py |
search_memories() |
~132 |
layers.py |
Layer3.search() |
~289 |
Steps to reproduce
import chromadb
client = chromadb.PersistentClient(path="/tmp/test_palace")
col = client.get_or_create_collection("mempalace_drawers")
# Query an empty collection
results = col.query(query_texts=["test"], n_results=5, include=["documents", "metadatas", "distances"])
print(results["documents"]) # [] — empty list
print(results["documents"][0]) # IndexError: list index out of range
Expected behavior
Should return "No results found" gracefully instead of crashing.
Fix
Guard the outer list before indexing: if not results["documents"] or not results["documents"][0].
Bug
searcher.search(),searcher.search_memories(), andLayer3.search()all accessresults["documents"][0]without checking if the outer list is empty first.When a query matches zero documents — e.g. a freshly initialized palace before any mining, or a wing/room filter that excludes everything — ChromaDB returns
{"documents": [], ...}and the[0]indexing crashes withIndexError.Affected locations
searcher.pysearch()searcher.pysearch_memories()layers.pyLayer3.search()Steps to reproduce
Expected behavior
Should return "No results found" gracefully instead of crashing.
Fix
Guard the outer list before indexing:
if not results["documents"] or not results["documents"][0].