FG
🤖 AI & LLMs

Support functions

Freshalmost 2 years ago
Mar 14, 20260 views
Confidence Score88%
88%

Problem

Currently, IvfflatGetType and HnswGetType functions do a syscache lookup to get the datatype, and then there is a bunch of code that do things like this based on the type: [code block] That's a bit of an unusual pattern in indexes, the usual pattern would be to have support function in the opclass to encapsulate any type-specific differences. To refactor this to use support functions, the minimal change to what's in 'master' would be to define one new support function, something like 'get_vector_type()', which returns a HnswType or IvfflatType. The HnswGetType()/IvfflatGetType() function would then just call the support function. Those if-statements would remain unchanged. A more proper way to use a support function would be to have support functions like 'hnsw_get_max_dimensions' and 'hnsw_check_value', to replace the places where we currently check the type (GetMaxDimensions and HnswCheckValue). A third approach would be to have just one support function like 'hnsw_type_support' that returns a struct like: [code block] That might be more handy than having a lot of support functions, and you get better type checking from the compiler as you don't need to convert all arguments to Datums. Ivfflat has "if (type == IVFFLAT_TYPE_VECTOR) ..." kind of checks, so it would need more support function, something like: [code block]

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: Support functions

Low Risk

Those IvfflatTypeSupport functions could be refactored into smaller functions, e.g. one for sorting used in both QuickCenters and CheckCenters

84

Trust Score

1 verification

100% success
  1. 1

    Those IvfflatTypeSupport functions could be refactored into smaller functions, e

    Those IvfflatTypeSupport functions could be refactored into smaller functions, e.g. one for sorting used in both QuickCenters and CheckCenters

Validation

Resolved in pgvector/pgvector GitHub issue #527. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

pgvectorembeddingsvector-search