fix(hnsw): resolve segfault with parameterized queries (#141)#142
Merged
fix(hnsw): resolve segfault with parameterized queries (#141)#142
Conversation
This commit fixes a critical P0 bug where HNSW indexes on ruvector columns would crash PostgreSQL with a segmentation fault when using parameterized queries (prepared statements, ORMs, application drivers). Root Cause: - Query vector extraction failed for parameterized queries - Code fell back to zero vector without validation - Zero vector caused segfault during HNSW search Changes: - Add multi-method query vector extraction pipeline 1. Direct RuVector::from_polymorphic_datum() 2. Text parameter conversion for parameterized queries 3. Validated varlena fallback with dimension checking - Add query_valid flag to track extraction success - Add validation before search execution: - Reject empty/invalid query vectors with clear errors - Reject all-zero vectors (invalid for similarity search) - Validate dimension match between query and index - Apply same fixes to IVFFlat for consistency Testing: - Added regression tests for parameterized queries - Added tests for zero vector error handling - Added tests for dimension mismatch errors - Added 384-dimension production-scale tests Fixes: #141 See: docs/adr/ADR-0027-hnsw-parameterized-query-fix.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move datum and false arguments to same line in from_polymorphic_datum - Join split let text_len = ... assignment to single line These changes fix CI rustfmt check failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Run rustfmt on all Rust files to fix CI formatting checks. This addresses pre-existing formatting inconsistencies across: - cognitum-gate-kernel - cognitum-gate-tilezero - prime-radiant - ruvector-* crates - examples/benchmarks - and other crates Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ruvnet
added a commit
that referenced
this pull request
Feb 20, 2026
…ault-141 fix(hnsw): resolve segfault with parameterized queries (#141)
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.
Summary
This PR fixes a critical P0 bug where HNSW indexes crash PostgreSQL with segmentation faults when using parameterized queries (prepared statements, ORMs, application drivers).
Root Cause
The
hnsw_rescancallback only handled directruvectordatum extraction. Parameterized queries pass text representations that require conversion - this path was missing. When extraction failed, the code fell back to a zero vector which caused the segfault.Changes
hnsw_am.rsivfflat_am.rshnsw_index_tests.sqlADR-0027-*.mdTest Plan
Release
ruvector-postgres v2.0.1on crates.io ✅ruvnet/ruvector-postgres:2.0.1building 🔄Fixes #141
🤖 Generated with Claude Code