Repository navigation
Stop queueing and failing sparse work while hybrid is off #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dpage
wants to merge
2
commits into
main
Choose a base branch
from
fix/issue-83-sparse-backfill
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Copyright (c) 2025 - 2026, pgEdge, Inc. | ||
| # | ||
| # Verify that sparse-only work is neither queued nor failed while | ||
| # pgedge_vectorizer.enable_hybrid is off. | ||
| # | ||
| # The 1.0 to 1.1 upgrade used to queue a sparse_only backfill item for every | ||
| # existing chunk regardless of the setting, and the worker raised an ERROR for | ||
| # each of them, so a database with many chunks filled its log for days before | ||
| # every item ran out of attempts. The upgrade is exercised from a real 1.0 | ||
| # install, once with hybrid off and once with it on, and the worker is then | ||
| # handed a sparse_only item with hybrid off and must complete it quietly. | ||
| # | ||
| # The provider is set to openai with no API key file, so it cannot be | ||
| # initialised. A sparse-only item needs no provider, so that must not stop the | ||
| # worker completing one. | ||
|
|
||
| use strict; | ||
| use warnings; | ||
|
|
||
| # See the comment in 001_worker_coverage.pl about loading these at compile time. | ||
| use PostgreSQL::Test::Cluster; | ||
| use PostgreSQL::Test::Utils; | ||
| use Test::More; | ||
|
|
||
| my $node = PostgreSQL::Test::Cluster->new('vectorizer_sparse_no_hybrid'); | ||
| $node->init; | ||
| $node->append_conf( | ||
| 'postgresql.conf', qq( | ||
| shared_preload_libraries = 'pgedge_vectorizer' | ||
| pgedge_vectorizer.worker_poll_interval = 200 | ||
| pgedge_vectorizer.batch_size = 1 | ||
| pgedge_vectorizer.provider = 'openai' | ||
| pgedge_vectorizer.enable_hybrid = false | ||
| max_worker_processes = 16 | ||
| )); | ||
|
|
||
| $node->start; | ||
|
|
||
| # Build a 1.0 vectorizer with embedded chunks, then upgrade it to 1.1 with | ||
| # enable_hybrid set as given, and return the number of sparse_only items the | ||
| # upgrade queued. No worker serves these databases, so nothing is consumed. | ||
| sub upgraded_sparse_items | ||
| { | ||
| my ($dbname, $hybrid) = @_; | ||
|
|
||
| $node->safe_psql('postgres', "CREATE DATABASE $dbname"); | ||
| $node->safe_psql($dbname, 'CREATE EXTENSION vector'); | ||
| $node->safe_psql($dbname, | ||
| "CREATE EXTENSION pgedge_vectorizer VERSION '1.0'"); | ||
| $node->safe_psql( | ||
| $dbname, q( | ||
| CREATE TABLE docs (id INT PRIMARY KEY, body TEXT); | ||
| SELECT pgedge_vectorizer.enable_vectorization('docs', 'body', | ||
| embedding_dimension => 3); | ||
| INSERT INTO docs VALUES (1, 'alpha beta'), (2, 'gamma delta'); | ||
| UPDATE docs_body_chunks SET embedding = '[1,2,3]'; | ||
| DELETE FROM pgedge_vectorizer.queue; | ||
| )); | ||
|
|
||
| return $node->safe_psql( | ||
| $dbname, qq( | ||
| SET pgedge_vectorizer.enable_hybrid = $hybrid; | ||
| ALTER EXTENSION pgedge_vectorizer UPDATE TO '1.1'; | ||
| SELECT count(*) FROM pgedge_vectorizer.queue | ||
| WHERE (metadata->>'sparse_only')::boolean; | ||
| )); | ||
| } | ||
|
|
||
| is(upgraded_sparse_items('upgrade_hybrid_off', 'off'), | ||
| '0', 'the 1.0 to 1.1 upgrade queues no sparse backfill with hybrid off'); | ||
|
|
||
| is(upgraded_sparse_items('upgrade_hybrid_on', 'on'), | ||
| '2', 'the 1.0 to 1.1 upgrade still queues the sparse backfill with hybrid on'); | ||
|
|
||
| # Now the worker: an item already queued, for example by an earlier upgrade, | ||
| # must be completed rather than failed while hybrid is off. | ||
| my $dbname = 'worker_hybrid_off'; | ||
|
|
||
| $node->safe_psql('postgres', "CREATE DATABASE $dbname"); | ||
| $node->safe_psql($dbname, 'CREATE EXTENSION vector'); | ||
| $node->safe_psql($dbname, 'CREATE EXTENSION pgedge_vectorizer'); | ||
| $node->safe_psql( | ||
| $dbname, q( | ||
| CREATE TABLE chunks ( | ||
| id BIGSERIAL PRIMARY KEY, | ||
| source_id BIGINT, | ||
| chunk_index INT, | ||
| content TEXT, | ||
| token_count INT, | ||
| embedding vector(3), | ||
| sparse_embedding sparsevec(65536) | ||
| ); | ||
| INSERT INTO chunks (source_id, chunk_index, content, token_count, embedding) | ||
| VALUES (1, 0, 'alpha', 1, '[1,2,3]'); | ||
| INSERT INTO pgedge_vectorizer.queue (chunk_id, chunk_table, content, status, metadata) | ||
| VALUES (1, 'chunks', 'alpha', 'pending', '{"sparse_only": true}'::jsonb); | ||
| )); | ||
|
|
||
| $node->append_conf('postgresql.conf', | ||
| "pgedge_vectorizer.databases = '$dbname'\n"); | ||
| $node->reload; | ||
|
|
||
| ok( $node->poll_query_until( | ||
| $dbname, | ||
| "SELECT status = 'completed' OR attempts > 0 FROM pgedge_vectorizer.queue WHERE chunk_id = 1" | ||
| ), | ||
| 'the worker picks up the sparse-only item'); | ||
|
|
||
| is( $node->safe_psql( | ||
| $dbname, | ||
| "SELECT status || ':' || attempts || ':' || coalesce(error_message, '') " | ||
| . "FROM pgedge_vectorizer.queue WHERE chunk_id = 1"), | ||
| 'completed:0:', | ||
| 'a sparse-only item is completed, not failed, while hybrid is off'); | ||
|
|
||
| is( $node->safe_psql( | ||
| $dbname, | ||
| 'SELECT sparse_embedding IS NULL AND embedding IS NOT NULL FROM chunks WHERE id = 1'), | ||
| 't', | ||
| 'the chunk keeps its dense embedding and gains no sparse one'); | ||
|
|
||
| $node->stop; | ||
| done_testing(); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.