Support functions
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
Solution: Support functions
Those IvfflatTypeSupport functions could be refactored into smaller functions, e.g. one for sorting used in both QuickCenters and CheckCenters
Trust Score
1 verification
- 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
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep