Repository navigation
Add PgSVS as a new benchmarking client - #910
Conversation
- Enabled alpha parameter - Enabled compression_type, compression_primary, compression_secondary parameters - Enabled search_list_size parameter Signed-off-by: Olasoji <olasoji.denloye@intel.com>
- Renamed sarch_list_size parameter to search_window_size - Added leanvec_dims parameter Signed-off-by: Olasoji <olasoji.denloye@intel.com>
-Adds leanvec_dims and build_window_size params Signed-off-by: Olasoji <olasoji.denloye@intel.com>
Signed-off-by: Olasoji <olasoji.denloye@intel.com>
Signed-off-by: Olasoji <olasoji.denloye@intel.com>
Signed-off-by: Olasoji <olasoji.denloye@intel.com>
- updates GUC names Signed-off-by: Olasoji <olasoji.denloye@intel.com>
- pgvector.py: verify svs is pre-installed rather than attempting CREATE EXTENSION (superuser-only) - config.py: rename GUC vamana.search_window_size -> svs.search_window_size - config.py: move use_search_history from session GUC to index build option (build-time only per svs extension docs) - pyproject.toml: add setuptools_scm fallback_version for builds without .git
PgVectorSVS parsed --quantization-type/--table-quantization-type but never passed them to PgVectorSVSVamanaConfig, so the flags silently had no effect. Also reject quantization_type=bit (vamana has no bit opclass) and reranking/quantized_fetch_limit (not applicable to SVS, which reranks internally via compression_secondary) with a clean UsageError instead of a confusing downstream failure.
SVS options were documented as bare placeholders ("svs alpha", "svs
compression_type") with no mention of their actual encodings, ranges,
or defaults (e.g. alpha is alpha*100, compression_primary/secondary
are signed bit-width codes, several options use -1 as a sentinel).
Spell those out, matching the level of detail already used by other
engines for the same kind of encoded parameters (e.g. milvus, lancedb,
cockroachdb). Also rename --use_search_history/--skip-use_search_history
to --use-search-history/--skip-use-search-history for consistency with
every other hyphenated flag in this file.
SVS used to be built directly into pgvector; it's now a separate Postgres extension that merely depends on pgvector. Give it its own top-level engine package (DB.PgSVS, PgSVSConfig, PgSVSVamanaConfig, pgsvs CLI command), matching the existing pattern already used for other pgvector-dependent extensions (pgvectorscale, pgdiskann, pgvecto_rs), instead of special-casing it inside the shared PgVector client. Renames the CLI command from pgvectorsvs to pgsvs.
PgSVSVamanaConfig only validated quantization/reranking combos; graph_degree, alpha, build_window_size, search_window_size, compression_type/primary/secondary, and leanvec_dims were passed through unchecked and would only fail deep inside the SVS extension (or silently do the wrong thing). Add validators matching the real bounds/encodings from vamana.h and svs_wrapper.c's MapCompressionParamToSVSType, so bad input fails fast as a UsageError instead of a confusing CREATE INDEX error. Also fixes the search_window_size help text: unlike build_window_size, its reloption bound (vamana.c, VAMANA_MIN_SEARCH_WINDOW=10) does not actually accept a -1 sentinel, despite the extension's own reloption description string claiming "-1 = 100" -- the stated default (100) is reachable only via the compiled-in default, not a user-supplied -1.
Two breaks surfaced after rebasing onto upstream v2.0.0: - IndexType.SVS_VAMANA collided with an enum member of the same name that upstream independently added for Milvus's own native SVS/Vamana support (milvus/config.py's SVSVamanaConfig family) -- unrelated to this Postgres-based SVS integration, just a coincidental name clash. Renamed ours to PGSVS_VAMANA; the value stays "vamana" since that's the literal Postgres access method name the generated SQL needs. - Upstream migrated the whole project to pydantic v2 (model_validator) somewhere in the 86 commits since the v1.0.18 fork point, but PgSVSVamanaConfig's validators were still pydantic v1 syntax (validator/root_validator), inherited unchanged through the extract. Migrated to field_validator/model_validator with no behavior change -- same bounds, same error messages, verified against the same boundary-value checks used when these validators were first added.
insert_embeddings passed a raw numpy array as the halfvec column value to psycopg's COPY BINARY writer. pgvector-python's VectorDumper auto-wraps raw arrays/lists into its Vector class (and even registers numpy.ndarray directly as a dumper key), but HalfVectorDumper does neither -- it only accepts an already-constructed HalfVector instance, calling .to_binary() on whatever it's given. Passing a raw array surfaced as "'numpy.ndarray' object has no attribute 'to_binary'" as soon as table_quantization_type=halfvec actually tried to insert a row. Verified end-to-end against a live SVS-enabled Postgres: insert, index build, and search all succeed now for table_quantization_type=halfvec (table stores halfvec directly) and for table_quantization_type=none with quantization_type=halfvec (expression-indexed mismatch case).
pgsvs ships under the same pgvector extra but wasn't listed in README's install table alongside the other pg-family engines.
Match the existing PgVector/PgVectorScale/PgDiskANN/PgVectoRS pattern: add CaseConfigParamType members for the vamana-specific fields, build PgSVSLoadingConfig/PgSVSPerformanceConfig from widgets bounded to match PgSVSVamanaConfig's validators, and register DB.PgSVS in the case-config map and icon lookup. Reranking/quantized_fetch_limit/reranking_metric are omitted since SVS's reject_reranking validator always rejects them, and "bit" is omitted from the quantization-type options since vamana has no bit operator class.
…g lists build_window_size, search_window_size, and table_quantization_type had no default on PgSVSVamanaConfig, so instantiating it from either the Load- or Performance-labeled Streamlit UI config (which each only supply their own widget list's fields) raised a pydantic ValidationError and the run never started. Give them the same None default every other optional field has, and make PgSVSPerformanceConfig a strict superset of PgSVSLoadingConfig (plus search_window_size) to match the PgVector/PgDiskANN precedent.
PgSVS shares PgVector's single mutable self.conn/self.cursor design but never set thread_safe = False or overrode copy_for_thread() the way pgvector.py does. Under any concurrency benchmark, concurrent_runner.py's _get_thread_db() returned the DB object unmodified and every worker thread executed on the same shared connection concurrently.
- cli.py: drop --reranking/--reranking-metric/--quantized-fetch-limit -- PgSVSVamanaConfig.reject_reranking always rejects a truthy reranking or non-None quantized_fetch_limit, so these flags could never be used successfully; --reranking-metric was also never wired into the config constructor at all. Also drop "bit" from --quantization-type/ --table-quantization-type choices since vamana has no bit operator class. - config.py: use_search_history is a build-time-only reloption (confirmed against the SVS extension source -- no session GUC exists for it), and search_param()["use_search_history"] was never read anywhere in pgsvs.py. Remove it from PgSVSSearchParam/search_param() and document why. - pgvector/config.py: drop an unused use_search_history key that had leaked into PgVectorSearchParam -- PgVector never populates or reads it. - api.py: delete a dead commented-out CompressionType enum.
It was added in an earlier commit as "1.0.18" (the upstream tag this fork originally started from) to avoid failing builds without .git. Two rebases later it no longer describes this codebase, and upstream never had this key at all, so it shows up as an unexplained addition in the diff. Restores pyproject.toml to upstream's exact structure. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
PgSVSVamanaConfig.reject_bit_quantization rejects quantization_type/ table_quantization_type="bit" at construction time (vamana has no bit opclass), and the earlier reject_reranking validator always rejected a truthy reranking (svs reranks internally via compression_secondary). Both guarantees made several downstream branches permanently unreachable: the reranking/quantized_fetch_limit/reranking_metric fields themselves, the TypedDict keys and query-building branches that consumed them in pgsvs.py, the "bit" entries in parse_metric/ parse_metric_fun_op, and the table_quantization_type="bit" forcing line in index_param(). All inherited verbatim from pgvector.py's original copy-paste origin; none of it was ever reachable for svs. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
normalize_cosine (the --normalize-cosine flag, PgVectorHNSWConfig
field, _effective_metric_type helper, and need_normalize_cosine) was
added to pgvector's HNSW alongside the original SVS-inside-pgvector
integration, before SVS was extracted into its own package. It's not
part of what this PR is adding -- restore pgvector/{cli,config,
pgvector}.py to upstream's exact state and keep normalize_cosine only
on PgSVSVamanaConfig, where it's actually needed.
Signed-off-by: Olasoji <olasoji.denloye@intel.com>
result_20230727_standard_pgvector.json and result_20230808_standard_pgvector.json are upstream's own reference benchmark results, accidentally deleted in commit 6a2dd21 (a GUC rename/maintenance_work_mem fix unrelated to result data, most likely swept up by a broad commit alongside a local benchmark run) and silently carried through two later rebases since. Restored byte- identical to intel-staging/main; not part of what this PR is adding. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: asonje The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| "Extension 'svs' is not installed. Run 'CREATE EXTENSION svs;' as a PostgreSQL superuser first." | ||
| ) | ||
|
|
||
| log.info(f"{self.name} config values: {self.connect_config}\n{self.case_config}") |
There was a problem hiding this comment.
[P1] Keep the database password out of logs and exceptions. Thanks for adding the SVS backend. PgSVSConfig.to_dict() unwraps the password before building connect_config, so this INFO message logs it in plaintext on normal startup. The error at lines 76–81 includes the same dictionary. Could you omit the connection dictionary from both messages, or log only non-sensitive fields? A test with a dummy password can check both paths.
There was a problem hiding this comment.
Fixed. connect_config only logs host/port/dbname/user. The password or any sensitive data never reaches a log message or exception text
| assert self.cursor is not None, "Cursor is not initialized" | ||
| log.info(f"{self.name} client drop index : {self._index_name}") | ||
|
|
||
| drop_index_sql = sql.SQL("DROP INDEX IF EXISTS {index_name}").format( |
There was a problem hiding this comment.
[P1] Limit index cleanup to the benchmark table. _index_name is always pgvector_index, the same name used by the PgVector client. Changing the PgSVS table name doesn't change this DROP. In a shared schema, initializing or optimizing table B can therefore remove table A's index. Please skip the separate DROP when dropping the table, and verify the index belongs to the target table before replacing it during optimization. A two-table test would catch this.
There was a problem hiding this comment.
Fixed. The index name is now table-scoped ({table_name}_svs_index) instead of the (erroneous) hardcoded pgvector_index, so two tables in the same schema get distinct index names. I also removed the separate DROP INDEX call in the drop_old path.
| q = np.asarray(query) | ||
| result = self.cursor.execute( | ||
| self._search, | ||
| (q, k), |
There was a problem hiding this comment.
[P1] Check that the search window can return the requested K. Passing k as SQL LIMIT does not increase the number of candidates that the Vamana index scan requests. With a window of 100 and k=200, an unfiltered index scan can return at most 100 IDs, even when the table has enough rows. That makes the reported recall misleading. Please reject an explicitly undersized window before benchmarking, or raise the effective window to at least K and record the value actually used.
| log.error(msg) | ||
| raise RuntimeError(msg) | ||
|
|
||
| if drop_old: |
There was a problem hiding this comment.
[P1] Validate the existing index on search-only reuse. With drop_old=False, initialization checks that the extension exists, but never checks what index serves this table. A search-only run can report the requested Vamana settings even if the existing index uses a different graph degree or is a PgVector HNSW index. Before accepting reuse, please check the target column, access method, operator class and build options against the requested configuration. Fail with a clear mismatch instead of publishing a mislabeled result.
There was a problem hiding this comment.
Fixed. On drop_old=False, init now queries pg_index/pg_class/pg_am/pg_opclass/pg_attribute for the target index and compares access method, operator class, column type/dimension, and every build-time reloption against this run's config, raising a clear RuntimeError listing each mismatch before the run proceeds. None of the other Postgres-family clients check anything about the existing table/index on reuse.
| ), | ||
| ) | ||
| self.cursor.execute( | ||
| sql.SQL("ALTER USER {} SET maintenance_work_mem TO {};").format( |
There was a problem hiding this comment.
[P1] Keep build settings scoped to the benchmark session. The session-level SET above already configures this connection. The committed ALTER USER here and in the worker-settings branch also changes defaults for future logins using the same role. With the UI defaults, an ordinary run can leave unrelated sessions with an 8 GB maintenance memory setting and worker limits of 16. Please apply these settings on the index-build connection without changing the role. PostgreSQL role-setting semantics
| # 0 ("no residual") is only accepted for LVQ's residual slot, not LeanVec's secondary encoding | ||
| if secondary == 0 and self.compression_type == 2: | ||
| return self | ||
| if secondary not in (-8, -4, 4, 8): |
There was a problem hiding this comment.
[P2] Validate the compression widths as a pair before loading data. This validator accepts LeanVec (primary=8, secondary=4) and LVQ (-8, -8); both fall outside the extension's supported combinations. The latter is also the first choice in both UI dropdowns when LVQ is selected. With an index built after load, the user can finish inserting the whole dataset before finding out the configuration is invalid. Please validate the pair for the selected scheme in the model and offer compatible choices in the UI.
There was a problem hiding this comment.
Fixed. Added a model validator that checks (compression_primary, compression_secondary) against the supported pairs in SVS
#911) * Fix halfvec table storage insert: wrap arrays in pgvector's HalfVector pgvector-python's HalfVectorDumper has no special case for a raw numpy.ndarray (unlike VectorDumper, which does), so a bare np.float16(...) array passed into a column typed halfvec during a binary COPY fails with "'numpy.ndarray' object has no attribute 'to_binary'". Wrap it in pgvector.HalfVector(...) first, same fix already applied to pgsvs.py's identical code (PR #910). Add a regression test (test_insert_and_search_halfvec_table) mirroring the existing test_insert_and_search, with table_quantization_type set to halfvec. Verified against pgvector/pgvector:pg17 in Docker: fails with the exact error above on the pre-fix code, passes after. Signed-off-by: Olasoji <olasoji.denloye@intel.com> * Require pgvector>=0.4.0 for HalfVector's top-level export HalfVector moved to pgvector/__init__.py in 0.4.0; versions before that only expose it under submodules like pgvector.utils.halfvec, so `from pgvector import HalfVector` fails on anything older. Pin it in install/requirements_py3.11.txt and the pgvector/test extras, the only places that import HalfVector. Signed-off-by: Olasoji <olasoji.denloye@intel.com> --------- Signed-off-by: Olasoji <olasoji.denloye@intel.com>
Add an allow-list helper exposing only host/port/dbname/user, used at both log sites that previously printed connect_config verbatim.
self._index_name was the hardcoded literal "pgvector_index" across all PgSVS instances, so dropping or creating one table's index could silently affect another table's index of the same name. Derive it from the table name instead, and drop the now-redundant separate DROP INDEX before DROP TABLE, which already cascades. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
The vamana scan always fetches exactly search_window_size candidates regardless of SQL LIMIT, so k > search_window_size silently caps recall below what was requested. Only checked when explicitly set; unset behaves as before, deferring to svs's own internal default. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
ALTER USER SET for maintenance_work_mem and the parallel-worker GUCs changes the role's defaults for every future login, not just the current session. The existing session-scoped SET already covers what the index build needs.
svs only compiles a fixed set of (primary, secondary) pairs per scheme (LeanVec: abs(primary) <= abs(secondary); LVQ: an 8-bit primary needs secondary=0); check this at construction instead of per field, and reorder the UI dropdowns so the default (4, 8) is valid under both schemes instead of the previous (-8, -8).
On drop_old=False, check the existing index's access method, operator class, column type, and build-time reloptions against the current config before accepting reuse. Skips cleanly if no index exists yet. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
Covers config validation and bounds, the compression-pair rule, the 5 client-level fixes (password redaction, table-scoped index naming, search_window_size vs k, reused-index validation, no ALTER USER on the build settings), and general lifecycle behavior (thread safety, copy_for_thread, optimize ordering, filter prep, init guard). All tests mock the connection; none require a live database. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
CI's unpinned black resolved to 26.10.1, which reformats triple-quoted strings and blank lines around class definitions differently than the black version used locally when these files were written. Signed-off-by: Olasoji <olasoji.denloye@intel.com>
Summary
same pattern as pgvectorscale/pgdiskann/pgvecto_rs.
Streamlit UI configuration page (Load + Performance).
Supported Features
Index Types
compression_secondary
Quantization: none, halfvec (both index-level quantization_type and table-storage table_quantization_type) — bit is
intentionally not offered; vamana has no bit operator class
Compression: internal LeanVec/LVQ compression via compression_type/compression_primary/compression_secondary, independent of table/index quantization
Metrics: L2, IP, COSINE, with --normalize-cosine to fold cosine into an L2 index instead of relying on a cosine operator
class
PostgreSQL Tuning: maintenance_work_mem, max_parallel_workers, svs.search_window_size (session GUC)
CLI
vectordbbench pgsvs --help
References