Repository navigation
fix(pipeline): leave the HNSW index alone when a run has nothing to write - #433
Merged
gero-robert merged 2 commits intoOct 9, 2026
Merged
gero-robert merged 2 commits into
gero-robert merged 2 commits into
Conversation
…rite The store thread dropped every HNSW index at the start of a run and rebuilt them at the end even when the incremental diff was empty, so re-indexing an unchanged checkout paid for a full index build and checkpoint. Skip the drop/rebuild bracket when there is no batch to write, no orphan to delete and no compaction due. open() already recreates an index a crashed run left missing, so recovery is unaffected. Compaction keeps the bracket because it rebuilds the indexes with the metrics the drop captures. The write-index progress phase still fires, as (1, 1) instead of (0, 1), so the progress bars resolve as before. Fixes chunkhound#431
3 tasks done
gero-robert
self-requested a review
October 8, 2026 16:44
gero-robert
requested changes
Oct 9, 2026
A run that skipped the bracket no longer asks needs_compaction() a second time after the write loop: compaction rebuilds the indexes from the metrics the drop captured, so it only belongs to a run that dropped them. The disk-limit log no longer says the indexes are rebuilt when they were left in place. Add a contract test for a non-incremental second run over unchanged files, which still writes and must keep the bracket.
gero-robert
approved these changes
Oct 9, 2026
gero-robert
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for the follow-up. The three notes on the diff are in 4652553:
- bug (log): the disk-limit message on the skip path says the existing indexes were left in place.
- The post-write compaction check reuses the skip decision.
- The non-incremental contract test expects a rebuild.
I've marked those threads resolved.
The descriptions in pipeline_parse_embed_store, src/AGENTS.md, and the write-index comment still say the store thread always rebuilds the index. Approving with that left as it is.
huangyingting
pushed a commit
to repomesh/chunkhound
that referenced
this pull request
Oct 14, 2026
Three descriptions still said the store thread always rebuilds the HNSW indexes after the final batch. Since chunkhound#433 a run with nothing to write, delete or compact leaves them in place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #431.
Why
Re-indexing an unchanged checkout still dropped every HNSW index at the start of the store thread and rebuilt them at the end. The diff already says there is nothing to write, so that is a full index build and checkpoint for no change (17 s of a 20.7 s run in the issue's measurement).
What changes
The store thread now skips the
drop_all_hnsw_indexes()/ensure_all_hnsw_indexes()bracket when all three hold:batch_count == 0)delete_pathsis empty)needs_compaction()is false)The decision lives in a small helper,
can_skip_hnsw_bracket, so it can be unit-tested with the existingFakeBackend.Three things I checked before skipping anything:
open()already callsensure_all_hnsw_indexes(), so an index a killed run left missing is recreated before the store thread reaches this point. Covered by a test that drops the index out-of-band and then runs an empty incremental index.run_compaction()rebuilds the indexes throughreopen()usingsaved_hnsw_metrics, which onlydrop_all_hnsw_indexes()fills. Skipping the drop on an empty-but-compacting run would rebuild a non-cosine index as cosine, so that case takes the old path.needs_compaction()is asked right afteropen(); nothing is written before the post-write check, so both calls give the same answer.rust_pipeline_runner.pyresolves the index and compact bars whenwrite-indexorwrite-compactfires, sowrite-indexis still emitted. It arrives as(1, 1)when the indexes were left in place and as(0, 1)when they are about to be rebuilt; the phase doc comment says so. The Python handler ignores those two numbers today, so nothing else changes.Tests
tests/contracts/test_hnsw_kept_on_empty_diff.py(Rust pipeline, mock embeddings, real DuckDB):write-indexis(1, 1), index and row counts unchangedwrite-indexis(0, 1), index presentwrite-indexis(0, 1), index presentwrite-compactfires,write-indexdoes not, index presentOn
mainthe first and last cases fail and the three controls pass; with this change all five pass. I use the progress tuple as the probe because nothing in DuckDB distinguishes a rebuilt index from the one it replaced (duckdb_indexes().index_oidsurvives a drop and recreate), and the[hnsw-drop]log line is not reliable to capture because pyo3-log caches logger levels per process.Four unit tests in
pipeline.rscover the decision itself, including that a failing compaction check still closes the backend.Run on Windows 11, Python 3.14, extension built from this branch:
cargo fmt --check,cargo clippy --all-targets -- -D warnings: cleancargo test: 135 passedruff check/ruff format --checkon the new test file: cleanpytest tests/test_smoke.py: 14 passedpytest tests/contracts: 108 passed, 4 skipped, 1 failed (test_symlink_preserves_logical_path, which needs a Windows symlink privilege my account lacks:WinError 1314)pytest tests/ -n 4: 4984 passed, 128 skipped, 23 failed, 65 errors. The 65 errors aretests/site, which need the site build I did not do. The 23 failures are that symlink test plus MCP/daemon/CLI start-up tests timing out under parallel load on this machine;tests/test_daemon_smoke.pyandtests/test_smoke.pypass when run on their own.Not measured: I did not reproduce the issue's 17 s figure on a large real index. The tests show the rebuild no longer happens; the time saved follows from that.