Skip to content

fix(sqlite_exact): cut remaining palace-wide read paths - #2311

Merged
igorls merged 1 commit into
developfrom
fix/sqlite-exact-hot-paths
Aug 19, 2026
Merged

fix(sqlite_exact): cut remaining palace-wide read paths#2311
igorls merged 1 commit into
developfrom
fix/sqlite-exact-hot-paths

Conversation

@igorls

@igorls igorls commented Aug 19, 2026

Copy link
Copy Markdown
Member

Follow-up to #2308. Search/status cosine and metadata paging are better; these were the next palace-wide reads on the live 167k-drawer sqlite_exact hub.

Does not touch chroma.py.

Changes

  1. get() no longer loads the whole palace

    • get(ids=...) uses WHERE id IN (...) (was: scan every row, then dict lookup).
    • include=["metadatas"] does not SELECT document or embedding.
    • Equality where (wing/room/source_file) plus LIMIT/OFFSET go to SQL.
  2. list_drawers paginates for real

    • Walk metadata only to collapse logical drawers and compute total.
    • Hydrate content_preview for the page via get(ids=...).
    • Live: unfiltered limit=20 was 2752 ms because it loaded every document.
  3. Taxonomy cache (5s TTL)

    • status / list_wings / list_rooms / get_taxonomy share one GROUP BY result.
    • Dropped on writes (_invalidate_overview_caches).
  4. graph_stats sqlite_exact fast path

    • Same reconstruction as chroma, from json_extract room/wing/hall GROUP BY.
    • First call was 1647 ms paging metadata.
  5. Closet boost is FTS, not a second cosine

    • Closets are pointer lines; BM25 is the better signal.
    • Avoids loading the 166k-closet embedding matrix on every search.

Isolated SQL on this palace (167k drawers)

Scan Time
id, document, metadata_json, embedding 806 ms
id, metadata_json 591 ms
LIMIT 20 / IN 20 0 ms
taxonomy GROUP BY 974 ms (then cached)

Tests

uv run pytest tests/test_sqlite_exact_backend.py tests/test_mcp_server.py tests/test_searcher.py tests/test_closets.py — 586 passed.

list_drawers(limit=20) still materialized every matching drawer
(documents + embeddings). get(ids=...) scanned the whole collection.
Search ran a second exact-cosine over 166k closets. Status/list_wings
re-ran the 1s json_extract GROUP BY on every call. graph_stats had no
sqlite_exact fast path and paged all metadata.

- get() selects only requested columns; get(ids=) uses IN; equality
  where + LIMIT go to SQL
- list_drawers walks metadata only, then hydrates the page
- 5s taxonomy cache, dropped on writes
- graph_stats uses json_extract GROUP BY on sqlite_exact
- closet boost uses FTS lexical_search instead of cosine

Isolated live palace (167k drawers): full-row fetch 806ms vs metadata
591ms vs LIMIT 20 / IN 20 at 0ms. Taxonomy GROUP BY ~1s, then cached.
@igorls
igorls requested a review from milla-jovovich as a code owner August 19, 2026 23:10
Copilot AI lite review requested due to automatic review settings August 19, 2026 23:10
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@igorls
igorls merged commit b9bff46 into develop Aug 19, 2026
9 checks passed
@igorls
igorls deleted the fix/sqlite-exact-hot-paths branch August 19, 2026 23:36
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