#ifndef DBMS_VECTOR_INDEX_MAP_INTERNAL_HPP #define DBMS_VECTOR_INDEX_MAP_INTERNAL_HPP /* * DBMS_VECTOR shared index mapping: Oracle CREATE_INDEX/REBUILD_INDEX * vocabulary (organization, idx_parameters type/keys, distance metric, * partitioning scheme) mapped onto the in-core vector access methods * (hnsw / ivfflat), their operator classes and reloptions, plus the * catalog resolution of an existing index to its access method. Consumed * by the index DDL / status / advisor entry points; no SQL surface of its * own. */ #include #include extern "C" { #include "postgres.h" #include "utils/jsonb.h" } // extern "C" /// Oracle index organizations (CREATE_INDEX, pls:571-576). #define DBMS_VECTOR_IDX_ORG_IVF "NEIGHBOR PARTITIONS" #define DBMS_VECTOR_IDX_ORG_HNSW "INMEMORY NEIGHBOR GRAPH" /* * One validated CREATE_INDEX parameter set mapped onto the rudb engine: * am is "hnsw" or "ivfflat", opclass is the vector operator class of the * metric for that access method, and the numeric idx_parameters keys keep * their Oracle names' values (0 = key absent, PG reloption defaults apply). */ struct DbmsVectorIndexMapping { std::string am; std::string opclass; int32_t m = 0; /* HNSW neighbors */ int32_t ef_construction = 0; /* HNSW efConstruction */ int32_t lists = 0; /* IVF partitions */ }; /* * Validate the Oracle parameter triple and produce the engine mapping: * organization must be NEIGHBOR PARTITIONS or INMEMORY NEIGHBOR GRAPH * (pls:571-576); idx_parameters must be a JSON object whose "type" is IVF * or HNSW with the per-type numeric keys (pls:628-652); the distance * metric must map onto an operator class of the chosen access method * (pls:584-589). Raises the Oracle parity errors otherwise. */ DbmsVectorIndexMapping dbms_vector_index_map( const char *idx_organization, const char *idx_distance_metric, Jsonb *idx_parameters); /* * Render the WITH (...) reloption list of a mapping ("m=16, * ef_construction=64" / "lists=100"); empty when no numeric key was given. */ std::string dbms_vector_index_reloptions_clause( const DbmsVectorIndexMapping &mapping); /* * Partitioning scheme check (Oracle accepts LOCAL and GLOBAL): RuDB has no * Oracle index partitioning, so only LOCAL (or NULL) is accepted and * GLOBAL is rejected with the parity error; anything else is rejected with * the Oracle invalid-option message (pls:582-586). */ void dbms_vector_index_check_partitioning(const char *idx_partitioning_scheme); /// One resolved vector index row of pg_index/pg_class. struct DbmsVectorIndexRef { Oid indexrelid = InvalidOid; Oid indrelid = InvalidOid; std::string am; /* hnsw | ivfflat */ bool indisvalid = false; std::vector reloptions; std::string table_name; /* table the index is built on */ std::string column_name; /* first key column (the vector column) */ std::string opclass; /* operator class of the key column */ }; /* * Resolve an (optionally schema-qualified) index name to its pg_index row * and access method. Returns false when the name does not resolve at all; * raises when the object is not an index or not a vector index * (hnsw/ivfflat). */ bool dbms_vector_index_lookup(const char *idx_name, DbmsVectorIndexRef &ref); #endif // DBMS_VECTOR_INDEX_MAP_INTERNAL_HPP