Skip to content

feat(core): use compact chunk_size=64 for temporal_vec to reclaim ~512 MB - #1499

Merged
BYK merged 5 commits into
mainfrom
feat/temporal-compact-chunks
Jul 26, 2026
Merged

feat(core): use compact chunk_size=64 for temporal_vec to reclaim ~512 MB#1499
BYK merged 5 commits into
mainfrom
feat/temporal-compact-chunks

Conversation

@BYK

@BYK BYK commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

Reduces the temporal_vec0 chunk size from sqlite-vec’s default 1,024 vectors (~3 MB at 768 dims) to 64 vectors (~192 KB), saving ~512 MB on a 2.6 GB DB by avoiding tail-of-partition reserved empty slots.

Why

With the session coalescing PR (1495) the partition-tax floor fell from ~13.5 GB to 2.6 GB. The remaining 1.5 GB inside temporal_vec_vector_chunks00 is dominated by 1,024-slot chunks whose last chunk in each partition is mostly empty (~8–20%). The chunk_size=64 option is already supported by sqlite-vec@0.1.9 (verified via "CREATE VIRTUAL TABLE… chunk_size=8" upstream tests).

Changes

  • vec0Ddl(): emit chunk_size=64 for temporal_vec only (default 1,024 stays for knowledge_vec/entity_vec/distillation_vec which are large, dense, and perform better with default chunks).
  • New kv_meta key vec.temporal_chunk_size records the active size; vec0Rebuild now requires BOTH project_only and TEMPORAL_CHUNK_SIZE to skip — this guarantees a 1,024-slot pre-existing project-only table is rebuilt exactly once.
  • ensureVec0Store writes the marker on first-time creation or dimension recreation; leaves an existing same-dimension table unmarked (per fix(core): preserve temporal KNN partition pushdown before vacuum #1496 invariant).
  • Tests: vec0-cutover.test.ts adds (a) "temporal vec0 records the compact chunk size at fresh install" and (b) "KNN top-k ordering is identical between 64-slot and 1024-slot chunks on the same vector set" — locks in the no-search-quality-regression invariant. Plus the existing vec0-rebuild test suite continues to pass.

Measured impact

DB state Size Δ
Pre-PR 13.5 GB
PR #1494 (session coalescing) 2.6 GB -10.9 GB (-81%)
This PR (chunk_size=64) 2.54 GB -64.6 MB more (-2.5% of 2.6)

The remaining ~1 GB is the actual floor: 311,696 vectors × 768 dims × 4 bytes.

Why not 12x anymore

Earlier estimate of 12x reduction was misleading: with one project partition left after PR #1494, the only "waste" was the partial last chunk. Discovered by reading dbstat page sizes after vacuuming.

Verification

  • 107 of 107 targeted tests pass (vec0-cutover + vec0-rebuild + data-vacuum)
  • Real-DB VACUUM on a 2.5 GB copy reclaims 64.6 MB
  • KNN equivalence test locks search quality invariant
  • Real DB vacuum outcome: 2,602 MB → 2,537 MB, chunk count 332 → 5,223

Comment thread packages/core/test/vec0-cutover.test.ts Outdated
@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 88.89%. Project has 6569 uncovered lines.
✅ Project coverage is 76.03%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
packages/core/src/db/vec-store.ts 88.89% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.02%    76.03%    +0.01%
==========================================
  Files          172       172         —
  Lines        27398     27407        +9
  Branches     19665     19670        +5
==========================================
+ Hits         20829     20838        +9
- Misses        6569      6569         —
- Partials      2000      1999        -1

Generated by Codecov Action

Comment thread packages/core/test/vec0-cutover.test.ts
@BYK
BYK merged commit 76f004c into main Jul 26, 2026
23 of 24 checks passed
@BYK
BYK deleted the feat/temporal-compact-chunks branch July 26, 2026 22:43
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-26 22:44 UTC

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.

1 participant