Repository navigation
fix(compaction): preserve non-cosine HNSW metrics during auto-compaction rebuilds - #464
3431481073 wants to merge 3 commits into
Conversation
|
Summary: The fix is correct for the sampled auto-compaction success path, but it leaves the rollback path unfixed and adds a second metric-restore mechanism next to an existing one. I read the diff, the PR description, and the surrounding code in duckdb_provider.py. I did not run the new test, so the "fails before, passes after" claim is unverified. The checkout is main, which doesn't include the PR. Grouping
The groups share one file and depend on each other, so I reviewed them sequentially myself rather than launching parallel agents. The change is only ~60 lines. Strengths
Decision: REQUEST CHANGES. Fix the _compact_restore gap, and prefer reusing _executor_recreate_vector_index_from_info. |
_compact_copy_data now returns the source catalog's HNSW index records instead of a had_hnsw boolean, and _compact_finalize passes them to _executor_ensure_all_hnsw_indexes so each rebuilt canonical index keeps its per-table metric instead of a hardcoded cosine. _extract_hnsw_metric now logs a warning when pragma_hnsw_index_info() fails or returns no row, instead of silently defaulting to cosine. The non-cosine HNSW test now forces the sampled auto-compaction path deterministically (COMPACT_SAMPLE_INTERVAL=1 plus a forced fragmentation measure) and asserts the metric survives the rebuild. Refs chunkhound#456
Compaction finalize and rollback now share one restore path built on _executor_recreate_vector_index_from_info, so each discovered source index keeps its original name and metric. Previously finalize rebuilt canonical idx_hnsw_<dims> indexes with a hardcoded cosine metric, and rollback only received a had_hnsw boolean. Source metrics are validated before the file swap: an unsupported metric aborts compaction while the original DB is still intact. During compaction, a pragma_hnsw_index_info() failure now raises through strict extraction instead of silently defaulting to cosine; best-effort callers log at ERROR level and also write to stderr in MCP mode. Tests force sampled auto-compaction deterministically (zero threshold and sample interval 1) and cover the rollback exit and unknown-metric failure. Refs chunkhound#456
f91a453 to
33ccd52
Compare
|
Addressed the review in
|
|
CI is action_required because this is a fork PR. Could a maintainer approve the workflow run when convenient? The local compaction suite passes 133/133. |
The metric regression test forced sampled auto-compaction with COMPACT_SAMPLE_INTERVAL=1 and a zero fragmentation threshold, but the threshold check still required the environment-dependent fragmentation ratio to exceed 1.0. On CI runners the tiny DB measured <= 1.0, so the sample fired but compaction was skipped and "Compaction complete" was never logged (the same failure on ubuntu and windows shard 1). Call compact_database() directly instead: it bypasses sampling and the fragmentation heuristic, so the test deterministically exercises the compaction finalize path. Assert the positive compacted size, the "Compaction complete" log, the repo's not-larger contract, and that the non-cosine metric survives. The test still fails on main with cosine. Refs chunkhound#456
|
Fixed the CI failure in Root cause: the test forced sampling with The test now calls
|
|
The new run 41430234017 is action_required again after the test fix. Could a maintainer approve it? The local compaction suite passes 133/133, and the previously failing metric test now runs deterministically. |
|
@3431481073 I looked into the action_required thing. It seems like a policy in github for first time contributors. Hopefuly once this PR is pushed, you won't be expiriencing it again. |
|
@3431481073 tests are failing, could you please fix them so we can run review again? |
Sampled auto-compaction could silently rewrite any non-cosine HNSW index as
cosine. That changes search quality with no error and no log line.The cause is three small gaps in the DuckDB provider:
_compact_copy_datarecorded only ahad_hnswboolean, discarding the per-index metric the source catalog scan already returned._compact_finalizethen called_executor_ensure_all_hnsw_indexes, which created every canonical indexWITH (metric = 'cosine')._extract_hnsw_metricalso fell back tocosinesilently whenpragma_hnsw_index_info()raised.This carries the discovered source index records through compaction and reuses each table's metric when rebuilding, and makes metric extraction failures loud.
Fixes #456.
Changes
_compact_copy_datareturns the source catalog's HNSW index records (source_hnsw_indexes) instead ofhad_hnsw._compact_finalizepasses those records to_executor_ensure_all_hnsw_indexes, which maps table to metric and uses it inCREATE INDEX ... WITH (metric = ...)._extract_hnsw_metriclogs a warning with the index name and error when the pragma raises or returns no row, instead of defaulting silently.test_non_cosine_hnsw_metric_survives_index_rebuildnow forces the sampled auto-compaction path deterministically (COMPACT_SAMPLE_INTERVAL = 1, forced fragmentation measure) and asserts thel2sqmetric survives.Testing
assert 'cosine' == 'l2sq'.tests/test_duckdb_compaction.py: 131 passed.uv run pytest tests/test_smoke.py -v -n autocannot pass on this Windows host. The CLI subprocess harness decodeschunkhound search --helpoutput with the GBK locale codec and raisesUnicodeDecodeError, sostdoutis empty for the 8 CLI checks. The non-CLI smoke tests pass (6 passed). This is a host locale issue, not the compaction change; Linux CI should exercise the same test with UTF-8.What I could not verify
_extract_hnsw_metricstill falls back to cosine with a warning, rather than fail-closed.ensure_all_hnsw_indexes()path withoutsource_indexesstill defaults to cosine; out of scope for this issue.