feat(pgvector): support pgvector halfvec indexes#258
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds pgvector halfvec support in Metis’ PostgreSQL vector store to keep HNSW indexing available for high-dimensional embeddings (e.g., 3072), including config, runtime wiring, HNSW operator-class rewriting, and documentation.
Changes:
- Introduces
metis_engine.pgvector_use_halfvec(auto/true/false) with auto-enable behavior for largeembed_dim. - Passes
use_halfvecthrough PG backend construction and intoPGVectorStore.from_params, rewritinghnsw_dist_methodoperator classes when needed. - Updates tests and docs, and preserves
hnsw_kwargs: nullsemantics as “disable HNSW”.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_pg_backend_mocked_unit.py | Adds mocked tests for use_halfvec passthrough, HNSW dist method rewrite, and hnsw_kwargs=None preservation. |
| tests/test_configuration.py | Adds config parsing tests for pgvector_use_halfvec and auto behavior based on embed_dim. |
| src/metis/vector_store/pgvector_store.py | Adds halfvec operator-class rewrite logic and propagates use_halfvec to PGVectorStore. |
| src/metis/metis.yaml | Documents and defaults pgvector_use_halfvec: auto in packaged config. |
| src/metis/configuration.py | Adds pgvector_use_halfvec_setting and sets runtime pgvector_use_halfvec based on config + embed_dim. |
| src/metis/cli/utils.py | Plumbs runtime pgvector_use_halfvec into PG backend construction (PGVectorStoreImpl). |
| README.md | Documents automatic halfvec selection and override knob. |
| docs/providers/vllm.md | Documents pgvector_use_halfvec in provider config example. |
| docs/providers/gemini.md | Documents pgvector_use_halfvec and rationale for 3072-dim embeddings. |
| docs/providers/embedding-provider.md | Adds explanation of pgvector_use_halfvec behavior and overrides. |
| docs/providers/anthropic.md | Documents pgvector_use_halfvec and rationale for 3072-dim embeddings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
7376449 to
dad1e53
Compare
mpekatsoula
approved these changes
Jun 25, 2026
mk-arm
approved these changes
Jun 29, 2026
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
Adds PostgreSQL pgvector
halfvecsupport for Metis vector stores so large embedding dimensions, such as 3072-dimensional embeddings, can still use HNSW indexes.Root Cause
Metis already allows
metis_engine.embed_dim: 3072, but its PostgreSQL backend always created normalvectorstores and forwarded HNSW settings using normal vector operator classes such asvector_cosine_ops. pgvector normal-vector HNSW indexes cannot be created above the supported dimension limit, so large embeddings could fall back to unindexed vector search or log HNSW setup failures.Changes
metis_engine.pgvector_use_halfvecwithauto,true, andfalsebehavior.autoto halfvec forembed_dim > 2000and full-precision vector storage for smaller embeddings.use_halfvecthrough to both code and docsPGVectorStoreinstances.vector_*_opsto matchinghalfvec_*_opswhen halfvec is enabled.hnsw_kwargs: nullas disabled HNSW instead of converting it to an empty dict.metis.yaml.Validation
uv run --extra lint ruff format --check .uv run --extra lint ruff check .uv run pytestuv run --extra postgres pytest --postgres tests/test_pg_backend_real_integration.py tests/test_pg_backend_mocked_unit.pyuv run --extra postgres pytest --postgresThe full Postgres-enabled suite passed against a local
pgvector/pgvector:pg16container after creating the expectedmetis_userrole,metis_dbdatabase, andvectorextension.