Skip to content

feat: add vchordrq vector index support for PostgreSQL#2378

Merged
danielaskdd merged 2 commits intoHKUDS:mainfrom
wmsnp:feature/postgres-vchordrq-indexes
Nov 18, 2025
Merged

feat: add vchordrq vector index support for PostgreSQL#2378
danielaskdd merged 2 commits intoHKUDS:mainfrom
wmsnp:feature/postgres-vchordrq-indexes

Conversation

@wmsnp
Copy link
Contributor

@wmsnp wmsnp commented Nov 18, 2025

Description

This PR refactors the vector index handling in postgres_impl and adds support for a new index type, vchordrq

Related Issues

#2377

Changes Made

  • Unified the vector index creation logic in postgres_impl.py by merging _create_hnsw_vector_indexes and _create_ivfflat_vector_indexes into a single _create_vector_indexes method.
  • Added VCHORDRQ as a new vector index method, along with three new configuration parameters: vchordrq_build_options, vchordrq_probes, and vchordrq_epsilon.
  • Updated env.example and config.ini.example to include the new VCHORDRQ-related settings and reflect the unified index creation workflow.

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

  • vchordrq requires the VectorChord plugin to be installed, which in turn depends on pgvector.
  • Using vchordrq as an alternative to pgvector for RAG vector storage is a potential option, but its advantages and performance characteristics have not been widely validated yet.

@danielaskdd
Copy link
Collaborator

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 415 to 420
async def configure_vchordrq(self, connection: asyncpg.Connection) -> None:
"""Configure VCHORDRQ extension for vector similarity search."""
try:
await connection.execute(f"SET vchordrq.probes TO '{self.vchordrq_probes}'")
await connection.execute(f"SET vchordrq.epsilon TO {self.vchordrq_epsilon}")
except Exception:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow epsilon to be configured when probes unset

The new configure_vchordrq wraps both SET statements in a single try and always tries to execute SET vchordrq.probes TO '' when POSTGRES_VCHORDRQ_PROBES is left empty (which is the default in both env.example and config.ini.example). That command fails with invalid value for parameter "vchordrq.probes", the exception is swallowed, and the method exits before the second SET runs, so vchordrq.epsilon (which defaults to 1.9 in the config) is never applied unless the user also supplies a valid probes value. This makes the documented epsilon setting impossible to use in the default configuration. Please skip issuing the probes SET when no value is provided or handle the two SETs independently so that a missing probes value does not block vchordrq.epsilon from being configured.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty string is actually accepted for 'vchordrq.probes', so the 'SET' statement itself shouldn’t fail. However, to make this more robust across environments, we could either wrap each 'SET' in its own try block or let exceptions propagate instead of swallowing them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should not catch exceptions. Configuration errors should fail-fast, while transient connection errors will be retried by _run_with_retry.

@danielaskdd danielaskdd merged commit b583b8a into HKUDS:main Nov 18, 2025
4 checks passed
@danielaskdd
Copy link
Collaborator

This PR has been merged with the updated configure_vchordrq. Please pull the latest code and verify that it functions as expected:

   async def configure_vchordrq(self, connection: asyncpg.Connection) -> None:
        """Configure VCHORDRQ extension for vector similarity search.

        Raises:
            asyncpg.exceptions.UndefinedObjectError: If VCHORDRQ extension is not installed
            asyncpg.exceptions.InvalidParameterValueError: If parameter value is invalid

        Note:
            This method does not catch exceptions. Configuration errors will fail-fast,
            while transient connection errors will be retried by _run_with_retry.
        """
        # Handle probes parameter - only set if non-empty value is provided
        if self.vchordrq_probes and str(self.vchordrq_probes).strip():
            await connection.execute(f"SET vchordrq.probes TO '{self.vchordrq_probes}'")
            logger.debug(f"PostgreSQL, VCHORDRQ probes set to: {self.vchordrq_probes}")

        # Handle epsilon parameter independently - check for None to allow 0.0 as valid value
        if self.vchordrq_epsilon is not None:
            await connection.execute(f"SET vchordrq.epsilon TO {self.vchordrq_epsilon}")
            logger.debug(
                f"PostgreSQL, VCHORDRQ epsilon set to: {self.vchordrq_epsilon}"
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants