Skip to content

fix: batch ChromaDB reads to avoid SQLite variable limit#66

Merged
bensig merged 1 commit intoMemPalace:mainfrom
MARUCIE:fix/sqlite-batch-reads
Apr 7, 2026
Merged

fix: batch ChromaDB reads to avoid SQLite variable limit#66
bensig merged 1 commit intoMemPalace:mainfrom
MARUCIE:fix/sqlite-batch-reads

Conversation

@MARUCIE
Copy link
Copy Markdown

@MARUCIE MARUCIE commented Apr 7, 2026

Summary

  • col.get() without limit generates SELECT ... WHERE id IN (...) with all document IDs
  • This exceeds SQLite's ~999 variable limit when a palace has more than ~1000 drawers
  • Breaks both mempalace compress and mempalace wake-up on large palaces

Reproduction

# Mine a large project (13880 files -> 242K+ drawers)
mempalace init ~/large-project --yes
echo "" | mempalace init ~/large-project --yes
mempalace mine ~/large-project

# These fail with "too many SQL variables"
mempalace compress --wing my_wing
mempalace wake-up --wing my_wing

Error: Error reading drawers: Error executing plan: Internal error: error returned from database: (code: 1) too many SQL variables

Fix

Paginate reads in batches of 500 using ChromaDB's offset/limit parameters in:

  • Layer1.generate() (layers.py)
  • cmd_compress() (cli.py)

Test plan

  • Verified fix on palace with 242K+ drawers (13880 files)
  • mempalace compress --wing 00_ai_fleet --dry-run completes successfully
  • mempalace wake-up --wing 00_ai_fleet returns ~851 tokens of context
  • mempalace search continues to work (unaffected by this change)

col.get() without limit generates SELECT ... WHERE id IN (...) with all
document IDs, which exceeds SQLite's ~999 variable limit when a palace
has more than ~1000 drawers.

This breaks both `mempalace compress` and `mempalace wake-up` on large
palaces. Reproduced on a 13880-file codebase (242K+ drawers).

Fix: paginate reads in batches of 500 using ChromaDB's offset/limit
parameters in both Layer1.generate() and cmd_compress().
GoodOlClint added a commit to GoodOlClint/mempalace that referenced this pull request Apr 7, 2026
Paginates col.get() in 500-item batches in compress and layers.
Prevents crash when palace exceeds SQLite's ~999 host parameter limit.

Upstream: MemPalace#66

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bensig bensig merged commit a59df81 into MemPalace:main Apr 7, 2026
@milla-jovovich milla-jovovich mentioned this pull request Apr 9, 2026
6 tasks
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.

2 participants