fix: handle missing VectorChord embedding table in read/delete paths#538
Merged
philwinder merged 4 commits intomainfrom Apr 17, 2026
Merged
Conversation
The VectorChordEmbeddingStore creates its table lazily on the first SaveAll() call (to determine embedding dimension from actual data). However, Find(), DeleteBy(), Exists(), and Search() were called before SaveAll() and crashed with "relation does not exist" errors. Solution: On construction, probe pg_class to check table existence and set an atomic.Bool flag. Read/delete methods check this flag (lock-free atomic read) and return empty/no-op if the table doesn't exist yet. Once SaveAll() creates the table, it atomically flips the flag. This avoids adding database queries to the hot path while handling the initialization race condition safely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…able guard Tests three scenarios against a real VectorChord instance: - Missing table: Find/DeleteBy/Exists/Search return empty, no errors - SaveAll creates table: flag flips, subsequent operations work - Existing table: flag set at construction, operations work immediately Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ensures VectorChord embedding store tests are excluded from the normal unit test suite and only run with -tags integration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pure unit tests (no DB required) verifying that Find/DeleteBy/Exists/Search short-circuit and return empty when tableReady is false, and that the atomic flag transitions correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Go Test CoverageTotal coverage: 32.2% Full coverage report |
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
VectorChordEmbeddingStore creates its table lazily on the first
SaveAll()call (needs embedding dimension from actual data). ButFind(),DeleteBy(),Exists(), andSearch()can be called before that first write, hitting "relation does not exist" errors on production clusters that upgraded the kodit version.Solution
pg_classto check if table exists, set anatomic.BoolflagSaveAll()→ensureTable(): creates table, atomically flips the flagThis avoids adding database queries to every read/delete operation while properly handling the initialization race.
Changes
tableReady boolwithatomic.Boolfor lock-free readsFind(),DeleteBy(),Exists()to guard withtableReady.Load()Search()methodensureTable()to usetableReady.Store(true)Tested: builds, all tests pass.
🤖 Generated with Claude Code