/* <begin connected objects> */
/*
This file is auto generated by pgrx.

The ordering of items is not stable, it is driven by a dependency graph.
*/
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/lib.rs:88

DO $pgcontext_schema_guard$
DECLARE
    target_owner oid;
    delegated_create boolean;
BEGIN
    SELECT namespace.nspowner,
           EXISTS (
               SELECT 1
                 FROM pg_catalog.aclexplode(
                          coalesce(
                              namespace.nspacl,
                              pg_catalog.acldefault('n', namespace.nspowner)
                          )
                      ) AS privilege
                WHERE privilege.privilege_type = 'CREATE'
                  AND privilege.grantee <> namespace.nspowner
           )
      INTO target_owner, delegated_create
      FROM pg_catalog.pg_namespace AS namespace
     WHERE namespace.nspname = 'pgcontext';

    IF target_owner IS DISTINCT FROM CURRENT_USER::pg_catalog.regrole::oid THEN
        RAISE EXCEPTION 'pgcontext schema must be owned by the extension installer'
            USING ERRCODE = '42501';
    END IF;
    IF delegated_create THEN
        RAISE EXCEPTION 'pgcontext schema must not delegate CREATE privilege'
            USING ERRCODE = '42501';
    END IF;
END
$pgcontext_schema_guard$;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership_catalog.rs:7
-- requires:
--   pgcontext_bootstrap


CREATE TABLE pgcontext._pgvector_ownership_conversions (
    conversion_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    owner_role oid NOT NULL,
    source_table_oid oid NOT NULL,
    source_schema_name name NOT NULL,
    source_table_name name NOT NULL,
    source_column_name name NOT NULL,
    source_attnum int2 NOT NULL CHECK (source_attnum > 0),
    source_type_oid oid NOT NULL,
    source_type_name text NOT NULL CHECK (source_type_name <> ''),
    source_typmod int4 NOT NULL CHECK (source_typmod >= -1),
    shadow_column_name name NOT NULL,
    shadow_attnum int2 CHECK (shadow_attnum IS NULL OR shadow_attnum > 0),
    backup_column_name name NOT NULL,
    trigger_name name NOT NULL,
    index_name name NOT NULL,
    mode text NOT NULL CHECK (mode IN ('fast', 'restricted_online')),
    metric text NOT NULL CHECK (metric IN ('l2', 'inner_product', 'cosine', 'l1')),
    status text NOT NULL DEFAULT 'planned' CHECK (
        status IN (
            'planned',
            'backfilling',
            'index_pending',
            'ready',
            'cutover',
            'completed',
            'rolled_back',
            'failed'
        )
    ),
    dependency_manifest text[] NOT NULL DEFAULT ARRAY[]::text[],
    validation_attestations text[] NOT NULL DEFAULT ARRAY[]::text[],
    total_rows bigint NOT NULL DEFAULT 0 CHECK (total_rows >= 0),
    processed_rows bigint NOT NULL DEFAULT 0 CHECK (processed_rows >= 0),
    mismatch_count bigint NOT NULL DEFAULT 0 CHECK (mismatch_count >= 0),
    backfill_cursor text NOT NULL DEFAULT '(0,0)',
    source_checksum text,
    shadow_checksum text,
    error_message text,
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    started_at timestamptz,
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    completed_at timestamptz,
    CHECK (source_schema_name <> ''),
    CHECK (source_table_name <> ''),
    CHECK (source_column_name <> ''),
    CHECK (shadow_column_name <> backup_column_name),
    CHECK (trigger_name <> index_name),
    CHECK (processed_rows <= total_rows),
    CHECK (completed_at IS NULL OR status IN ('completed', 'rolled_back'))
);

CREATE UNIQUE INDEX pgcontext_pgvector_ownership_conversions_active_source
    ON pgcontext._pgvector_ownership_conversions (source_table_oid, source_attnum)
    WHERE status IN (
        'planned',
        'backfilling',
        'index_pending',
        'ready',
        'cutover',
        'failed'
    );

REVOKE ALL ON TABLE pgcontext._pgvector_ownership_conversions FROM PUBLIC;

CREATE VIEW pgcontext._visible_pgvector_ownership_conversions
WITH (security_barrier = true) AS
SELECT conversions.*
  FROM pgcontext._pgvector_ownership_conversions AS conversions
 WHERE pg_catalog.pg_has_role(SESSION_USER, conversions.owner_role, 'MEMBER');

GRANT SELECT ON pgcontext._visible_pgvector_ownership_conversions TO PUBLIC;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am/mapped_lifecycle.rs:38
-- requires:
--   pgcontext_bootstrap


CREATE FUNCTION pgcontext._mapped_hnsw_sql_drop()
RETURNS event_trigger
AS 'MODULE_PATHNAME', 'pgcontext_hnsw_mapped_sql_drop'
LANGUAGE C;

CREATE EVENT TRIGGER pgcontext_mapped_hnsw_sql_drop
    ON sql_drop
    EXECUTE FUNCTION pgcontext._mapped_hnsw_sql_drop();
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog_schema.rs:3
-- requires:
--   pgcontext_bootstrap


CREATE TABLE pgcontext._collections (
    collection_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_name text NOT NULL UNIQUE,
    owner_role oid NOT NULL,
    config_revision bigint NOT NULL DEFAULT 1 CHECK (config_revision > 0),
    source_table_oid oid,
    source_schema_name text,
    source_table_name text,
    strict_mode boolean NOT NULL DEFAULT false,
    max_dimensions int4 CHECK (max_dimensions IS NULL OR max_dimensions > 0),
    max_vectors int4 CHECK (max_vectors IS NULL OR max_vectors > 0),
    max_points bigint CHECK (max_points IS NULL OR max_points > 0),
    max_filter_nodes int4 CHECK (max_filter_nodes IS NULL OR max_filter_nodes > 0),
    max_search_limit int4 CHECK (max_search_limit IS NULL OR max_search_limit > 0),
    max_candidate_budget int4 CHECK (max_candidate_budget IS NULL OR max_candidate_budget > 0),
    query_timeout_ms int4 CHECK (query_timeout_ms IS NULL OR query_timeout_ms > 0),
    max_index_memory_bytes bigint CHECK (
        max_index_memory_bytes IS NULL OR max_index_memory_bytes > 0
    ),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(), updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    CHECK (
        (source_table_oid IS NULL AND source_schema_name IS NULL AND source_table_name IS NULL)
        OR
        (source_table_oid IS NOT NULL AND source_schema_name IS NOT NULL AND source_table_name IS NOT NULL)
    )
);

CREATE TABLE pgcontext._collection_vectors (
    vector_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    vector_name text NOT NULL,
    source_table_oid oid NOT NULL,
    source_schema_name text NOT NULL,
    source_table_name text NOT NULL,
    vector_column_name text NOT NULL,
    vector_attnum int2 NOT NULL,
    hnsw_index_oid oid,
    dimensions int4 NOT NULL CHECK (dimensions > 0),
    metric text NOT NULL CHECK (metric IN ('l2', 'inner_product', 'cosine', 'l1', 'hamming', 'jaccard')),
    hnsw_options jsonb NOT NULL DEFAULT '{}'::jsonb CHECK (pg_catalog.jsonb_typeof(hnsw_options) = 'object'),
    quantization_options jsonb NOT NULL DEFAULT '{}'::jsonb CHECK (pg_catalog.jsonb_typeof(quantization_options) = 'object'),
    status text NOT NULL DEFAULT 'ready' CHECK (status IN ('ready', 'building', 'disabled', 'failed')),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(), updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    UNIQUE (collection_id, vector_name),
    UNIQUE (collection_id, vector_column_name)
);

CREATE TABLE pgcontext._collection_sparse_vectors (
    sparse_vector_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    vector_name text NOT NULL,
    source_table_oid oid NOT NULL,
    source_schema_name text NOT NULL,
    source_table_name text NOT NULL,
    vector_column_name text NOT NULL,
    vector_attnum int2 NOT NULL,
    dimensions int4 NOT NULL CHECK (dimensions > 0),
    metric text NOT NULL CHECK (metric IN ('l2', 'inner_product', 'cosine', 'l1', 'hamming', 'jaccard')),
    storage_options jsonb NOT NULL DEFAULT '{}'::jsonb CHECK (pg_catalog.jsonb_typeof(storage_options) = 'object'),
    index_options jsonb NOT NULL DEFAULT '{}'::jsonb CHECK (pg_catalog.jsonb_typeof(index_options) = 'object'),
    status text NOT NULL DEFAULT 'ready' CHECK (status IN ('ready', 'building', 'disabled', 'failed')),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(), updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    UNIQUE (collection_id, vector_name),
    UNIQUE (collection_id, vector_column_name)
);

CREATE TABLE pgcontext._collection_points (
    point_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    source_key text NOT NULL,
    deleted_at timestamptz,
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    UNIQUE (collection_id, source_key)
);

CREATE TABLE pgcontext._collection_aliases (
    alias_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    alias_name text NOT NULL UNIQUE,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now()
);

CREATE TABLE pgcontext._collection_payload_columns (
    payload_column_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    filter_key text NOT NULL,
    source_table_oid oid NOT NULL,
    source_schema_name text NOT NULL,
    source_table_name text NOT NULL,
    column_name text NOT NULL,
    column_attnum int2 NOT NULL,
    jsonb_path text[],
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    UNIQUE (collection_id, filter_key),
    UNIQUE NULLS NOT DISTINCT (collection_id, column_name, jsonb_path)
);

CREATE TABLE pgcontext._query_stats (
    query_stat_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    cohort text NOT NULL CHECK (cohort <> ''),
    query_kind text NOT NULL CHECK (query_kind IN ('search', 'search_filtered', 'candidate_recheck', 'hybrid')),
    result_count bigint NOT NULL CHECK (result_count >= 0),
    candidate_count bigint CHECK (candidate_count IS NULL OR candidate_count >= 0),
    rows_rechecked bigint NOT NULL DEFAULT 0 CHECK (rows_rechecked >= 0),
    rows_pruned bigint NOT NULL DEFAULT 0 CHECK (rows_pruned >= 0),
    recall_threshold double precision CHECK (recall_threshold IS NULL OR (recall_threshold >= 0 AND recall_threshold <= 1)),
    recall_achieved double precision CHECK (recall_achieved IS NULL OR (recall_achieved >= 0 AND recall_achieved <= 1)),
    latency_bucket text NOT NULL DEFAULT 'Unspecified' CHECK (latency_bucket IN ('Lt1Ms', 'Lt10Ms', 'Lt100Ms', 'Lt1S', 'Gte1S', 'Unspecified')),
    lifecycle_state text NOT NULL DEFAULT 'Unspecified' CHECK (lifecycle_state IN ('Unspecified', 'Exact', 'Indexed', 'Fallback', 'IndexNotReady', 'IndexCorrupt', 'ArtifactMissing')),
    strategy text NOT NULL DEFAULT 'unspecified' CHECK (
        pg_catalog.octet_length(strategy) BETWEEN 1 AND 64
        AND strategy ~ '^[a-z0-9_]+$'
    ),
    visits bigint NOT NULL DEFAULT 0 CHECK (visits >= 0),
    filter_candidates bigint NOT NULL DEFAULT 0 CHECK (filter_candidates >= 0),
    candidates bigint NOT NULL DEFAULT 0 CHECK (candidates >= 0),
    rechecks bigint NOT NULL DEFAULT 0 CHECK (rechecks >= 0),
    stages bigint NOT NULL DEFAULT 0 CHECK (stages >= 0),
    expansions bigint NOT NULL DEFAULT 0 CHECK (expansions >= 0),
    completion text NOT NULL DEFAULT 'unspecified' CHECK (
        completion IN ('unspecified', 'complete', 'cancelled', 'budget_exhausted', 'error')
    ),
    latency_ms double precision NOT NULL CHECK (latency_ms >= 0),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now()
);

CREATE TABLE pgcontext._model_versions (
    model_version_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    model_name text NOT NULL CHECK (model_name <> ''),
    model_version text NOT NULL CHECK (model_version <> ''),
    dimensions int4 NOT NULL CHECK (dimensions > 0),
    metric text NOT NULL CHECK (metric IN ('l2', 'inner_product', 'cosine', 'l1', 'hamming', 'jaccard')),
    is_active boolean NOT NULL DEFAULT true,
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    UNIQUE (collection_id, model_name, model_version)
);

CREATE TABLE pgcontext._embedding_migrations (
    migration_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    source_model_version_id bigint NOT NULL REFERENCES pgcontext._model_versions(model_version_id),
    target_model_version_id bigint NOT NULL REFERENCES pgcontext._model_versions(model_version_id),
    status text NOT NULL CHECK (status IN ('planned', 'running', 'completed', 'failed')),
    total_points bigint NOT NULL CHECK (total_points >= 0),
    processed_points bigint NOT NULL DEFAULT 0 CHECK (processed_points >= 0),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    CHECK (processed_points <= total_points),
    CHECK (source_model_version_id <> target_model_version_id)
);

CREATE TABLE pgcontext._build_jobs (
    build_job_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    artifact_kind text NOT NULL CHECK (artifact_kind IN ('index', 'segment', 'sparse_index', 'mmap')),
    artifact_name text NOT NULL CHECK (artifact_name <> ''),
    target_name text NOT NULL CHECK (target_name <> ''),
    status text NOT NULL CHECK (
        status IN ('planned', 'running', 'cancel_requested', 'cancelled', 'completed', 'failed', 'abandoned')
    ),
    backend_pid int4,
    backend_identity text,
    attempt int4 NOT NULL DEFAULT 1 CHECK (attempt > 0),
    total_units bigint NOT NULL CHECK (total_units >= 0),
    processed_units bigint NOT NULL DEFAULT 0 CHECK (processed_units >= 0),
    last_source_point_id bigint NOT NULL DEFAULT 0 CHECK (last_source_point_id >= 0),
    config_revision bigint,
    cancel_requested boolean NOT NULL DEFAULT false,
    error_message text,
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    completed_at timestamptz,
    CHECK (processed_units <= total_units)
);

CREATE FUNCTION pgcontext._reject_build_job_progress_regression()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
    IF NEW.processed_units < OLD.processed_units THEN
        RAISE EXCEPTION 'build job progress cannot go backwards: % < %',
            NEW.processed_units,
            OLD.processed_units
            USING ERRCODE = '22023';
    END IF;
    RETURN NEW;
END;
$$;

CREATE TRIGGER pgcontext_build_jobs_no_progress_regression
BEFORE UPDATE OF processed_units ON pgcontext._build_jobs
FOR EACH ROW
EXECUTE FUNCTION pgcontext._reject_build_job_progress_regression();

CREATE FUNCTION pgcontext._enforce_build_job_terminal_state()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
    IF NEW.status IN ('running', 'cancel_requested') THEN
        IF NEW.backend_pid IS NULL THEN
            RAISE EXCEPTION 'active build job % must record backend_pid',
                NEW.status
                USING ERRCODE = '22023';
        END IF;
        IF NEW.backend_identity IS NULL THEN
            RAISE EXCEPTION 'active build job % must record backend_identity',
                NEW.status
                USING ERRCODE = '22023';
        END IF;
        IF NEW.completed_at IS NOT NULL THEN
            RAISE EXCEPTION 'active build job % cannot retain completed_at',
                NEW.status
                USING ERRCODE = '22023';
        END IF;
    END IF;
    IF NEW.status IN ('completed', 'failed', 'cancelled', 'abandoned') THEN
        IF NEW.backend_pid IS NOT NULL OR NEW.backend_identity IS NOT NULL THEN
            RAISE EXCEPTION 'terminal build job % cannot retain backend ownership',
                NEW.status
                USING ERRCODE = '22023';
        END IF;
        IF NEW.completed_at IS NULL THEN
            RAISE EXCEPTION 'terminal build job % must record completed_at',
                NEW.status
                USING ERRCODE = '22023';
        END IF;
    END IF;
    IF NEW.status = 'completed' AND NEW.processed_units <> NEW.total_units THEN
        RAISE EXCEPTION 'completed build job progress must equal total: % <> %',
            NEW.processed_units,
            NEW.total_units
            USING ERRCODE = '22023';
    END IF;
    RETURN NEW;
END;
$$;

CREATE TRIGGER pgcontext_build_jobs_terminal_state
BEFORE INSERT OR UPDATE OF status, backend_pid, backend_identity, completed_at, processed_units, total_units
ON pgcontext._build_jobs
FOR EACH ROW
EXECUTE FUNCTION pgcontext._enforce_build_job_terminal_state();

CREATE UNIQUE INDEX pgcontext_build_jobs_one_active_target
    ON pgcontext._build_jobs (collection_id, artifact_kind, artifact_name, target_name)
 WHERE status IN ('planned', 'running', 'cancel_requested');

CREATE TABLE pgcontext._build_deltas (
    delta_sequence bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    build_job_id bigint NOT NULL REFERENCES pgcontext._build_jobs(build_job_id) ON DELETE CASCADE,
    point_id bigint NOT NULL REFERENCES pgcontext._collection_points(point_id) ON DELETE CASCADE,
    operation text NOT NULL CHECK (operation IN ('upsert', 'delete')),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    UNIQUE (build_job_id, point_id, delta_sequence)
);

CREATE FUNCTION pgcontext._capture_build_point_delta()
RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
    delta_operation text;
BEGIN
    delta_operation := CASE WHEN NEW.deleted_at IS NULL THEN 'upsert' ELSE 'delete' END;
    INSERT INTO pgcontext._build_deltas (build_job_id, point_id, operation)
    SELECT jobs.build_job_id, NEW.point_id, delta_operation
      FROM pgcontext._build_jobs AS jobs
     WHERE jobs.collection_id = NEW.collection_id
       AND jobs.status IN ('running', 'cancel_requested');
    RETURN NEW;
END;
$$;

CREATE TRIGGER pgcontext_capture_build_point_delta
AFTER INSERT OR UPDATE OF deleted_at ON pgcontext._collection_points
FOR EACH ROW
EXECUTE FUNCTION pgcontext._capture_build_point_delta();

CREATE TABLE pgcontext._artifact_segments (
    artifact_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    build_job_id bigint NOT NULL REFERENCES pgcontext._build_jobs(build_job_id) ON DELETE RESTRICT,
    artifact_kind text NOT NULL CHECK (artifact_kind IN ('segment', 'mmap')),
    artifact_name text NOT NULL CHECK (artifact_name <> ''),
    target_name text NOT NULL CHECK (target_name <> ''),
    generation bigint NOT NULL CHECK (generation > 0),
    segment_kind text NOT NULL CHECK (segment_kind IN ('hnsw_graph')),
    format_version int4 NOT NULL CHECK (format_version = 1),
    payload_bytes bigint NOT NULL CHECK (payload_bytes >= 0),
    checksum bigint NOT NULL,
    config_revision bigint,
    relative_path text,
    lifecycle_state text NOT NULL DEFAULT 'validated' CHECK (lifecycle_state IN ('validated', 'file_materialized', 'rebuild_required', 'retired')),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    CHECK (lifecycle_state <> 'file_materialized' OR relative_path IS NOT NULL),
    UNIQUE (collection_id, artifact_kind, artifact_name, target_name, generation)
);

CREATE FUNCTION pgcontext.current_vector_config_revision(collection bigint)
RETURNS bigint
LANGUAGE sql
STABLE
AS $$
    SELECT config_revision
      FROM pgcontext._collections
     WHERE collection_id = $1
$$;

CREATE TABLE pgcontext._artifact_reader_pins (
    artifact_id bigint NOT NULL REFERENCES pgcontext._artifact_segments(artifact_id) ON DELETE CASCADE,
    backend_pid int4 NOT NULL,
    backend_identity text NOT NULL,
    pin_count int4 NOT NULL CHECK (pin_count > 0),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    PRIMARY KEY (artifact_id, backend_pid, backend_identity)
);

-- Intentionally unfiltered pre-authorization lookup. Callers need this minimal
-- collection/alias name, owner-role, and source-binding summary to resolve a
-- collection before checking membership. It must not expose source-table
-- identity, source keys, vectors, payload metadata, or operational state.
CREATE VIEW pgcontext._collection_acl AS
SELECT collection_id,
       collection_name,
       owner_role,
       source_table_oid IS NOT NULL AS has_source_table
  FROM pgcontext._collections
UNION ALL
SELECT collections.collection_id,
       aliases.alias_name AS collection_name,
       collections.owner_role,
       collections.source_table_oid IS NOT NULL AS has_source_table
  FROM pgcontext._collection_aliases AS aliases
  JOIN pgcontext._collections AS collections USING (collection_id);

CREATE VIEW pgcontext._visible_collection_vectors
WITH (security_barrier = true) AS
SELECT vectors.*
  FROM pgcontext._collection_vectors AS vectors
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_collection_sparse_vectors
WITH (security_barrier = true) AS
SELECT vectors.*
  FROM pgcontext._collection_sparse_vectors AS vectors
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_collection_points
WITH (security_barrier = true) AS
SELECT points.*
  FROM pgcontext._collection_points AS points
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_query_stats
WITH (security_barrier = true) AS
SELECT stats.*
  FROM pgcontext._query_stats AS stats
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_collection_payload_columns
WITH (security_barrier = true) AS
SELECT payload_columns.*
  FROM pgcontext._collection_payload_columns AS payload_columns
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_build_jobs
WITH (security_barrier = true) AS
SELECT jobs.*
  FROM pgcontext._build_jobs AS jobs
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_artifact_segments
WITH (security_barrier = true) AS
SELECT artifacts.*,
       collections.collection_name
  FROM pgcontext._artifact_segments AS artifacts
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_collection_limits
WITH (security_barrier = true) AS
SELECT collection_id,
       strict_mode,
       max_dimensions,
       max_vectors,
       max_points,
       max_filter_nodes,
       max_search_limit,
       max_candidate_budget,
       query_timeout_ms,
       max_index_memory_bytes
  FROM pgcontext._collections
 WHERE pg_catalog.pg_has_role(SESSION_USER, owner_role, 'MEMBER');

CREATE VIEW pgcontext._visible_collections
WITH (security_barrier = true) AS
SELECT collection_id,
       collection_name,
       owner_role,
       source_table_oid,
       source_schema_name,
       source_table_name
  FROM pgcontext._collections
 WHERE pg_catalog.pg_has_role(SESSION_USER, owner_role, 'MEMBER');

GRANT SELECT ON pgcontext._collection_acl TO PUBLIC;
GRANT SELECT ON pgcontext._visible_collection_vectors TO PUBLIC;
GRANT SELECT ON pgcontext._visible_collection_sparse_vectors TO PUBLIC;
GRANT SELECT ON pgcontext._visible_collection_points TO PUBLIC;
GRANT SELECT ON pgcontext._visible_query_stats TO PUBLIC;
GRANT SELECT ON pgcontext._visible_collection_payload_columns TO PUBLIC;
GRANT SELECT ON pgcontext._visible_build_jobs TO PUBLIC;
GRANT SELECT ON pgcontext._visible_artifact_segments TO PUBLIC;
GRANT SELECT ON pgcontext._visible_collection_limits TO PUBLIC;
GRANT SELECT ON pgcontext._visible_collections TO PUBLIC;

-- Drift self-healing writes. Retrieval functions run SECURITY INVOKER so that
-- source-table SELECT/RLS is enforced against the caller, which means a
-- non-superuser collection member holds no direct privilege on the private
-- catalog tables. When a dump/restore or table rewrite changes a source
-- table's oid, the query path detects the drift and refreshes the stored
-- metadata through these SECURITY DEFINER helpers so the write succeeds as the
-- extension owner.
--
-- Security: these helpers accept only identifying keys, never a caller-supplied
-- oid or attnum. Each re-derives the authoritative oid/attnum from pg_catalog
-- using the schema, table, and column names already stored in the private
-- catalog, so a call can only ever set the true current binding of the
-- already-registered source table. This is deliberate: accepting an oid would
-- let a collection member repoint _collections.source_table_oid at an unrelated
-- table they control, and the SECURITY DEFINER payload/backfill paths check
-- privileges by that oid while mutating the real table by name -- a
-- confused-deputy escalation. Each helper also re-checks owner-role membership
-- on SESSION_USER (defence in depth for direct calls) and pins search_path.
CREATE FUNCTION pgcontext._refresh_collection_source_table(
    p_collection_id bigint
)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
          FROM pgcontext._collections
         WHERE collection_id = p_collection_id
           AND pg_catalog.pg_has_role(SESSION_USER, owner_role, 'MEMBER')
    ) THEN
        RAISE EXCEPTION 'permission denied to refresh collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;

    UPDATE pgcontext._collections AS collections
       SET source_table_oid = source_class.oid,
           updated_at = pg_catalog.now()
      FROM pg_catalog.pg_class AS source_class
      JOIN pg_catalog.pg_namespace AS source_namespace
        ON source_namespace.oid = source_class.relnamespace
     WHERE collections.collection_id = p_collection_id
       AND source_namespace.nspname = collections.source_schema_name
       AND source_class.relname = collections.source_table_name
       AND source_class.relkind IN ('r', 'p');
END;
$$;

CREATE FUNCTION pgcontext._refresh_vector_source_binding(
    p_collection_id bigint,
    p_vector_column_name text
)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
          FROM pgcontext._collections
         WHERE collection_id = p_collection_id
           AND pg_catalog.pg_has_role(SESSION_USER, owner_role, 'MEMBER')
    ) THEN
        RAISE EXCEPTION 'permission denied to refresh collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;

    UPDATE pgcontext._collection_vectors AS vectors
       SET source_table_oid = source_class.oid,
           vector_attnum = source_attribute.attnum,
           updated_at = pg_catalog.now()
      FROM pg_catalog.pg_class AS source_class
      JOIN pg_catalog.pg_namespace AS source_namespace
        ON source_namespace.oid = source_class.relnamespace
      JOIN pg_catalog.pg_attribute AS source_attribute
        ON source_attribute.attrelid = source_class.oid
     WHERE vectors.collection_id = p_collection_id
       AND vectors.vector_column_name = p_vector_column_name
       AND source_namespace.nspname = vectors.source_schema_name
       AND source_class.relname = vectors.source_table_name
       AND source_class.relkind IN ('r', 'p')
       AND source_attribute.attname = vectors.vector_column_name
       AND source_attribute.attnum > 0
       AND NOT source_attribute.attisdropped;
END;
$$;

CREATE FUNCTION pgcontext._refresh_sparse_vector_source_binding(
    p_collection_id bigint,
    p_vector_name text
)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
          FROM pgcontext._collections
         WHERE collection_id = p_collection_id
           AND pg_catalog.pg_has_role(SESSION_USER, owner_role, 'MEMBER')
    ) THEN
        RAISE EXCEPTION 'permission denied to refresh collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;

    UPDATE pgcontext._collection_sparse_vectors AS sparse_vectors
       SET source_table_oid = source_class.oid,
           vector_attnum = source_attribute.attnum,
           updated_at = pg_catalog.now()
      FROM pg_catalog.pg_class AS source_class
      JOIN pg_catalog.pg_namespace AS source_namespace
        ON source_namespace.oid = source_class.relnamespace
      JOIN pg_catalog.pg_attribute AS source_attribute
        ON source_attribute.attrelid = source_class.oid
     WHERE sparse_vectors.collection_id = p_collection_id
       AND sparse_vectors.vector_name = p_vector_name
       AND source_namespace.nspname = sparse_vectors.source_schema_name
       AND source_class.relname = sparse_vectors.source_table_name
       AND source_class.relkind IN ('r', 'p')
       AND source_attribute.attname = sparse_vectors.vector_column_name
       AND source_attribute.attnum > 0
       AND NOT source_attribute.attisdropped;
END;
$$;

CREATE FUNCTION pgcontext._refresh_payload_source_bindings(
    p_collection_id bigint
)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
          FROM pgcontext._collections
         WHERE collection_id = p_collection_id
           AND pg_catalog.pg_has_role(SESSION_USER, owner_role, 'MEMBER')
    ) THEN
        RAISE EXCEPTION 'permission denied to refresh collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;

    UPDATE pgcontext._collection_payload_columns AS payload_columns
       SET source_table_oid = source_class.oid,
           column_attnum = source_attribute.attnum,
           updated_at = pg_catalog.now()
      FROM pg_catalog.pg_class AS source_class
      JOIN pg_catalog.pg_namespace AS source_namespace
        ON source_namespace.oid = source_class.relnamespace
      JOIN pg_catalog.pg_attribute AS source_attribute
        ON source_attribute.attrelid = source_class.oid
     WHERE payload_columns.collection_id = p_collection_id
       AND source_namespace.nspname = payload_columns.source_schema_name
       AND source_class.relname = payload_columns.source_table_name
       AND source_class.relkind IN ('r', 'p')
       AND source_attribute.attname = payload_columns.column_name
       AND source_attribute.attnum > 0
       AND NOT source_attribute.attisdropped;
END;
$$;

SELECT pg_catalog.pg_extension_config_dump('pgcontext._collections', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._collection_vectors', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._collection_sparse_vectors', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._collection_points', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._collection_aliases', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._collection_payload_columns', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._query_stats', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._model_versions', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._embedding_migrations', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._build_jobs', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._build_deltas', '');
SELECT pg_catalog.pg_extension_config_dump('pgcontext._artifact_segments', '');
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:4
-- BuildJobStatus
CREATE TYPE BuildJobStatus AS ENUM (
	'Planned',
	'Running',
	'CancelRequested',
	'Cancelled',
	'Completed',
	'Failed',
	'Abandoned'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:23
-- EmbeddingMigrationStatus
CREATE TYPE EmbeddingMigrationStatus AS ENUM (
	'Planned',
	'Running',
	'Completed',
	'Failed'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:162
-- IndexAdvisorRecommendation
CREATE TYPE IndexAdvisorRecommendation AS ENUM (
	'NoAction',
	'CreateBtreeIndex',
	'CreateGinIndex',
	'AnalyzeTable',
	'AvoidCandidateMaterialization',
	'TuneHnswSettings'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:101
-- IndexDiagnosticStatus
CREATE TYPE IndexDiagnosticStatus AS ENUM (
	'Ready',
	'IndexNotReady',
	'IndexCorrupt',
	'UnsupportedAccessMethod'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:90
-- IndexLifecycleStatus
CREATE TYPE IndexLifecycleStatus AS ENUM (
	'Ready',
	'Building',
	'Invalid'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:125
-- IndexMemoryEstimateStatus
CREATE TYPE IndexMemoryEstimateStatus AS ENUM (
	'Projected',
	'UnsupportedAccessMethod',
	'UnavailableStatistics'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:136
-- OptimizationStatus
CREATE TYPE OptimizationStatus AS ENUM (
	'Indexed',
	'ExactOnly',
	'MissingArtifacts',
	'StaleCatalog'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:55
-- QueryCohortStatus
CREATE TYPE QueryCohortStatus AS ENUM (
	'Observed'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:79
-- QueryExplainStatus
CREATE TYPE QueryExplainStatus AS ENUM (
	'Ready',
	'Fallback',
	'Policy'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:62
-- QueryLatencyBucket
CREATE TYPE QueryLatencyBucket AS ENUM (
	'Lt1Ms',
	'Lt10Ms',
	'Lt100Ms',
	'Lt1S',
	'Gte1S',
	'Unspecified'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:36
-- QueryLifecycleState
CREATE TYPE QueryLifecycleState AS ENUM (
	'Unspecified',
	'Exact',
	'Indexed',
	'Fallback',
	'IndexNotReady',
	'IndexCorrupt',
	'ArtifactMissing'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:114
-- RecallCheckStatus
CREATE TYPE RecallCheckStatus AS ENUM (
	'Passing',
	'Failing',
	'EmptyExact'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:179
-- TelemetryStatus
CREATE TYPE TelemetryStatus AS ENUM (
	'Active',
	'Empty',
	'MissingArtifacts',
	'StaleCatalog'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sql_enums.rs:149
-- VacuumAdviceStatus
CREATE TYPE VacuumAdviceStatus AS ENUM (
	'Healthy',
	'VacuumRecommended',
	'AnalyzeRecommended',
	'UnsupportedAccessMethod'
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership/persistence.rs:140
-- pgcontext::pgvector_ownership::persistence::_begin_pgvector_ownership_conversion
CREATE  FUNCTION "_begin_pgvector_ownership_conversion"(
	"source_table_oid" oid, /* pg_sys :: Oid */
	"source_column_name" TEXT, /* String */
	"mode" TEXT, /* String */
	"metric" TEXT, /* String */
	"dependency_manifest" TEXT[], /* Vec < String > */
	"validation_attestations" TEXT[] /* Vec < String > */
) RETURNS bigint /* i64 */
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'begin_conversion_catalog_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership/persistence.rs:300
-- pgcontext::pgvector_ownership::persistence::_transition_pgvector_ownership_conversion
CREATE  FUNCTION "_transition_pgvector_ownership_conversion"(
	"conversion_id" bigint, /* i64 */
	"expected_status" TEXT, /* String */
	"new_status" TEXT, /* String */
	"shadow_attnum" smallint, /* Option < i16 > */
	"total_rows" bigint, /* i64 */
	"processed_rows" bigint, /* i64 */
	"mismatch_count" bigint, /* i64 */
	"backfill_cursor" TEXT, /* Option < String > */
	"source_checksum" TEXT, /* Option < String > */
	"shadow_checksum" TEXT, /* Option < String > */
	"attestation" TEXT, /* Option < String > */
	"error_message" TEXT /* Option < String > */
) RETURNS void
SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transition_conversion_catalog_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_compat.rs:412
-- pgcontext::pgvector_compat::adopt_pgvector
CREATE  FUNCTION "adopt_pgvector"(
	"target" regclass DEFAULT NULL, /* Option < PgRelation > */
	"dry_run" bool DEFAULT true, /* bool */
	"drop_old" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"index_name" TEXT,  /* String */
	"action" TEXT,  /* String */
	"command" TEXT,  /* String */
	"executed" bool  /* bool */
)
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'adopt_pgvector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:711
-- pgcontext::artifact_segments::artifact_segment_diagnostics
CREATE  FUNCTION "artifact_segment_diagnostics"(
	"collection" TEXT /* String */
) RETURNS TABLE (
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"lifecycle_state" TEXT,  /* String */
	"status" TEXT,  /* String */
	"detail" TEXT,  /* String */
	"repair_advice" TEXT,  /* String */
	"cleanup_eligible" bool,  /* bool */
	"relative_path" TEXT,  /* Option < String > */
	"payload_bytes" bigint,  /* i64 */
	"file_payload_bytes" bigint,  /* Option < i64 > */
	"checksum" bigint,  /* i64 */
	"file_checksum" bigint  /* Option < i64 > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'artifact_segment_diagnostics_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:593
-- pgcontext::artifact_segments::artifact_segment_memory
CREATE  FUNCTION "artifact_segment_memory"(
	"collection" TEXT /* String */
) RETURNS TABLE (
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"lifecycle_state" TEXT,  /* String */
	"payload_bytes" bigint,  /* i64 */
	"header_bytes" bigint,  /* i64 */
	"mapped_bytes" bigint,  /* i64 */
	"file_materialized" bool  /* bool */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'artifact_segment_memory_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments/serving_readiness.rs:83
-- pgcontext::artifact_segments::serving_readiness::artifact_segment_mmap_payload
CREATE  FUNCTION "artifact_segment_mmap_payload"(
	"collection" TEXT, /* String */
	"artifact_name" TEXT, /* String */
	"max_mapped_bytes" bigint /* i64 */
) RETURNS TABLE (
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"mapped_bytes" bigint,  /* i64 */
	"payload" bytea  /* Vec < u8 > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'artifact_segment_mmap_payload_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments/serving_readiness.rs:52
-- pgcontext::artifact_segments::serving_readiness::artifact_segment_serving_readiness
CREATE  FUNCTION "artifact_segment_serving_readiness"(
	"collection" TEXT, /* String */
	"max_mapped_bytes" bigint /* i64 */
) RETURNS TABLE (
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"lifecycle_state" TEXT,  /* String */
	"status" TEXT,  /* String */
	"serving_ready" bool,  /* bool */
	"mapped_bytes" bigint,  /* i64 */
	"max_mapped_bytes" bigint,  /* i64 */
	"detail" TEXT  /* String */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'artifact_segment_serving_readiness_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:561
-- pgcontext::artifact_segments::artifact_segments
CREATE  FUNCTION "artifact_segments"(
	"collection" TEXT /* String */
) RETURNS TABLE (
	"artifact_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"build_job_id" bigint,  /* i64 */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"segment_kind" TEXT,  /* String */
	"format_version" INT,  /* i32 */
	"payload_bytes" bigint,  /* i64 */
	"checksum" bigint,  /* i64 */
	"relative_path" TEXT,  /* Option < String > */
	"lifecycle_state" TEXT  /* String */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'list_artifact_segments_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:161
-- pgcontext::vector_catalog::attach_hnsw_index
CREATE  FUNCTION "attach_hnsw_index"(
	"collection_name" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"index_name" TEXT /* String */
) RETURNS void
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'attach_hnsw_index_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:202
-- pgcontext::vector_catalog::attach_sparse_hnsw_index
CREATE  FUNCTION "attach_sparse_hnsw_index"(
	"collection_name" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"index_name" TEXT /* String */
) RETURNS void
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'attach_sparse_hnsw_index_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/points.rs:238
-- pgcontext::points::backfill_points
CREATE  FUNCTION "backfill_points"(
	"collection_name" TEXT, /* String */
	"batch_size" INT /* i32 */
) RETURNS TABLE (
	"batch_number" bigint,  /* i64 */
	"processed_count" bigint,  /* i64 */
	"inserted_count" bigint,  /* i64 */
	"reactivated_count" bigint  /* i64 */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'backfill_points_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:58
-- BitVec
CREATE TYPE BitVec;

-- crates/context-pg/src/vector_variants.rs:58
-- pgcontext::pgcontext::vector_variants::bitvec_in
CREATE  FUNCTION "bitvec_in"(
	"input" cstring /* Option < & :: core :: ffi :: CStr > */
) RETURNS BitVec /* Option < BitVec > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_in_wrapper';

-- crates/context-pg/src/vector_variants.rs:58
-- pgcontext::pgcontext::vector_variants::bitvec_out
CREATE  FUNCTION "bitvec_out"(
	"input" BitVec /* BitVec */
) RETURNS cstring /* :: pgrx :: ffi :: CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_out_wrapper';

-- crates/context-pg/src/vector_variants.rs:58
-- BitVec
CREATE TYPE BitVec (
	INTERNALLENGTH = variable,
	INPUT = bitvec_in, /* pgcontext::pgcontext::vector_variants::bitvec_in */
	OUTPUT = bitvec_out, /* pgcontext::pgcontext::vector_variants::bitvec_out */
	STORAGE = extended
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:268
-- pgcontext::vector_variant_ordering::bitvec_cmp
CREATE  FUNCTION "bitvec_cmp"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_cmp_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:273
-- pgcontext::vector_variant_ordering::bitvec_lt
CREATE  FUNCTION "bitvec_lt"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_lt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:298
-- pgcontext::vector_variant_ordering::bitvec_gt
CREATE  FUNCTION "bitvec_gt"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_gt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:876
-- pgcontext::pgcontext::vector_variants::bitvec_or_transition
CREATE  FUNCTION "bitvec_or_transition"(
	"state" bool[], /* :: std :: option :: Option < Vec < bool > > */
	"value" BitVec /* Option < BitVec > */
) RETURNS bool[] /* :: std :: option :: Option < Vec < bool > > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_or_transition_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:283
-- pgcontext::vector_variant_ordering::bitvec_eq
CREATE  FUNCTION "bitvec_eq"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_eq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:747
-- pgcontext::pgcontext::vector_variants::bitvec_hamming_distance
CREATE  FUNCTION "bitvec_hamming_distance"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_hamming_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:288
-- pgcontext::vector_variant_ordering::bitvec_ne
CREATE  FUNCTION "bitvec_ne"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_ne_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:886
-- pgcontext::pgcontext::vector_variants::bitvec_bits_final
CREATE  FUNCTION "bitvec_bits_final"(
	"state" bool[] /* Vec < bool > */
) RETURNS BitVec /* BitVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_bits_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:759
-- pgcontext::pgcontext::vector_variants::bitvec_jaccard_distance
CREATE  FUNCTION "bitvec_jaccard_distance"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS double precision /* f64 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_jaccard_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:677
-- pgcontext::pgcontext::vector_variants::bitvec_dims
CREATE  FUNCTION "bitvec_dims"(
	"vector" BitVec /* BitVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_dims_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:881
-- pgcontext::pgcontext::vector_variants::bitvec_and_transition
CREATE  FUNCTION "bitvec_and_transition"(
	"state" bool[], /* :: std :: option :: Option < Vec < bool > > */
	"value" BitVec /* Option < BitVec > */
) RETURNS bool[] /* :: std :: option :: Option < Vec < bool > > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_and_transition_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:460
-- pgcontext::pgcontext::vector_variants::bitvec_from_bool_array
CREATE  FUNCTION "bitvec_from_bool_array"(
	"bits" bool[] /* Vec < bool > */
) RETURNS BitVec /* BitVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_from_bool_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:171
-- pgcontext::vector_variant_typmods::bitvec_enforce_typmod
CREATE  FUNCTION "bitvec_enforce_typmod"(
	"vector" BitVec, /* BitVec */
	"typmod" INT, /* i32 */
	"_explicit" bool /* bool */
) RETURNS BitVec /* BitVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_enforce_typmod_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:589
-- pgcontext::pgcontext::vector_variants::bitvec
CREATE  FUNCTION "bitvec"(
	"input" TEXT /* & str */
) RETURNS BitVec /* BitVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:293
-- pgcontext::vector_variant_ordering::bitvec_ge
CREATE  FUNCTION "bitvec_ge"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_ge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:278
-- pgcontext::vector_variant_ordering::bitvec_le
CREATE  FUNCTION "bitvec_le"(
	"left" BitVec, /* BitVec */
	"right" BitVec /* BitVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_le_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:469
-- pgcontext::pgcontext::vector_variants::bitvec_to_bool_array
CREATE  FUNCTION "bitvec_to_bool_array"(
	"vector" BitVec /* BitVec */
) RETURNS bool[] /* Vec < bool > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_to_bool_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:259
-- requires:
--   BitVec
--   bitvec_from_bool_array
--   bitvec_to_bool_array
--   bitvec_hamming_distance
--   bitvec_jaccard_distance


CREATE CAST (bit AS bitvec) WITH INOUT AS ASSIGNMENT;
CREATE CAST (bit varying AS bitvec) WITH INOUT AS ASSIGNMENT;
CREATE CAST (bitvec AS bit varying) WITH INOUT AS ASSIGNMENT;
CREATE CAST (bitvec AS bit) WITH INOUT;
CREATE CAST (boolean[] AS bitvec) WITH FUNCTION pgcontext.bitvec_from_bool_array(boolean[]) AS ASSIGNMENT;
CREATE CAST (bitvec AS boolean[]) WITH FUNCTION pgcontext.bitvec_to_bool_array(bitvec) AS ASSIGNMENT;
CREATE FUNCTION pgcontext.hamming_distance("left" bit, "right" bit) RETURNS double precision LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT AS $$
    SELECT pgcontext.bitvec_hamming_distance($1::bitvec, $2::bitvec)::double precision
$$;
CREATE FUNCTION pgcontext.hamming_distance("left" bit varying, "right" bit varying) RETURNS double precision LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT AS $$
    SELECT pgcontext.bitvec_hamming_distance($1::bitvec, $2::bitvec)::double precision
$$;
CREATE FUNCTION pgcontext.jaccard_distance("left" bit, "right" bit) RETURNS double precision LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT AS $$
    SELECT pgcontext.bitvec_jaccard_distance($1::bitvec, $2::bitvec)
$$;
CREATE FUNCTION pgcontext.jaccard_distance("left" bit varying, "right" bit varying) RETURNS double precision LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT AS $$
    SELECT pgcontext.bitvec_jaccard_distance($1::bitvec, $2::bitvec)
$$;
CREATE OPERATOR pgcontext.<~> (LEFTARG = bit, RIGHTARG = bit, FUNCTION = pgcontext.hamming_distance, COMMUTATOR = OPERATOR(pgcontext.<~>));
CREATE OPERATOR pgcontext.<~> (LEFTARG = bit varying, RIGHTARG = bit varying, FUNCTION = pgcontext.hamming_distance, COMMUTATOR = OPERATOR(pgcontext.<~>));
CREATE OPERATOR pgcontext.<%> (LEFTARG = bit, RIGHTARG = bit, FUNCTION = pgcontext.jaccard_distance, COMMUTATOR = OPERATOR(pgcontext.<%>));
CREATE OPERATOR pgcontext.<%> (LEFTARG = bit varying, RIGHTARG = bit varying, FUNCTION = pgcontext.jaccard_distance, COMMUTATOR = OPERATOR(pgcontext.<%>));
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:127
-- pgcontext::vector_variant_typmods::bitvec_typmod_in
CREATE  FUNCTION "bitvec_typmod_in"(
	"modifiers" cstring[] /* Array < '_, & CStr > */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_typmod_in_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:134
-- pgcontext::vector_variant_typmods::bitvec_typmod_out
CREATE  FUNCTION "bitvec_typmod_out"(
	"typmod" INT /* i32 */
) RETURNS cstring /* CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bitvec_typmod_out_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/build_jobs.rs:156
-- pgcontext::build_jobs::build_jobs
CREATE  FUNCTION "build_jobs"(
	"collection" TEXT /* String */
) RETURNS TABLE (
	"build_job_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" BuildJobStatus,  /* BuildJobStatus */
	"backend_pid" INT,  /* Option < i32 > */
	"attempt" INT,  /* i32 */
	"processed_units" bigint,  /* i64 */
	"total_units" bigint,  /* i64 */
	"cancel_requested" bool,  /* bool */
	"error_message" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_jobs_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:184
-- pgcontext::artifact_segments::build_mmap_hnsw_artifact
CREATE  FUNCTION "build_mmap_hnsw_artifact"(
	"build_job_id" bigint /* i64 */
) RETURNS bytea /* Vec < u8 > */
STRICT VOLATILE
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'build_mmap_hnsw_artifact_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/points.rs:189
-- pgcontext::points::bulk_delete_points
CREATE  FUNCTION "bulk_delete_points"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[], /* Vec < String > */
	"batch_size" INT /* i32 */
) RETURNS TABLE (
	"batch_number" bigint,  /* i64 */
	"processed_count" bigint,  /* i64 */
	"deleted_count" bigint,  /* i64 */
	"missing_count" bigint  /* i64 */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bulk_delete_points_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/points.rs:137
-- pgcontext::points::bulk_upsert_points
CREATE  FUNCTION "bulk_upsert_points"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[], /* Vec < String > */
	"batch_size" INT /* i32 */
) RETURNS TABLE (
	"batch_number" bigint,  /* i64 */
	"processed_count" bigint,  /* i64 */
	"inserted_count" bigint,  /* i64 */
	"reactivated_count" bigint  /* i64 */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'bulk_upsert_points_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:666
-- pgcontext::artifact_segments::cleanup_artifact_segments
CREATE  FUNCTION "cleanup_artifact_segments"(
	"collection" TEXT, /* String */
	"dry_run" bool /* bool */
) RETURNS TABLE (
	"artifact_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" TEXT,  /* String */
	"cleanup_action" TEXT,  /* String */
	"relative_path" TEXT,  /* Option < String > */
	"file_removed" bool,  /* bool */
	"lifecycle_state" TEXT  /* String */
)
STRICT VOLATILE SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'cleanup_artifact_segments_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/payload_mutations.rs:105
-- pgcontext::payload_mutations::clear_payload
CREATE  FUNCTION "clear_payload"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"source_key" TEXT,  /* String */
	"updated" bool  /* bool */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'clear_payload_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/collection_aliases.rs:56
-- pgcontext::collection_aliases::collection_aliases
CREATE  FUNCTION "collection_aliases"() RETURNS TABLE (
	"alias_name" TEXT,  /* String */
	"collection_name" TEXT  /* String */
)
STRICT STABLE SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'collection_aliases_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog.rs:121
-- pgcontext::catalog::collection_info
CREATE  FUNCTION "collection_info"(
	"collection_name" TEXT /* String */
) RETURNS TABLE (
	"collection_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"owner_name" TEXT,  /* String */
	"table_schema" TEXT,  /* Option < String > */
	"table_name" TEXT  /* Option < String > */
)
STRICT STABLE SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'collection_info_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/collection_limits.rs:132
-- pgcontext::collection_limits::collection_limits
CREATE  FUNCTION "collection_limits"(
	"collection_name" TEXT /* String */
) RETURNS TABLE (
	"strict_mode" bool,  /* bool */
	"max_dimensions" INT,  /* Option < i32 > */
	"max_vectors" INT,  /* Option < i32 > */
	"max_points" bigint,  /* Option < i64 > */
	"max_filter_nodes" INT,  /* Option < i32 > */
	"max_search_limit" INT,  /* Option < i32 > */
	"max_candidate_budget" INT,  /* Option < i32 > */
	"query_timeout_ms" INT,  /* Option < i32 > */
	"max_index_memory_bytes" bigint  /* Option < i64 > */
)
STRICT STABLE SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'collection_limits_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:342
-- pgcontext::vector_catalog::collection_sparse_vectors
CREATE  FUNCTION "collection_sparse_vectors"(
	"collection_name" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"vector_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"vector_column" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"storage_options" jsonb,  /* JsonB */
	"index_options" jsonb,  /* JsonB */
	"status" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'collection_sparse_vectors_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:60
-- pgcontext::vector_catalog::collection_vectors
CREATE  FUNCTION "collection_vectors"(
	"collection_name" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"vector_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"vector_column" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"hnsw_options" jsonb,  /* JsonB */
	"quantization_options" jsonb,  /* JsonB */
	"status" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'collection_vectors_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am_compaction.rs:257
-- pgcontext::hnsw_am::compact
CREATE  FUNCTION "compact"(
	"index" regclass /* PgRelation */
) RETURNS TABLE (
	"live_rows" bigint,  /* i64 */
	"base_records_read" bigint,  /* i64 */
	"delta_records_drained" bigint  /* i64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_compact_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_compat.rs:723
-- pgcontext::pgvector_compat::compare_indexes
CREATE  FUNCTION "compare_indexes"(
	"table_name" TEXT, /* String */
	"column_name" TEXT, /* String */
	"queries" INT DEFAULT 20 /* i32 */
) RETURNS TABLE (
	"index_name" TEXT,  /* String */
	"access_method" TEXT,  /* String */
	"operator" TEXT,  /* Option < String > */
	"p50_ms" double precision,  /* Option < f64 > */
	"p95_ms" double precision,  /* Option < f64 > */
	"recall_at_10" double precision  /* Option < f64 > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'compare_indexes_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/collection_limits.rs:45
-- pgcontext::collection_limits::configure_collection_limits
CREATE  FUNCTION "configure_collection_limits"(
	"collection_name" TEXT, /* String */
	"strict_mode" bool, /* bool */
	"max_dimensions" INT, /* Option < i32 > */
	"max_vectors" INT, /* Option < i32 > */
	"max_points" bigint, /* Option < i64 > */
	"max_filter_nodes" INT, /* Option < i32 > */
	"max_search_limit" INT, /* Option < i32 > */
	"max_candidate_budget" INT, /* Option < i32 > */
	"query_timeout_ms" INT, /* Option < i32 > */
	"max_index_memory_bytes" bigint /* Option < i64 > */
) RETURNS TABLE (
	"strict_mode" bool,  /* bool */
	"max_dimensions" INT,  /* Option < i32 > */
	"max_vectors" INT,  /* Option < i32 > */
	"max_points" bigint,  /* Option < i64 > */
	"max_filter_nodes" INT,  /* Option < i32 > */
	"max_search_limit" INT,  /* Option < i32 > */
	"max_candidate_budget" INT,  /* Option < i32 > */
	"query_timeout_ms" INT,  /* Option < i32 > */
	"max_index_memory_bytes" bigint  /* Option < i64 > */
)
SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'configure_collection_limits_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:377
-- pgcontext::vector_catalog::configure_sparse_vector
CREATE  FUNCTION "configure_sparse_vector"(
	"collection_name" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"storage_options" jsonb, /* JsonB */
	"index_options" jsonb, /* JsonB */
	"status" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"vector_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"vector_column" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"storage_options" jsonb,  /* JsonB */
	"index_options" jsonb,  /* JsonB */
	"status" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'configure_sparse_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:100
-- pgcontext::vector_catalog::configure_vector
CREATE  FUNCTION "configure_vector"(
	"collection_name" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"hnsw_options" jsonb, /* JsonB */
	"quantization_options" jsonb, /* JsonB */
	"status" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"vector_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"vector_column" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"hnsw_options" jsonb,  /* JsonB */
	"quantization_options" jsonb,  /* JsonB */
	"status" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'configure_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search.rs:149
-- pgcontext::table_search::count
CREATE  FUNCTION "count"(
	"collection" TEXT /* String */
) RETURNS bigint /* i64 */
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'count_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search.rs:155
-- pgcontext::table_search::count
CREATE  FUNCTION "count"(
	"collection" TEXT, /* String */
	"filter" TEXT /* Option < String > */
) RETURNS bigint /* i64 */

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'count_collection_filtered_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog.rs:59
-- pgcontext::catalog::create_collection
CREATE  FUNCTION "create_collection"(
	"collection_name" TEXT /* String */
) RETURNS TABLE (
	"collection_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"owner_name" TEXT,  /* String */
	"table_schema" TEXT,  /* Option < String > */
	"table_name" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'create_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog.rs:90
-- pgcontext::catalog::create_collection
CREATE  FUNCTION "create_collection"(
	"collection_name" TEXT, /* String */
	"table_name" TEXT /* String */
) RETURNS TABLE (
	"collection_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"owner_name" TEXT,  /* String */
	"table_schema" TEXT,  /* Option < String > */
	"table_name" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'create_collection_for_table_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/collection_aliases.rs:21
-- pgcontext::collection_aliases::create_collection_alias
CREATE  FUNCTION "create_collection_alias"(
	"alias_name" TEXT, /* String */
	"target_collection_name" TEXT /* String */
) RETURNS TABLE (
	"alias_name" TEXT,  /* String */
	"collection_name" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'create_collection_alias_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/embedding_migrations.rs:44
-- pgcontext::embedding_migrations::create_embedding_migration
CREATE  FUNCTION "create_embedding_migration"(
	"collection" TEXT, /* String */
	"source_model_name" TEXT, /* String */
	"source_model_version" TEXT, /* String */
	"target_model_name" TEXT, /* String */
	"target_model_version" TEXT, /* String */
	"total_points" bigint /* i64 */
) RETURNS TABLE (
	"migration_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"source_model" TEXT,  /* String */
	"source_version" TEXT,  /* String */
	"target_model" TEXT,  /* String */
	"target_version" TEXT,  /* String */
	"status" EmbeddingMigrationStatus,  /* EmbeddingMigrationStatus */
	"total_points" bigint,  /* i64 */
	"processed_points" bigint  /* i64 */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'create_embedding_migration_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership.rs:225
-- pgcontext::pgvector_ownership::cutover_pgvector_ownership_conversion
CREATE  FUNCTION "cutover_pgvector_ownership_conversion"(
	"conversion_id" bigint, /* i64 */
	"sessions_drained" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"conversion_id" bigint,  /* i64 */
	"mode" TEXT,  /* String */
	"status" TEXT,  /* String */
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"target_type" TEXT,  /* String */
	"total_rows" bigint,  /* i64 */
	"processed_rows" bigint,  /* i64 */
	"mismatch_count" bigint,  /* i64 */
	"validation_attestations" TEXT[],  /* Vec < String > */
	"next_command" TEXT,  /* Option < String > */
	"error_message" TEXT  /* Option < String > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'cutover_pgvector_ownership_conversion_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/payload_mutations.rs:79
-- pgcontext::payload_mutations::delete_payload
CREATE  FUNCTION "delete_payload"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[], /* Vec < String > */
	"payload_keys" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"source_key" TEXT,  /* String */
	"updated" bool  /* bool */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'delete_payload_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/points.rs:106
-- pgcontext::points::delete_points
CREATE  FUNCTION "delete_points"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'delete_points_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/recommend.rs:87
-- pgcontext::table_search::recommend::discover
CREATE  FUNCTION "discover"(
	"collection" TEXT, /* String */
	"context_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'discover_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog.rs:301
-- pgcontext::catalog::drop_collection
CREATE  FUNCTION "drop_collection"(
	"collection_name" TEXT /* String */
) RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'drop_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/collection_aliases.rs:110
-- pgcontext::collection_aliases::drop_collection_alias
CREATE  FUNCTION "drop_collection_alias"(
	"alias_name" TEXT /* String */
) RETURNS bool /* bool */
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'drop_collection_alias_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/embedding_migrations.rs:148
-- pgcontext::embedding_migrations::embedding_migrations
CREATE  FUNCTION "embedding_migrations"() RETURNS TABLE (
	"migration_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"source_model" TEXT,  /* String */
	"source_version" TEXT,  /* String */
	"target_model" TEXT,  /* String */
	"target_version" TEXT,  /* String */
	"status" EmbeddingMigrationStatus,  /* EmbeddingMigrationStatus */
	"total_points" bigint,  /* i64 */
	"processed_points" bigint  /* i64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'embedding_migrations_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_compat.rs:640
-- pgcontext::pgvector_compat::enable_pgvector_binding
CREATE  FUNCTION "enable_pgvector_binding"() RETURNS void
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'enable_pgvector_binding_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:174
-- pgcontext::artifact_segments::encode_artifact_segment
CREATE  FUNCTION "encode_artifact_segment"(
	"kind" TEXT, /* String */
	"payload" bytea /* Vec < u8 > */
) RETURNS bytea /* Vec < u8 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'encode_artifact_segment_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:188
-- pgcontext::operations::estimate_index_memory
CREATE  FUNCTION "estimate_index_memory"(
	"index_name" TEXT /* String */
) RETURNS TABLE (
	"index_schema" TEXT,  /* String */
	"index_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"access_method" TEXT,  /* String */
	"estimated_rows" bigint,  /* i64 */
	"dimensions" INT,  /* i32 */
	"vector_bytes" bigint,  /* i64 */
	"link_bytes" bigint,  /* i64 */
	"total_bytes" bigint,  /* i64 */
	"status" IndexMemoryEstimateStatus  /* IndexMemoryEstimateStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'estimate_index_memory_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:244
-- pgcontext::query_builders::execute_query
CREATE  FUNCTION "execute_query"(
	"collection" TEXT, /* String */
	"plan" jsonb /* JsonB */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'execute_query_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query.rs:177
-- pgcontext::hybrid_query::explain
CREATE  FUNCTION "explain"(
	"collection" TEXT, /* String */
	"text_column" TEXT /* String */
) RETURNS TABLE (
	"stage" TEXT,  /* String */
	"detail" TEXT,  /* String */
	"branch" TEXT,  /* Option < String > */
	"strategy" TEXT,  /* String */
	"status" QueryExplainStatus,  /* QueryExplainStatus */
	"estimated_candidates" bigint,  /* Option < i64 > */
	"candidate_budget" bigint  /* Option < i64 > */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'explain_collection_query_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/recommend.rs:106
-- pgcontext::table_search::recommend::explore
CREATE  FUNCTION "explore"(
	"collection" TEXT, /* String */
	"context_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'explore_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search.rs:171
-- pgcontext::table_search::facet
CREATE  FUNCTION "facet"(
	"collection" TEXT, /* String */
	"field" TEXT, /* String */
	"filter" TEXT, /* Option < String > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"value" TEXT,  /* String */
	"count" bigint  /* i64 */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'facet_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership.rs:270
-- pgcontext::pgvector_ownership::finalize_pgvector_ownership_conversion
CREATE  FUNCTION "finalize_pgvector_ownership_conversion"(
	"conversion_id" bigint /* i64 */
) RETURNS TABLE (
	"conversion_id" bigint,  /* i64 */
	"mode" TEXT,  /* String */
	"status" TEXT,  /* String */
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"target_type" TEXT,  /* String */
	"total_rows" bigint,  /* i64 */
	"processed_rows" bigint,  /* i64 */
	"mismatch_count" bigint,  /* i64 */
	"validation_attestations" TEXT[],  /* Vec < String > */
	"next_command" TEXT,  /* Option < String > */
	"error_message" TEXT  /* Option < String > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'finalize_pgvector_ownership_conversion_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:36
-- HalfVec
CREATE TYPE HalfVec;

-- crates/context-pg/src/vector_variants.rs:36
-- pgcontext::pgcontext::vector_variants::halfvec_in
CREATE  FUNCTION "halfvec_in"(
	"input" cstring /* Option < & :: core :: ffi :: CStr > */
) RETURNS HalfVec /* Option < HalfVec > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_in_wrapper';

-- crates/context-pg/src/vector_variants.rs:36
-- pgcontext::pgcontext::vector_variants::halfvec_out
CREATE  FUNCTION "halfvec_out"(
	"input" HalfVec /* HalfVec */
) RETURNS cstring /* :: pgrx :: ffi :: CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_out_wrapper';

-- crates/context-pg/src/vector_variants.rs:36
-- HalfVec
CREATE TYPE HalfVec (
	INTERNALLENGTH = variable,
	INPUT = halfvec_in, /* pgcontext::pgcontext::vector_variants::halfvec_in */
	OUTPUT = halfvec_out, /* pgcontext::pgcontext::vector_variants::halfvec_out */
	STORAGE = extended
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:421
-- pgcontext::pgcontext::vector_variants::halfvec_from_real_array
CREATE  FUNCTION "halfvec_from_real_array"(
	"values" real[] /* Vec < f32 > */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_from_real_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:221
-- pgcontext::vector_variant_ordering::halfvec_ge
CREATE  FUNCTION "halfvec_ge"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_ge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:226
-- pgcontext::vector_variant_ordering::halfvec_gt
CREATE  FUNCTION "halfvec_gt"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_gt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:818
-- pgcontext::pgcontext::vector_variants::halfvec_avg_final
CREATE  FUNCTION "halfvec_avg_final"(
	"state" real[] /* Vec < f32 > */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_avg_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:437
-- pgcontext::pgcontext::vector_variants::halfvec_from_double_array
CREATE  FUNCTION "halfvec_from_double_array"(
	"values" double precision[] /* Vec < f64 > */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_from_double_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:699
-- pgcontext::pgcontext::vector_variants::halfvec_negative_inner_product
CREATE  FUNCTION "halfvec_negative_inner_product"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_negative_inner_product_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:196
-- pgcontext::vector_variant_ordering::halfvec_cmp
CREATE  FUNCTION "halfvec_cmp"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_cmp_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:201
-- pgcontext::vector_variant_ordering::halfvec_lt
CREATE  FUNCTION "halfvec_lt"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_lt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:429
-- pgcontext::pgcontext::vector_variants::halfvec_from_integer_array
CREATE  FUNCTION "halfvec_from_integer_array"(
	"values" INT[] /* Vec < i32 > */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_from_integer_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:711
-- pgcontext::pgcontext::vector_variants::halfvec_l1_distance
CREATE  FUNCTION "halfvec_l1_distance"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_l1_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:206
-- pgcontext::vector_variant_ordering::halfvec_le
CREATE  FUNCTION "halfvec_le"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_le_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:637
-- pgcontext::pgcontext::vector_variants::halfvec_dims
CREATE  FUNCTION "halfvec_dims"(
	"vector" HalfVec /* HalfVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_dims_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:693
-- pgcontext::pgcontext::vector_variants::halfvec_inner_product
CREATE  FUNCTION "halfvec_inner_product"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_inner_product_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:216
-- pgcontext::vector_variant_ordering::halfvec_ne
CREATE  FUNCTION "halfvec_ne"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_ne_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:525
-- pgcontext::pgcontext::vector_variants::halfvec
CREATE  FUNCTION "halfvec"(
	"input" TEXT /* & str */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:141
-- pgcontext::vector_variant_typmods::halfvec_enforce_typmod
CREATE  FUNCTION "halfvec_enforce_typmod"(
	"vector" HalfVec, /* HalfVec */
	"typmod" INT, /* i32 */
	"_explicit" bool /* bool */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_enforce_typmod_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:687
-- pgcontext::pgcontext::vector_variants::halfvec_l2_distance
CREATE  FUNCTION "halfvec_l2_distance"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_l2_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:705
-- pgcontext::pgcontext::vector_variants::halfvec_cosine_distance
CREATE  FUNCTION "halfvec_cosine_distance"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_cosine_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:211
-- pgcontext::vector_variant_ordering::halfvec_eq
CREATE  FUNCTION "halfvec_eq"(
	"left" HalfVec, /* HalfVec */
	"right" HalfVec /* HalfVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_eq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:812
-- pgcontext::pgcontext::vector_variants::halfvec_sum_final
CREATE  FUNCTION "halfvec_sum_final"(
	"state" real[] /* Vec < f32 > */
) RETURNS HalfVec /* HalfVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_sum_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:771
-- pgcontext::pgcontext::vector_variants::halfvec_sum_transition
CREATE  FUNCTION "halfvec_sum_transition"(
	"state" real[], /* :: std :: option :: Option < Vec < f32 > > */
	"value" HalfVec /* Option < HalfVec > */
) RETURNS real[] /* :: std :: option :: Option < Vec < f32 > > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_sum_transition_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:443
-- pgcontext::pgcontext::vector_variants::halfvec_to_real_array
CREATE  FUNCTION "halfvec_to_real_array"(
	"vector" HalfVec /* HalfVec */
) RETURNS real[] /* Vec < f32 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_to_real_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:99
-- pgcontext::vector_variant_typmods::halfvec_typmod_in
CREATE  FUNCTION "halfvec_typmod_in"(
	"modifiers" cstring[] /* Array < '_, & CStr > */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_typmod_in_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:106
-- pgcontext::vector_variant_typmods::halfvec_typmod_out
CREATE  FUNCTION "halfvec_typmod_out"(
	"typmod" INT /* i32 */
) RETURNS cstring /* CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_typmod_out_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:896
-- pgcontext::operations::hnsw_build_stats
CREATE  FUNCTION "hnsw_build_stats"() RETURNS TABLE (
	"last_build_tuples" bigint,  /* i64 */
	"graph_millis" bigint,  /* i64 */
	"write_millis" bigint  /* i64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_build_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am.rs:474
-- pgcontext::hnsw_am::hnsw_last_scan_work
CREATE  FUNCTION "hnsw_last_scan_work"() RETURNS TABLE (
	"page_visits" bigint,  /* i64 */
	"node_reads" bigint,  /* i64 */
	"candidates" bigint,  /* i64 */
	"rechecks" bigint,  /* i64 */
	"exact_strategy" bool  /* bool */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_last_scan_work_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:845
-- pgcontext::operations::hnsw_serving_stats
CREATE  FUNCTION "hnsw_serving_stats"() RETURNS TABLE (
	"pack_builds" bigint,  /* i64 */
	"pack_reuses" bigint,  /* i64 */
	"last_pack_bytes" bigint,  /* i64 */
	"last_pack_millis" bigint,  /* i64 */
	"total_pack_millis" bigint,  /* i64 */
	"shared_attaches" bigint,  /* i64 */
	"shared_publishes" bigint,  /* i64 */
	"shared_publish_skips" bigint,  /* i64 */
	"mapped_attaches" bigint,  /* i64 */
	"mapped_publishes" bigint,  /* i64 */
	"mapped_publish_skips" bigint,  /* i64 */
	"page_native_fallbacks" bigint,  /* i64 */
	"delta_segment_records" bigint,  /* i64 */
	"delta_segment_scans" bigint  /* i64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_serving_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations/advisor.rs:49
-- pgcontext::operations::advisor::index_advisor
CREATE  FUNCTION "index_advisor"(
	"collection" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"filter_key" TEXT,  /* Option < String > */
	"column_name" TEXT,  /* Option < String > */
	"recommendation" IndexAdvisorRecommendation,  /* IndexAdvisorRecommendation */
	"detail" TEXT,  /* String */
	"suggested_sql" TEXT  /* Option < String > */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'index_advisor_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:138
-- pgcontext::operations::index_diagnostics
CREATE  FUNCTION "index_diagnostics"(
	"index_name" TEXT /* String */
) RETURNS TABLE (
	"index_schema" TEXT,  /* String */
	"index_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"access_method" TEXT,  /* String */
	"status" IndexDiagnosticStatus,  /* IndexDiagnosticStatus */
	"context_error" TEXT,  /* Option < String > */
	"sqlstate" TEXT,  /* Option < String > */
	"repair_advice" TEXT  /* String */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'index_diagnostics_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:92
-- pgcontext::operations::index_status
CREATE  FUNCTION "index_status"(
	"index_name" TEXT /* String */
) RETURNS TABLE (
	"index_schema" TEXT,  /* String */
	"index_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"access_method" TEXT,  /* String */
	"is_valid" bool,  /* bool */
	"is_ready" bool,  /* bool */
	"is_live" bool,  /* bool */
	"status" IndexLifecycleStatus  /* IndexLifecycleStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'index_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_compat.rs:254
-- pgcontext::pgvector_compat::migration_report
CREATE  FUNCTION "migration_report"() RETURNS TABLE (
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"type_name" TEXT,  /* String */
	"dimensions" INT,  /* Option < i32 > */
	"pgvector_indexes" TEXT[],  /* Vec < String > */
	"pgcontext_indexes" TEXT[],  /* Vec < String > */
	"conversion_supported" bool,  /* bool */
	"blockers" TEXT[],  /* Vec < String > */
	"suggested_command" TEXT  /* String */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'migration_report_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/model_versions.rs:88
-- pgcontext::model_versions::model_versions
CREATE  FUNCTION "model_versions"() RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"model_name" TEXT,  /* String */
	"model_version" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"is_active" bool  /* bool */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'model_versions_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:241
-- pgcontext::operations::optimization_status
CREATE  FUNCTION "optimization_status"(
	"collection" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"table_schema" TEXT,  /* Option < String > */
	"table_name" TEXT,  /* Option < String > */
	"has_source_table" bool,  /* bool */
	"source_table_exists" bool,  /* bool */
	"registered_vectors" bigint,  /* i64 */
	"active_points" bigint,  /* i64 */
	"filter_fields" bigint,  /* i64 */
	"hnsw_indexes" bigint,  /* i64 */
	"status" OptimizationStatus  /* OptimizationStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'optimization_status_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership.rs:345
-- pgcontext::pgvector_ownership::pgvector_ownership_conversions
CREATE  FUNCTION "pgvector_ownership_conversions"() RETURNS TABLE (
	"conversion_id" bigint,  /* i64 */
	"mode" TEXT,  /* String */
	"status" TEXT,  /* String */
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"target_type" TEXT,  /* String */
	"total_rows" bigint,  /* i64 */
	"processed_rows" bigint,  /* i64 */
	"mismatch_count" bigint,  /* i64 */
	"validation_attestations" TEXT[],  /* Vec < String > */
	"next_command" TEXT,  /* Option < String > */
	"error_message" TEXT  /* Option < String > */
)
STRICT
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'pgvector_ownership_conversions_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:373
-- pgcontext::artifact_segments::publish_artifact_segment
CREATE  FUNCTION "publish_artifact_segment"(
	"build_job_id" bigint, /* i64 */
	"segment" bytea /* Vec < u8 > */
) RETURNS TABLE (
	"artifact_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"build_job_id" bigint,  /* i64 */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"segment_kind" TEXT,  /* String */
	"format_version" INT,  /* i32 */
	"payload_bytes" bigint,  /* i64 */
	"checksum" bigint,  /* i64 */
	"lifecycle_state" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'publish_artifact_segment_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:410
-- pgcontext::artifact_segments::publish_artifact_segment_file
CREATE  FUNCTION "publish_artifact_segment_file"(
	"build_job_id" bigint, /* i64 */
	"segment" bytea /* Vec < u8 > */
) RETURNS TABLE (
	"artifact_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"build_job_id" bigint,  /* i64 */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"segment_kind" TEXT,  /* String */
	"format_version" INT,  /* i32 */
	"payload_bytes" bigint,  /* i64 */
	"checksum" bigint,  /* i64 */
	"relative_path" TEXT,  /* Option < String > */
	"lifecycle_state" TEXT  /* String */
)
STRICT VOLATILE SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'publish_artifact_segment_file_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_stats.rs:358
-- pgcontext::query_stats::query_cohort_stats
CREATE  FUNCTION "query_cohort_stats"() RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"cohort" TEXT,  /* String */
	"query_kind" TEXT,  /* String */
	"query_count" bigint,  /* i64 */
	"total_results" bigint,  /* i64 */
	"total_candidates" bigint,  /* Option < i64 > */
	"total_rows_rechecked" bigint,  /* i64 */
	"total_rows_pruned" bigint,  /* i64 */
	"avg_recall_threshold" double precision,  /* Option < f64 > */
	"avg_recall_achieved" double precision,  /* Option < f64 > */
	"latency_bucket" QueryLatencyBucket,  /* QueryLatencyBucket */
	"lifecycle_state" QueryLifecycleState,  /* QueryLifecycleState */
	"avg_latency_ms" double precision,  /* f64 */
	"status" QueryCohortStatus  /* QueryCohortStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_cohort_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:161
-- pgcontext::query_builders::query_discover
CREATE  FUNCTION "query_discover"(
	"context_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_discover_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_stats.rs:387
-- pgcontext::query_stats::query_execution_stats
CREATE  FUNCTION "query_execution_stats"() RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"query_kind" TEXT,  /* String */
	"strategy" TEXT,  /* String */
	"query_count" bigint,  /* i64 */
	"total_visits" bigint,  /* i64 */
	"total_filter_candidates" bigint,  /* i64 */
	"total_candidates" bigint,  /* i64 */
	"total_rechecks" bigint,  /* i64 */
	"total_stages" bigint,  /* i64 */
	"total_expansions" bigint,  /* i64 */
	"completion" TEXT,  /* String */
	"latency_bucket" QueryLatencyBucket,  /* QueryLatencyBucket */
	"lifecycle_state" QueryLifecycleState,  /* QueryLifecycleState */
	"avg_latency_ms" double precision  /* f64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_execution_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:219
-- pgcontext::query_builders::query_formula
CREATE  FUNCTION "query_formula"(
	"branch" jsonb, /* JsonB */
	"formula" TEXT /* String */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_formula_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:94
-- pgcontext::query_builders::query_full_text
CREATE  FUNCTION "query_full_text"(
	"text_query" TEXT, /* String */
	"text_column" TEXT, /* String */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_full_text_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:172
-- pgcontext::query_builders::query_lookup
CREATE  FUNCTION "query_lookup"(
	"point_ids" bigint[] /* Vec < i64 > */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_lookup_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:182
-- pgcontext::query_builders::query_prefetch
CREATE  FUNCTION "query_prefetch"(
	"branches" jsonb[] /* Vec < JsonB > */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_prefetch_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:142
-- pgcontext::query_builders::query_recommend
CREATE  FUNCTION "query_recommend"(
	"positive_point_ids" bigint[], /* Vec < i64 > */
	"negative_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_recommend_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:233
-- pgcontext::query_builders::query_rerank
CREATE  FUNCTION "query_rerank"(
	"branch" jsonb, /* JsonB */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_rerank_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:203
-- pgcontext::query_builders::query_score_threshold
CREATE  FUNCTION "query_score_threshold"(
	"branch" jsonb, /* JsonB */
	"min_score" double precision, /* Option < f64 > */
	"max_score" double precision /* Option < f64 > */
) RETURNS jsonb /* JsonB */
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_score_threshold_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_stats.rs:416
-- pgcontext::query_stats::query_telemetry_queue_stats
CREATE  FUNCTION "query_telemetry_queue_stats"() RETURNS TABLE (
	"transport" TEXT,  /* String */
	"delivery" TEXT,  /* String */
	"enqueued" bigint,  /* i64 */
	"persisted" bigint,  /* i64 */
	"dropped_contention" bigint,  /* i64 */
	"dropped_full" bigint,  /* i64 */
	"dropped_orphaned" bigint,  /* i64 */
	"database_slot_exhausted" bigint,  /* i64 */
	"worker_launch_failures" bigint,  /* i64 */
	"pending" bigint,  /* i64 */
	"worker_pid" INT  /* Option < i32 > */
)
STRICT 
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_telemetry_queue_stats_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:192
-- pgcontext::query_builders::query_weight
CREATE  FUNCTION "query_weight"(
	"branch" jsonb, /* JsonB */
	"weight" double precision /* f64 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_weight_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:340
-- pgcontext::operations::recall_check
CREATE  FUNCTION "recall_check"(
	"exact_point_ids" bigint[], /* Vec < i64 > */
	"candidate_point_ids" bigint[], /* Vec < i64 > */
	"min_recall" double precision /* f64 */
) RETURNS TABLE (
	"exact_count" bigint,  /* i64 */
	"candidate_count" bigint,  /* i64 */
	"intersection_count" bigint,  /* i64 */
	"recall" double precision,  /* f64 */
	"status" RecallCheckStatus  /* RecallCheckStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'recall_check_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/recommend.rs:17
-- pgcontext::table_search::recommend::recommend
CREATE  FUNCTION "recommend"(
	"collection" TEXT, /* String */
	"positive_point_ids" bigint[], /* Vec < i64 > */
	"negative_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'recommend_collection_from_points_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_stats.rs:248
-- pgcontext::query_stats::record_query_stat
CREATE  FUNCTION "record_query_stat"(
	"collection" TEXT, /* String */
	"cohort" TEXT, /* String */
	"query_kind" TEXT, /* String */
	"result_count" bigint, /* i64 */
	"candidate_count" bigint, /* Option < i64 > */
	"latency_ms" double precision /* f64 */
) RETURNS bool /* bool */
SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'record_query_stat_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_stats.rs:299
-- pgcontext::query_stats::record_query_stat
CREATE  FUNCTION "record_query_stat"(
	"collection" TEXT, /* String */
	"cohort" TEXT, /* String */
	"query_kind" TEXT, /* String */
	"result_count" bigint, /* i64 */
	"candidates_considered" bigint, /* Option < i64 > */
	"rows_rechecked" bigint, /* i64 */
	"rows_pruned" bigint, /* i64 */
	"recall_threshold" double precision, /* Option < f64 > */
	"recall_achieved" double precision, /* Option < f64 > */
	"latency_ms" double precision, /* f64 */
	"lifecycle_state" QueryLifecycleState /* QueryLifecycleState */
) RETURNS bool /* bool */
SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'record_query_stat_detailed_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog.rs:237
-- pgcontext::catalog::register_filter_column
CREATE  FUNCTION "register_filter_column"(
	"collection_name" TEXT, /* String */
	"filter_key" TEXT, /* String */
	"column_name" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"filter_key" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'register_filter_column_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/payload_catalog.rs:39
-- pgcontext::payload_catalog::register_jsonb_path
CREATE  FUNCTION "register_jsonb_path"(
	"collection_name" TEXT, /* String */
	"filter_key" TEXT, /* String */
	"column_name" TEXT, /* String */
	"path" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"filter_key" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"jsonb_path" TEXT[]  /* Vec < String > */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'register_jsonb_path_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/late_interaction_catalog.rs:57
-- pgcontext::late_interaction_catalog::register_late_interaction
CREATE  FUNCTION "register_late_interaction"(
	"collection" TEXT, /* String */
	"source_table" TEXT, /* String */
	"token_source" TEXT /* String */
) RETURNS TABLE (
	"collection" TEXT,  /* String */
	"source_table" TEXT,  /* String */
	"token_source" TEXT,  /* String */
	"dimensions" INT,  /* Option < i32 > */
	"point_count" bigint,  /* i64 */
	"token_count" bigint,  /* i64 */
	"status" TEXT  /* String */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'register_late_interaction_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/model_versions.rs:40
-- pgcontext::model_versions::register_model_version
CREATE  FUNCTION "register_model_version"(
	"collection" TEXT, /* String */
	"model_name" TEXT, /* String */
	"model_version" TEXT, /* String */
	"dimensions" INT, /* i32 */
	"metric" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"model_name" TEXT,  /* String */
	"model_version" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"is_active" bool  /* bool */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'register_model_version_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_catalog.rs:273
-- pgcontext::vector_catalog::register_sparse_vector
CREATE  FUNCTION "register_sparse_vector"(
	"collection_name" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector_column" TEXT, /* String */
	"dimensions" INT, /* i32 */
	"metric" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"vector_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"vector_column" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT,  /* String */
	"storage_options" jsonb,  /* JsonB */
	"index_options" jsonb,  /* JsonB */
	"status" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'register_sparse_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/catalog.rs:163
-- pgcontext::catalog::register_vector
CREATE  FUNCTION "register_vector"(
	"collection_name" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector_column" TEXT, /* String */
	"dimensions" INT, /* i32 */
	"metric" TEXT /* String */
) RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"vector_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"vector_column" TEXT,  /* String */
	"dimensions" INT,  /* i32 */
	"metric" TEXT  /* String */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'register_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/late_interaction_catalog.rs:113
-- pgcontext::late_interaction_catalog::repair_late_interaction
CREATE  FUNCTION "repair_late_interaction"(
	"collection" TEXT, /* String */
	"batch_size" INT /* i32 */
) RETURNS TABLE (
	"collection" TEXT,  /* String */
	"batch_count" bigint,  /* i64 */
	"point_count" bigint,  /* i64 */
	"token_count" bigint,  /* i64 */
	"dimensions" INT,  /* Option < i32 > */
	"status" TEXT  /* String */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'repair_late_interaction_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/build_jobs.rs:283
-- pgcontext::build_jobs::request_build_cancel
CREATE  FUNCTION "request_build_cancel"(
	"build_job_id" bigint /* i64 */
) RETURNS TABLE (
	"build_job_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" BuildJobStatus,  /* BuildJobStatus */
	"backend_pid" INT,  /* Option < i32 > */
	"attempt" INT,  /* i32 */
	"processed_units" bigint,  /* i64 */
	"total_units" bigint,  /* i64 */
	"cancel_requested" bool,  /* bool */
	"error_message" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'request_build_cancel_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:621
-- pgcontext::artifact_segments::retire_artifact_segment
CREATE  FUNCTION "retire_artifact_segment"(
	"artifact_id" bigint /* i64 */
) RETURNS TABLE (
	"artifact_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"previous_relative_path" TEXT,  /* Option < String > */
	"file_removed" bool,  /* bool */
	"lifecycle_state" TEXT  /* String */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'retire_artifact_segment_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/build_jobs.rs:329
-- pgcontext::build_jobs::retry_build_job
CREATE  FUNCTION "retry_build_job"(
	"build_job_id" bigint /* i64 */
) RETURNS TABLE (
	"build_job_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" BuildJobStatus,  /* BuildJobStatus */
	"backend_pid" INT,  /* Option < i32 > */
	"attempt" INT,  /* i32 */
	"processed_units" bigint,  /* i64 */
	"total_units" bigint,  /* i64 */
	"cancel_requested" bool,  /* bool */
	"error_message" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'retry_build_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership.rs:306
-- pgcontext::pgvector_ownership::rollback_pgvector_ownership_conversion
CREATE  FUNCTION "rollback_pgvector_ownership_conversion"(
	"conversion_id" bigint /* i64 */
) RETURNS TABLE (
	"conversion_id" bigint,  /* i64 */
	"mode" TEXT,  /* String */
	"status" TEXT,  /* String */
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"target_type" TEXT,  /* String */
	"total_rows" bigint,  /* i64 */
	"processed_rows" bigint,  /* i64 */
	"mismatch_count" bigint,  /* i64 */
	"validation_attestations" TEXT[],  /* Vec < String > */
	"next_command" TEXT,  /* Option < String > */
	"error_message" TEXT  /* Option < String > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'rollback_pgvector_ownership_conversion_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/build_jobs.rs:386
-- pgcontext::build_jobs::run_build_job
CREATE  FUNCTION "run_build_job"(
	"build_job_id" bigint, /* i64 */
	"units_per_step" bigint DEFAULT 1 /* i64 */
) RETURNS TABLE (
	"build_job_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" BuildJobStatus,  /* BuildJobStatus */
	"backend_pid" INT,  /* Option < i32 > */
	"attempt" INT,  /* i32 */
	"processed_units" bigint,  /* i64 */
	"total_units" bigint,  /* i64 */
	"cancel_requested" bool,  /* bool */
	"error_message" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_build_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership.rs:156
-- pgcontext::pgvector_ownership::run_pgvector_ownership_conversion
CREATE  FUNCTION "run_pgvector_ownership_conversion"(
	"conversion_id" bigint, /* i64 */
	"batch_size" INT DEFAULT 1000, /* i32 */
	"sessions_drained" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"conversion_id" bigint,  /* i64 */
	"mode" TEXT,  /* String */
	"status" TEXT,  /* String */
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"target_type" TEXT,  /* String */
	"total_rows" bigint,  /* i64 */
	"processed_rows" bigint,  /* i64 */
	"mismatch_count" bigint,  /* i64 */
	"validation_attestations" TEXT[],  /* Vec < String > */
	"next_command" TEXT,  /* Option < String > */
	"error_message" TEXT  /* Option < String > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'run_pgvector_ownership_conversion_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search.rs:120
-- pgcontext::table_search::scroll
CREATE  FUNCTION "scroll"(
	"collection" TEXT, /* String */
	"cursor" TEXT, /* Option < String > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"next_cursor" TEXT  /* String */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'scroll_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/payload_mutations.rs:43
-- pgcontext::payload_mutations::set_payload
CREATE  FUNCTION "set_payload"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[], /* Vec < String > */
	"payload" jsonb /* JsonB */
) RETURNS TABLE (
	"source_key" TEXT,  /* String */
	"updated" bool  /* bool */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'set_payload_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:44
-- SparseVec
CREATE TYPE SparseVec;

-- crates/context-pg/src/vector_variants.rs:44
-- pgcontext::pgcontext::vector_variants::sparsevec_in
CREATE  FUNCTION "sparsevec_in"(
	"input" cstring /* Option < & :: core :: ffi :: CStr > */
) RETURNS SparseVec /* Option < SparseVec > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_in_wrapper';

-- crates/context-pg/src/vector_variants.rs:44
-- pgcontext::pgcontext::vector_variants::sparsevec_out
CREATE  FUNCTION "sparsevec_out"(
	"input" SparseVec /* SparseVec */
) RETURNS cstring /* :: pgrx :: ffi :: CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_out_wrapper';

-- crates/context-pg/src/vector_variants.rs:44
-- SparseVec
CREATE TYPE SparseVec (
	INTERNALLENGTH = variable,
	INPUT = sparsevec_in, /* pgcontext::pgcontext::vector_variants::sparsevec_in */
	OUTPUT = sparsevec_out, /* pgcontext::pgcontext::vector_variants::sparsevec_out */
	STORAGE = extended
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sparse_search.rs:54
-- pgcontext::sparse_search::explain_sparse
CREATE  FUNCTION "explain_sparse"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"query" SparseVec, /* SparseVec */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"strategy" TEXT,  /* String */
	"active_points" bigint,  /* i64 */
	"scored_count" bigint,  /* i64 */
	"candidate_count" bigint,  /* i64 */
	"recheck_count" bigint  /* i64 */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'explain_sparse_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am.rs:539
-- pgcontext::hnsw_am::_hnsw_sparse_candidates
CREATE  FUNCTION "_hnsw_sparse_candidates"(
	"index_relation" regclass, /* PgRelation */
	"query" SparseVec, /* SparseVec */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"heap_tid" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_sparse_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:232
-- pgcontext::vector_variant_ordering::sparsevec_cmp
CREATE  FUNCTION "sparsevec_cmp"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_cmp_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:647
-- pgcontext::pgcontext::vector_variants::sparsevec_dims
CREATE  FUNCTION "sparsevec_dims"(
	"vector" SparseVec /* SparseVec */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_dims_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:657
-- pgcontext::pgcontext::vector_variants::sparsevec_indices
CREATE  FUNCTION "sparsevec_indices"(
	"vector" SparseVec /* SparseVec */
) RETURNS INT[] /* Vec < i32 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_indices_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sparse_search.rs:159
-- pgcontext::sparse_search::search_sparse
CREATE  FUNCTION "search_sparse"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"query" SparseVec, /* SparseVec */
	"filter" TEXT, /* Option < String > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_sparse_collection_filtered_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:717
-- pgcontext::pgcontext::vector_variants::sparsevec_l2_distance
CREATE  FUNCTION "sparsevec_l2_distance"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_l2_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:247
-- pgcontext::vector_variant_ordering::sparsevec_eq
CREATE  FUNCTION "sparsevec_eq"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_eq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:723
-- pgcontext::pgcontext::vector_variants::sparsevec_inner_product
CREATE  FUNCTION "sparsevec_inner_product"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_inner_product_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:741
-- pgcontext::pgcontext::vector_variants::sparsevec_l1_distance
CREATE  FUNCTION "sparsevec_l1_distance"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_l1_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:543
-- pgcontext::pgcontext::vector_variants::sparsevec_from_arrays
CREATE  FUNCTION "sparsevec_from_arrays"(
	"indices" INT[], /* Vec < i32 > */
	"values" real[], /* Vec < f32 > */
	"dimensions" INT /* i32 */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_from_arrays_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:156
-- pgcontext::vector_variant_typmods::sparsevec_enforce_typmod
CREATE  FUNCTION "sparsevec_enforce_typmod"(
	"vector" SparseVec, /* SparseVec */
	"typmod" INT, /* i32 */
	"_explicit" bool /* bool */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_enforce_typmod_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:729
-- pgcontext::pgcontext::vector_variants::sparsevec_negative_inner_product
CREATE  FUNCTION "sparsevec_negative_inner_product"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_negative_inner_product_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sparse_search.rs:19
-- pgcontext::sparse_search::search_sparse
CREATE  FUNCTION "search_sparse"(
	"query" SparseVec, /* SparseVec */
	"point_ids" bigint[], /* Vec < i64 > */
	"vectors" SparseVec[], /* Vec < SparseVec > */
	"metric" TEXT, /* String */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"score" real  /* f32 */
)
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_sparse_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:534
-- pgcontext::pgcontext::vector_variants::sparsevec
CREATE  FUNCTION "sparsevec"(
	"input" TEXT /* & str */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:50
-- pgcontext::query_builders::query_sparse_nearest
CREATE  FUNCTION "query_sparse_nearest"(
	"vector_name" TEXT, /* String */
	"vector" SparseVec, /* SparseVec */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_sparse_nearest_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:262
-- pgcontext::vector_variant_ordering::sparsevec_gt
CREATE  FUNCTION "sparsevec_gt"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_gt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:871
-- pgcontext::pgcontext::vector_variants::sparsevec_avg_final
CREATE  FUNCTION "sparsevec_avg_final"(
	"state" real[] /* Vec < f32 > */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_avg_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/sparse_search.rs:115
-- pgcontext::sparse_search::search_sparse
CREATE  FUNCTION "search_sparse"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"query" SparseVec, /* SparseVec */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_sparse_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:242
-- pgcontext::vector_variant_ordering::sparsevec_le
CREATE  FUNCTION "sparsevec_le"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_le_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am.rs:609
-- pgcontext::hnsw_am::_hnsw_sparse_masked_candidates
CREATE  FUNCTION "_hnsw_sparse_masked_candidates"(
	"index_relation" regclass, /* PgRelation */
	"query" SparseVec, /* SparseVec */
	"allowed_heap_tids" anyarray, /* AnyArray */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"heap_tid" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_sparse_masked_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:237
-- pgcontext::vector_variant_ordering::sparsevec_lt
CREATE  FUNCTION "sparsevec_lt"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_lt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:735
-- pgcontext::pgcontext::vector_variants::sparsevec_cosine_distance
CREATE  FUNCTION "sparsevec_cosine_distance"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_cosine_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:252
-- pgcontext::vector_variant_ordering::sparsevec_ne
CREATE  FUNCTION "sparsevec_ne"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_ne_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:257
-- pgcontext::vector_variant_ordering::sparsevec_ge
CREATE  FUNCTION "sparsevec_ge"(
	"left" SparseVec, /* SparseVec */
	"right" SparseVec /* SparseVec */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_ge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_ordering.rs:11
-- requires:
--   HalfVec
--   SparseVec
--   BitVec
--   halfvec_lt
--   halfvec_le
--   halfvec_eq
--   halfvec_ne
--   halfvec_ge
--   halfvec_gt
--   halfvec_cmp
--   sparsevec_lt
--   sparsevec_le
--   sparsevec_eq
--   sparsevec_ne
--   sparsevec_ge
--   sparsevec_gt
--   sparsevec_cmp
--   bitvec_lt
--   bitvec_le
--   bitvec_eq
--   bitvec_ne
--   bitvec_ge
--   bitvec_gt
--   bitvec_cmp


CREATE OPERATOR pgcontext.< (
    LEFTARG = halfvec,
    RIGHTARG = halfvec,
    FUNCTION = pgcontext.halfvec_lt,
    COMMUTATOR = OPERATOR(pgcontext.>),
    NEGATOR = OPERATOR(pgcontext.>=)
);
CREATE OPERATOR pgcontext.<= (
    LEFTARG = halfvec,
    RIGHTARG = halfvec,
    FUNCTION = pgcontext.halfvec_le,
    COMMUTATOR = OPERATOR(pgcontext.>=),
    NEGATOR = OPERATOR(pgcontext.>)
);
CREATE OPERATOR pgcontext.= (
    LEFTARG = halfvec,
    RIGHTARG = halfvec,
    FUNCTION = pgcontext.halfvec_eq,
    COMMUTATOR = OPERATOR(pgcontext.=),
    NEGATOR = OPERATOR(pgcontext.<>)
);
CREATE OPERATOR pgcontext.<> (
    LEFTARG = halfvec,
    RIGHTARG = halfvec,
    FUNCTION = pgcontext.halfvec_ne,
    COMMUTATOR = OPERATOR(pgcontext.<>),
    NEGATOR = OPERATOR(pgcontext.=)
);
CREATE OPERATOR pgcontext.>= (
    LEFTARG = halfvec,
    RIGHTARG = halfvec,
    FUNCTION = pgcontext.halfvec_ge,
    COMMUTATOR = OPERATOR(pgcontext.<=),
    NEGATOR = OPERATOR(pgcontext.<)
);
CREATE OPERATOR pgcontext.> (
    LEFTARG = halfvec,
    RIGHTARG = halfvec,
    FUNCTION = pgcontext.halfvec_gt,
    COMMUTATOR = OPERATOR(pgcontext.<),
    NEGATOR = OPERATOR(pgcontext.<=)
);
CREATE OPERATOR CLASS pgcontext.halfvec_ops
    DEFAULT FOR TYPE halfvec USING btree AS
    OPERATOR 1 pgcontext.< (halfvec, halfvec),
    OPERATOR 2 pgcontext.<= (halfvec, halfvec),
    OPERATOR 3 pgcontext.= (halfvec, halfvec),
    OPERATOR 4 pgcontext.>= (halfvec, halfvec),
    OPERATOR 5 pgcontext.> (halfvec, halfvec),
    FUNCTION 1 pgcontext.halfvec_cmp(halfvec, halfvec);

CREATE OPERATOR pgcontext.< (
    LEFTARG = sparsevec,
    RIGHTARG = sparsevec,
    FUNCTION = pgcontext.sparsevec_lt,
    COMMUTATOR = OPERATOR(pgcontext.>),
    NEGATOR = OPERATOR(pgcontext.>=)
);
CREATE OPERATOR pgcontext.<= (
    LEFTARG = sparsevec,
    RIGHTARG = sparsevec,
    FUNCTION = pgcontext.sparsevec_le,
    COMMUTATOR = OPERATOR(pgcontext.>=),
    NEGATOR = OPERATOR(pgcontext.>)
);
CREATE OPERATOR pgcontext.= (
    LEFTARG = sparsevec,
    RIGHTARG = sparsevec,
    FUNCTION = pgcontext.sparsevec_eq,
    COMMUTATOR = OPERATOR(pgcontext.=),
    NEGATOR = OPERATOR(pgcontext.<>)
);
CREATE OPERATOR pgcontext.<> (
    LEFTARG = sparsevec,
    RIGHTARG = sparsevec,
    FUNCTION = pgcontext.sparsevec_ne,
    COMMUTATOR = OPERATOR(pgcontext.<>),
    NEGATOR = OPERATOR(pgcontext.=)
);
CREATE OPERATOR pgcontext.>= (
    LEFTARG = sparsevec,
    RIGHTARG = sparsevec,
    FUNCTION = pgcontext.sparsevec_ge,
    COMMUTATOR = OPERATOR(pgcontext.<=),
    NEGATOR = OPERATOR(pgcontext.<)
);
CREATE OPERATOR pgcontext.> (
    LEFTARG = sparsevec,
    RIGHTARG = sparsevec,
    FUNCTION = pgcontext.sparsevec_gt,
    COMMUTATOR = OPERATOR(pgcontext.<),
    NEGATOR = OPERATOR(pgcontext.<=)
);
CREATE OPERATOR CLASS pgcontext.sparsevec_ops
    DEFAULT FOR TYPE sparsevec USING btree AS
    OPERATOR 1 pgcontext.< (sparsevec, sparsevec),
    OPERATOR 2 pgcontext.<= (sparsevec, sparsevec),
    OPERATOR 3 pgcontext.= (sparsevec, sparsevec),
    OPERATOR 4 pgcontext.>= (sparsevec, sparsevec),
    OPERATOR 5 pgcontext.> (sparsevec, sparsevec),
    FUNCTION 1 pgcontext.sparsevec_cmp(sparsevec, sparsevec);

CREATE OPERATOR pgcontext.< (
    LEFTARG = bitvec,
    RIGHTARG = bitvec,
    FUNCTION = pgcontext.bitvec_lt,
    COMMUTATOR = OPERATOR(pgcontext.>),
    NEGATOR = OPERATOR(pgcontext.>=)
);
CREATE OPERATOR pgcontext.<= (
    LEFTARG = bitvec,
    RIGHTARG = bitvec,
    FUNCTION = pgcontext.bitvec_le,
    COMMUTATOR = OPERATOR(pgcontext.>=),
    NEGATOR = OPERATOR(pgcontext.>)
);
CREATE OPERATOR pgcontext.= (
    LEFTARG = bitvec,
    RIGHTARG = bitvec,
    FUNCTION = pgcontext.bitvec_eq,
    COMMUTATOR = OPERATOR(pgcontext.=),
    NEGATOR = OPERATOR(pgcontext.<>)
);
CREATE OPERATOR pgcontext.<> (
    LEFTARG = bitvec,
    RIGHTARG = bitvec,
    FUNCTION = pgcontext.bitvec_ne,
    COMMUTATOR = OPERATOR(pgcontext.<>),
    NEGATOR = OPERATOR(pgcontext.=)
);
CREATE OPERATOR pgcontext.>= (
    LEFTARG = bitvec,
    RIGHTARG = bitvec,
    FUNCTION = pgcontext.bitvec_ge,
    COMMUTATOR = OPERATOR(pgcontext.<=),
    NEGATOR = OPERATOR(pgcontext.<)
);
CREATE OPERATOR pgcontext.> (
    LEFTARG = bitvec,
    RIGHTARG = bitvec,
    FUNCTION = pgcontext.bitvec_gt,
    COMMUTATOR = OPERATOR(pgcontext.<),
    NEGATOR = OPERATOR(pgcontext.<=)
);
CREATE OPERATOR CLASS pgcontext.bitvec_ops
    DEFAULT FOR TYPE bitvec USING btree AS
    OPERATOR 1 pgcontext.< (bitvec, bitvec),
    OPERATOR 2 pgcontext.<= (bitvec, bitvec),
    OPERATOR 3 pgcontext.= (bitvec, bitvec),
    OPERATOR 4 pgcontext.>= (bitvec, bitvec),
    OPERATOR 5 pgcontext.> (bitvec, bitvec),
    FUNCTION 1 pgcontext.bitvec_cmp(bitvec, bitvec);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:65
-- pgcontext::query_builders::query_sparse_nearest
CREATE  FUNCTION "query_sparse_nearest"(
	"vector_name" TEXT, /* String */
	"vector" SparseVec, /* SparseVec */
	"filter" jsonb, /* Option < JsonB > */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_sparse_nearest_filtered_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:478
-- pgcontext::pgcontext::vector_variants::sparsevec_from_real_array
CREATE  FUNCTION "sparsevec_from_real_array"(
	"values" real[] /* Vec < f32 > */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_from_real_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:865
-- pgcontext::pgcontext::vector_variants::sparsevec_sum_final
CREATE  FUNCTION "sparsevec_sum_final"(
	"state" real[] /* Vec < f32 > */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_sum_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:824
-- pgcontext::pgcontext::vector_variants::sparsevec_sum_transition
CREATE  FUNCTION "sparsevec_sum_transition"(
	"state" real[], /* :: std :: option :: Option < Vec < f32 > > */
	"value" SparseVec /* Option < SparseVec > */
) RETURNS real[] /* :: std :: option :: Option < Vec < f32 > > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_sum_transition_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:353
-- requires:
--   HalfVec
--   SparseVec
--   BitVec
--   halfvec_sum_transition
--   halfvec_sum_final
--   halfvec_avg_final
--   sparsevec_sum_transition
--   sparsevec_sum_final
--   sparsevec_avg_final
--   bitvec_or_transition
--   bitvec_and_transition
--   bitvec_bits_final


CREATE AGGREGATE pgcontext.sum(halfvec) (
    SFUNC = pgcontext.halfvec_sum_transition,
    STYPE = real[],
    FINALFUNC = pgcontext.halfvec_sum_final
);

CREATE AGGREGATE pgcontext.avg(halfvec) (
    SFUNC = pgcontext.halfvec_sum_transition,
    STYPE = real[],
    FINALFUNC = pgcontext.halfvec_avg_final
);

CREATE AGGREGATE pgcontext.sum(sparsevec) (
    SFUNC = pgcontext.sparsevec_sum_transition,
    STYPE = real[],
    FINALFUNC = pgcontext.sparsevec_sum_final
);

CREATE AGGREGATE pgcontext.avg(sparsevec) (
    SFUNC = pgcontext.sparsevec_sum_transition,
    STYPE = real[],
    FINALFUNC = pgcontext.sparsevec_avg_final
);

CREATE AGGREGATE pgcontext.bit_or(bitvec) (
    SFUNC = pgcontext.bitvec_or_transition,
    STYPE = boolean[],
    FINALFUNC = pgcontext.bitvec_bits_final
);

CREATE AGGREGATE pgcontext.bit_and(bitvec) (
    SFUNC = pgcontext.bitvec_and_transition,
    STYPE = boolean[],
    FINALFUNC = pgcontext.bitvec_bits_final
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:496
-- pgcontext::pgcontext::vector_variants::sparsevec_to_real_array
CREATE  FUNCTION "sparsevec_to_real_array"(
	"vector" SparseVec /* SparseVec */
) RETURNS real[] /* Vec < f32 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_to_real_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:113
-- pgcontext::vector_variant_typmods::sparsevec_typmod_in
CREATE  FUNCTION "sparsevec_typmod_in"(
	"modifiers" cstring[] /* Array < '_, & CStr > */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_typmod_in_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:120
-- pgcontext::vector_variant_typmods::sparsevec_typmod_out
CREATE  FUNCTION "sparsevec_typmod_out"(
	"typmod" INT /* i32 */
) RETURNS cstring /* CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_typmod_out_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:667
-- pgcontext::pgcontext::vector_variants::sparsevec_values
CREATE  FUNCTION "sparsevec_values"(
	"vector" SparseVec /* SparseVec */
) RETURNS real[] /* Vec < f32 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_values_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/build_jobs.rs:100
-- pgcontext::build_jobs::start_build_job
CREATE  FUNCTION "start_build_job"(
	"collection" TEXT, /* String */
	"artifact_kind" TEXT, /* String */
	"artifact_name" TEXT, /* String */
	"target_name" TEXT, /* String */
	"total_units" bigint /* i64 */
) RETURNS TABLE (
	"build_job_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" BuildJobStatus,  /* BuildJobStatus */
	"backend_pid" INT,  /* Option < i32 > */
	"attempt" INT,  /* i32 */
	"processed_units" bigint,  /* i64 */
	"total_units" bigint,  /* i64 */
	"cancel_requested" bool,  /* bool */
	"error_message" TEXT  /* Option < String > */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'start_build_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership.rs:54
-- pgcontext::pgvector_ownership::start_pgvector_ownership_conversion
CREATE  FUNCTION "start_pgvector_ownership_conversion"(
	"target" regclass, /* PgRelation */
	"column_name" TEXT, /* String */
	"mode" TEXT DEFAULT 'fast', /* String */
	"metric" TEXT DEFAULT 'cosine', /* String */
	"application_uses_column_lists" bool DEFAULT false, /* bool */
	"application_dependencies_reviewed" bool DEFAULT false /* bool */
) RETURNS TABLE (
	"conversion_id" bigint,  /* i64 */
	"mode" TEXT,  /* String */
	"status" TEXT,  /* String */
	"schema_name" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"column_name" TEXT,  /* String */
	"target_type" TEXT,  /* String */
	"total_rows" bigint,  /* i64 */
	"processed_rows" bigint,  /* i64 */
	"mismatch_count" bigint,  /* i64 */
	"validation_attestations" TEXT[],  /* Vec < String > */
	"next_command" TEXT,  /* Option < String > */
	"error_message" TEXT  /* Option < String > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'start_pgvector_ownership_conversion_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/telemetry.rs:30
-- pgcontext::telemetry::telemetry
CREATE  FUNCTION "telemetry"() RETURNS TABLE (
	"collection_name" TEXT,  /* String */
	"table_schema" TEXT,  /* Option < String > */
	"table_name" TEXT,  /* Option < String > */
	"has_source_table" bool,  /* bool */
	"source_table_exists" bool,  /* bool */
	"registered_vectors" bigint,  /* i64 */
	"active_points" bigint,  /* i64 */
	"deleted_points" bigint,  /* i64 */
	"filter_fields" bigint,  /* i64 */
	"hnsw_indexes" bigint,  /* i64 */
	"status" TelemetryStatus  /* TelemetryStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'telemetry_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/build_jobs.rs:203
-- pgcontext::build_jobs::update_build_job
CREATE  FUNCTION "update_build_job"(
	"build_job_id" bigint, /* i64 */
	"processed_units" bigint, /* i64 */
	"status" TEXT, /* String */
	"error_message" TEXT DEFAULT NULL /* Option < String > */
) RETURNS TABLE (
	"build_job_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"artifact_kind" TEXT,  /* String */
	"artifact_name" TEXT,  /* String */
	"target_name" TEXT,  /* String */
	"status" BuildJobStatus,  /* BuildJobStatus */
	"backend_pid" INT,  /* Option < i32 > */
	"attempt" INT,  /* i32 */
	"processed_units" bigint,  /* i64 */
	"total_units" bigint,  /* i64 */
	"cancel_requested" bool,  /* bool */
	"error_message" TEXT  /* Option < String > */
)
SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'update_build_job_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/embedding_migrations.rs:116
-- pgcontext::embedding_migrations::update_embedding_migration
CREATE  FUNCTION "update_embedding_migration"(
	"migration_id" bigint, /* i64 */
	"processed_points" bigint, /* i64 */
	"status" TEXT /* String */
) RETURNS TABLE (
	"migration_id" bigint,  /* i64 */
	"collection_name" TEXT,  /* String */
	"source_model" TEXT,  /* String */
	"source_version" TEXT,  /* String */
	"target_model" TEXT,  /* String */
	"target_version" TEXT,  /* String */
	"status" EmbeddingMigrationStatus,  /* EmbeddingMigrationStatus */
	"total_points" bigint,  /* i64 */
	"processed_points" bigint  /* i64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'update_embedding_migration_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/points.rs:58
-- pgcontext::points::upsert_points
CREATE  FUNCTION "upsert_points"(
	"collection_name" TEXT, /* String */
	"source_keys" TEXT[] /* Vec < String > */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"inserted" bool  /* bool */
)
STRICT SECURITY DEFINER
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'upsert_points_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/operations.rs:291
-- pgcontext::operations::vacuum_advice
CREATE  FUNCTION "vacuum_advice"(
	"index_name" TEXT /* String */
) RETURNS TABLE (
	"index_schema" TEXT,  /* String */
	"index_name" TEXT,  /* String */
	"table_schema" TEXT,  /* String */
	"table_name" TEXT,  /* String */
	"access_method" TEXT,  /* String */
	"estimated_index_tuples" bigint,  /* i64 */
	"index_pages" bigint,  /* i64 */
	"dead_table_tuples" bigint,  /* i64 */
	"status" VacuumAdviceStatus  /* VacuumAdviceStatus */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vacuum_advice_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:286
-- pgcontext::artifact_segments::validate_artifact_segment
CREATE  FUNCTION "validate_artifact_segment"(
	"segment" bytea /* Vec < u8 > */
) RETURNS TABLE (
	"kind" TEXT,  /* String */
	"payload_bytes" bigint,  /* i64 */
	"checksum" bigint  /* i64 */
)
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'validate_artifact_segment_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/artifact_segments.rs:316
-- pgcontext::artifact_segments::validate_hnsw_graph_artifact
CREATE  FUNCTION "validate_hnsw_graph_artifact"(
	"segment" bytea /* Vec < u8 > */
) RETURNS TABLE (
	"record_count" bigint,  /* i64 */
	"dimensions" INT,  /* i32 */
	"base_neighbor_count" bigint  /* i64 */
)
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'validate_hnsw_graph_artifact_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:91
-- Vector
CREATE TYPE Vector;

-- crates/context-pg/src/vector.rs:91
-- pgcontext::pgcontext::vector::vector_in
CREATE  FUNCTION "vector_in"(
	"input" cstring /* Option < & :: core :: ffi :: CStr > */
) RETURNS Vector /* Option < Vector > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_in_wrapper';

-- crates/context-pg/src/vector.rs:91
-- pgcontext::pgcontext::vector::vector_out
CREATE  FUNCTION "vector_out"(
	"input" Vector /* Vector */
) RETURNS cstring /* :: pgrx :: ffi :: CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_out_wrapper';

-- crates/context-pg/src/vector.rs:91
-- Vector
CREATE TYPE Vector (
	INTERNALLENGTH = variable,
	INPUT = vector_in, /* pgcontext::pgcontext::vector::vector_in */
	OUTPUT = vector_out, /* pgcontext::pgcontext::vector::vector_out */
	STORAGE = extended
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/late_interaction_catalog_schema.rs:9
-- requires:
--   Vector
--   create_catalog_tables


CREATE TABLE pgcontext._collection_late_interaction (
    collection_id bigint PRIMARY KEY
        REFERENCES pgcontext._collections(collection_id) ON DELETE CASCADE,
    source_table_oid oid NOT NULL,
    source_schema_name text NOT NULL,
    source_table_name text NOT NULL,
    token_column_name text NOT NULL,
    token_attnum int2 NOT NULL,
    dimensions int4,
    hnsw_index_oid oid,
    point_count bigint NOT NULL DEFAULT 0 CHECK (point_count >= 0),
    token_count bigint NOT NULL DEFAULT 0 CHECK (token_count >= 0),
    status text NOT NULL DEFAULT 'building'
        CHECK (status IN ('building', 'ready', 'stale', 'failed')),
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    CHECK (dimensions IS NULL OR dimensions > 0),
    CHECK ((status = 'ready') = (dimensions IS NOT NULL AND hnsw_index_oid IS NOT NULL))
);

ALTER TABLE pgcontext._collection_points
    ADD CONSTRAINT pgcontext_collection_points_collection_point_unique
    UNIQUE (collection_id, point_id);

CREATE TABLE pgcontext._collection_late_interaction_tokens (
    token_id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    collection_id bigint NOT NULL,
    point_id bigint NOT NULL,
    token_ordinal int4 NOT NULL CHECK (token_ordinal > 0),
    token_vector vector NOT NULL,
    created_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    updated_at timestamptz NOT NULL DEFAULT pg_catalog.now(),
    FOREIGN KEY (collection_id, point_id)
        REFERENCES pgcontext._collection_points(collection_id, point_id)
        ON DELETE CASCADE,
    UNIQUE (collection_id, point_id, token_ordinal)
);

CREATE VIEW pgcontext._visible_collection_late_interaction
WITH (security_barrier = true) AS
SELECT registrations.*
  FROM pgcontext._collection_late_interaction AS registrations
  JOIN pgcontext._collections AS collections USING (collection_id)
 WHERE pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');

GRANT SELECT ON pgcontext._visible_collection_late_interaction TO PUBLIC;

CREATE FUNCTION pgcontext._capture_late_interaction_tokens()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    registration pgcontext._collection_late_interaction%ROWTYPE;
    selected_record record;
    current_source_key text;
    previous_source_key text;
    token_vectors pgcontext.vector[];
    point bigint;
    minimum_dimensions int4;
    maximum_dimensions int4;
    deleted_token_count bigint;
    replacement_token_count bigint;
BEGIN
    SELECT *
      INTO registration
      FROM pgcontext._collection_late_interaction
     WHERE collection_id = TG_ARGV[0]::bigint;

    IF NOT FOUND OR registration.source_table_oid <> TG_RELID THEN
        RAISE EXCEPTION 'late-interaction source trigger binding is stale for relation %', TG_RELID
            USING ERRCODE = '55000';
    END IF;

    IF TG_OP IN ('UPDATE', 'DELETE') THEN
        previous_source_key := pg_catalog.to_jsonb(OLD)->>'id';
        IF previous_source_key IS NULL OR previous_source_key = '' THEN
            RAISE EXCEPTION 'late-interaction source key id must not be null or empty'
                USING ERRCODE = '22023';
        END IF;
    END IF;

    IF TG_OP = 'DELETE' THEN
        DELETE FROM pgcontext._collection_late_interaction_tokens AS tokens
         USING pgcontext._collection_points AS points
         WHERE tokens.collection_id = registration.collection_id
           AND tokens.point_id = points.point_id
           AND points.collection_id = registration.collection_id
           AND points.source_key = previous_source_key;
        GET DIAGNOSTICS deleted_token_count = ROW_COUNT;

        IF deleted_token_count > 0 THEN
            UPDATE pgcontext._collection_late_interaction
               SET point_count = point_count - 1,
                   token_count = token_count - deleted_token_count,
                   updated_at = pg_catalog.now()
             WHERE collection_id = registration.collection_id;
        END IF;

        UPDATE pgcontext._collection_points
           SET deleted_at = coalesce(deleted_at, pg_catalog.now()),
               updated_at = pg_catalog.now()
         WHERE collection_id = registration.collection_id
           AND source_key = previous_source_key;
        RETURN OLD;
    END IF;

    current_source_key := pg_catalog.to_jsonb(NEW)->>'id';
    IF current_source_key IS NULL OR current_source_key = '' THEN
        RAISE EXCEPTION 'late-interaction source key id must not be null or empty'
            USING ERRCODE = '22023';
    END IF;

    EXECUTE pg_catalog.format(
        'SELECT ($1).%I::pgcontext.vector[] AS token_vectors',
        registration.token_column_name
    )
    INTO selected_record
    USING NEW;
    token_vectors := selected_record.token_vectors;

    IF token_vectors IS NULL
       OR pg_catalog.cardinality(token_vectors) = 0
       OR pg_catalog.array_position(token_vectors, NULL) IS NOT NULL THEN
        RAISE EXCEPTION 'late-interaction token source must contain at least one non-null vector for source key %', current_source_key
            USING ERRCODE = '22023';
    END IF;
    IF pg_catalog.cardinality(token_vectors) > 16384 THEN
        RAISE EXCEPTION 'late-interaction token count exceeds per-point limit 16384 for source key %', current_source_key
            USING ERRCODE = '54000';
    END IF;

    SELECT pg_catalog.min(pgcontext.vector_dims(token)),
           pg_catalog.max(pgcontext.vector_dims(token))
      INTO minimum_dimensions, maximum_dimensions
      FROM pg_catalog.unnest(token_vectors) AS token;
    IF minimum_dimensions IS NULL OR minimum_dimensions <> maximum_dimensions THEN
        RAISE EXCEPTION 'late-interaction token dimensions must be uniform for source key %', current_source_key
            USING ERRCODE = '22023';
    END IF;
    IF registration.dimensions IS NOT NULL
       AND registration.dimensions <> minimum_dimensions THEN
        RAISE EXCEPTION 'late-interaction token dimension mismatch: expected %, found % for source key %',
            registration.dimensions,
            minimum_dimensions,
            current_source_key
            USING ERRCODE = '22023';
    END IF;

    IF TG_OP = 'UPDATE' AND previous_source_key <> current_source_key THEN
        DELETE FROM pgcontext._collection_late_interaction_tokens AS tokens
         USING pgcontext._collection_points AS points
         WHERE tokens.collection_id = registration.collection_id
           AND tokens.point_id = points.point_id
           AND points.collection_id = registration.collection_id
           AND points.source_key = previous_source_key;
        GET DIAGNOSTICS deleted_token_count = ROW_COUNT;
        IF deleted_token_count > 0 THEN
            UPDATE pgcontext._collection_late_interaction
               SET point_count = point_count - 1,
                   token_count = token_count - deleted_token_count,
                   updated_at = pg_catalog.now()
             WHERE collection_id = registration.collection_id;
        END IF;
        UPDATE pgcontext._collection_points
           SET deleted_at = coalesce(deleted_at, pg_catalog.now()),
               updated_at = pg_catalog.now()
         WHERE collection_id = registration.collection_id
           AND source_key = previous_source_key;
    END IF;

    INSERT INTO pgcontext._collection_points (collection_id, source_key)
    VALUES (registration.collection_id, current_source_key)
    ON CONFLICT (collection_id, source_key) DO UPDATE
        SET deleted_at = NULL,
            updated_at = pg_catalog.now()
    RETURNING point_id INTO point;

    DELETE FROM pgcontext._collection_late_interaction_tokens
     WHERE collection_id = registration.collection_id
       AND point_id = point;
    GET DIAGNOSTICS replacement_token_count = ROW_COUNT;
    INSERT INTO pgcontext._collection_late_interaction_tokens (
        collection_id,
        point_id,
        token_ordinal,
        token_vector
    )
    SELECT registration.collection_id,
           point,
           ordinal::int4,
           token
      FROM pg_catalog.unnest(token_vectors) WITH ORDINALITY AS expanded(token, ordinal);

    UPDATE pgcontext._collection_late_interaction
       SET dimensions = coalesce(dimensions, minimum_dimensions),
           point_count = point_count + CASE WHEN replacement_token_count = 0 THEN 1 ELSE 0 END,
           token_count = token_count
               - replacement_token_count
               + pg_catalog.cardinality(token_vectors),
           updated_at = pg_catalog.now()
     WHERE collection_id = registration.collection_id;
    RETURN NEW;
END;
$$;

CREATE FUNCTION pgcontext._begin_late_interaction_registration(
    p_collection_id bigint,
    p_source_table_oid oid,
    p_source_schema_name text,
    p_source_table_name text,
    p_token_column_name text,
    p_token_attnum int2
)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    trigger_name text;
BEGIN
    IF NOT EXISTS (
        SELECT 1
          FROM pgcontext._collections AS collections
          JOIN pg_catalog.pg_class AS source_class
            ON source_class.oid = collections.source_table_oid
          JOIN pg_catalog.pg_namespace AS source_namespace
            ON source_namespace.oid = source_class.relnamespace
          JOIN pg_catalog.pg_attribute AS token_attribute
            ON token_attribute.attrelid = source_class.oid
           AND token_attribute.attname = p_token_column_name
           AND token_attribute.attnum = p_token_attnum
           AND token_attribute.attnum > 0
           AND NOT token_attribute.attisdropped
         WHERE collections.collection_id = p_collection_id
           AND pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER')
           AND source_class.oid = p_source_table_oid
           AND source_namespace.nspname = p_source_schema_name
           AND source_class.relname = p_source_table_name
           AND source_class.relkind = 'r'
           AND token_attribute.atttypid = 'pgcontext.vector[]'::pg_catalog.regtype
    ) THEN
        RAISE EXCEPTION 'invalid or unauthorized late-interaction registration for collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;
    IF NOT pg_catalog.has_table_privilege(SESSION_USER, p_source_table_oid, 'SELECT') THEN
        RAISE EXCEPTION 'permission denied for late-interaction source table %.%',
            p_source_schema_name,
            p_source_table_name
            USING ERRCODE = '42501';
    END IF;

    INSERT INTO pgcontext._collection_late_interaction (
        collection_id,
        source_table_oid,
        source_schema_name,
        source_table_name,
        token_column_name,
        token_attnum
    )
    VALUES (
        p_collection_id,
        p_source_table_oid,
        p_source_schema_name,
        p_source_table_name,
        p_token_column_name,
        p_token_attnum
    );

    trigger_name := pg_catalog.format('pgcontext_late_interaction_%s', p_collection_id);
    EXECUTE pg_catalog.format(
        'CREATE TRIGGER %I AFTER INSERT OR UPDATE OF id, %I OR DELETE ON %I.%I '
        'FOR EACH ROW EXECUTE FUNCTION pgcontext._capture_late_interaction_tokens(%L)',
        trigger_name,
        p_token_column_name,
        p_source_schema_name,
        p_source_table_name,
        p_collection_id::text
    );
END;
$$;

CREATE FUNCTION pgcontext._store_late_interaction_tokens(
    p_collection_id bigint,
    p_source_key text
)
RETURNS bigint
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    registration pgcontext._collection_late_interaction%ROWTYPE;
    point bigint;
    minimum_dimensions int4;
    maximum_dimensions int4;
    replacement_token_count bigint;
    token_vectors pgcontext.vector[];
    loaded_row_count bigint;
BEGIN
    SELECT registrations.*
      INTO registration
      FROM pgcontext._collection_late_interaction AS registrations
      JOIN pgcontext._collections AS collections USING (collection_id)
     WHERE registrations.collection_id = p_collection_id
       AND pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER');
    IF NOT FOUND
       OR NOT pg_catalog.has_table_privilege(
           SESSION_USER,
           registration.source_table_oid,
           'SELECT'
       ) THEN
        RAISE EXCEPTION 'permission denied for late-interaction collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;
    IF p_source_key IS NULL OR p_source_key = '' THEN
        RAISE EXCEPTION 'late-interaction source key must not be null or empty'
            USING ERRCODE = '22023';
    END IF;

    EXECUTE pg_catalog.format(
        'SELECT source.%I::pgcontext.vector[]
           FROM %I.%I AS source
          WHERE source.id::text = $1
          LIMIT 1',
        registration.token_column_name,
        registration.source_schema_name,
        registration.source_table_name
    ) INTO token_vectors USING p_source_key;
    GET DIAGNOSTICS loaded_row_count = ROW_COUNT;
    IF loaded_row_count = 0 THEN
        RAISE EXCEPTION 'late-interaction source row does not exist for source key %', p_source_key
            USING ERRCODE = '42704';
    END IF;
    IF token_vectors IS NULL
       OR pg_catalog.cardinality(token_vectors) = 0
       OR pg_catalog.array_position(token_vectors, NULL) IS NOT NULL THEN
        RAISE EXCEPTION 'late-interaction token source must contain at least one non-null vector for source key %', p_source_key
            USING ERRCODE = '22023';
    END IF;
    IF pg_catalog.cardinality(token_vectors) > 16384 THEN
        RAISE EXCEPTION 'late-interaction token count exceeds per-point limit 16384 for source key %', p_source_key
            USING ERRCODE = '54000';
    END IF;

    SELECT pg_catalog.min(pgcontext.vector_dims(token)),
           pg_catalog.max(pgcontext.vector_dims(token))
      INTO minimum_dimensions, maximum_dimensions
      FROM pg_catalog.unnest(token_vectors) AS token;
    IF minimum_dimensions IS NULL OR minimum_dimensions <> maximum_dimensions THEN
        RAISE EXCEPTION 'late-interaction token dimensions must be uniform for source key %', p_source_key
            USING ERRCODE = '22023';
    END IF;
    IF registration.dimensions IS NOT NULL
       AND registration.dimensions <> minimum_dimensions THEN
        RAISE EXCEPTION 'late-interaction token dimension mismatch: expected %, found % for source key %',
            registration.dimensions,
            minimum_dimensions,
            p_source_key
            USING ERRCODE = '22023';
    END IF;

    INSERT INTO pgcontext._collection_points (collection_id, source_key)
    VALUES (p_collection_id, p_source_key)
    ON CONFLICT (collection_id, source_key) DO UPDATE
        SET updated_at = pg_catalog.now()
    RETURNING point_id INTO point;

    DELETE FROM pgcontext._collection_late_interaction_tokens
     WHERE collection_id = p_collection_id
       AND point_id = point;
    GET DIAGNOSTICS replacement_token_count = ROW_COUNT;
    INSERT INTO pgcontext._collection_late_interaction_tokens (
        collection_id,
        point_id,
        token_ordinal,
        token_vector
    )
    SELECT p_collection_id,
           point,
           ordinal::int4,
           token
      FROM pg_catalog.unnest(token_vectors) WITH ORDINALITY AS expanded(token, ordinal);

    UPDATE pgcontext._collection_late_interaction
       SET dimensions = coalesce(dimensions, minimum_dimensions),
           point_count = point_count + CASE WHEN replacement_token_count = 0 THEN 1 ELSE 0 END,
           token_count = token_count
               - replacement_token_count
               + pg_catalog.cardinality(token_vectors),
           updated_at = pg_catalog.now()
     WHERE collection_id = p_collection_id;
    RETURN point;
END;
$$;

CREATE FUNCTION pgcontext._finish_late_interaction_registration(
    p_collection_id bigint,
    p_dimensions int4
)
RETURNS oid
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    index_name text;
    index_oid oid;
BEGIN
    IF p_dimensions <= 0 OR NOT EXISTS (
        SELECT 1
          FROM pgcontext._collection_late_interaction AS registrations
          JOIN pgcontext._collections AS collections USING (collection_id)
         WHERE registrations.collection_id = p_collection_id
           AND registrations.dimensions = p_dimensions
           AND pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER')
    ) THEN
        RAISE EXCEPTION 'invalid or unauthorized late-interaction finalization for collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;

    index_name := pg_catalog.format('pgcontext_late_interaction_%s_hnsw', p_collection_id);
    EXECUTE pg_catalog.format(
        'CREATE INDEX %I ON pgcontext._collection_late_interaction_tokens '
        'USING pgcontext_hnsw ((token_vector::pgcontext.vector(%s)) pgcontext.vector_hnsw_ip_ops) '
        'WHERE collection_id = %s',
        index_name,
        p_dimensions,
        p_collection_id
    );
    index_oid := pg_catalog.to_regclass(
        pg_catalog.format('pgcontext.%I', index_name)
    )::oid;
    UPDATE pgcontext._collection_late_interaction
       SET hnsw_index_oid = index_oid,
           status = 'ready',
           updated_at = pg_catalog.now()
     WHERE collection_id = p_collection_id;
    RETURN index_oid;
END;
$$;

CREATE FUNCTION pgcontext._late_interaction_ann_candidate_points(
    p_collection_id bigint,
    p_query vector,
    p_limit int4
)
RETURNS TABLE (point_id bigint)
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    registration pgcontext._collection_late_interaction%ROWTYPE;
    previous_enable_seqscan text;
BEGIN
    IF p_limit IS NULL OR p_limit <= 0 THEN
        RAISE EXCEPTION 'late-interaction ANN candidate limit must be positive'
            USING ERRCODE = '22023';
    END IF;

    SELECT registrations.*
      INTO registration
      FROM pgcontext._collection_late_interaction AS registrations
      JOIN pgcontext._collections AS collections USING (collection_id)
      JOIN pg_catalog.pg_index AS index_metadata
        ON index_metadata.indexrelid = registrations.hnsw_index_oid
      JOIN pg_catalog.pg_class AS index_class
        ON index_class.oid = index_metadata.indexrelid
      JOIN pg_catalog.pg_am AS access_method
        ON access_method.oid = index_class.relam
      JOIN pg_catalog.pg_opclass AS operator_class
        ON operator_class.oid = index_metadata.indclass[0]
      JOIN pg_catalog.pg_namespace AS operator_namespace
        ON operator_namespace.oid = operator_class.opcnamespace
     WHERE registrations.collection_id = p_collection_id
       AND pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER')
       AND registrations.status = 'ready'
       AND registrations.dimensions IS NOT NULL
       AND index_metadata.indrelid = 'pgcontext._collection_late_interaction_tokens'::regclass
       AND index_metadata.indisvalid
       AND index_metadata.indisready
       AND access_method.amname = 'pgcontext_hnsw'
       AND index_class.relname = pg_catalog.format(
           'pgcontext_late_interaction_%s_hnsw',
           registrations.collection_id
       )
       AND index_metadata.indnkeyatts = 1
       AND index_metadata.indnatts = 1
       AND operator_namespace.nspname = 'pgcontext'
       AND operator_class.opcname = 'vector_hnsw_ip_ops'
       AND pg_catalog.regexp_replace(
           pg_catalog.pg_get_expr(
               index_metadata.indpred,
               index_metadata.indrelid,
               true
           ),
           '[()[:space:]]',
           '',
           'g'
       ) = pg_catalog.format('collection_id=%s', registrations.collection_id)
       AND pg_catalog.regexp_replace(
           pg_catalog.pg_get_indexdef(index_metadata.indexrelid, 1, true),
           '[()[:space:]]',
           '',
           'g'
       ) IN (
           pg_catalog.format('token_vector::vector%s', registrations.dimensions),
           pg_catalog.format('token_vector::pgcontext.vector%s', registrations.dimensions)
       );
    IF NOT FOUND THEN
        RAISE EXCEPTION 'late-interaction ANN generation is not ready or is unauthorized for collection %', p_collection_id
            USING ERRCODE = '55000';
    END IF;
    IF pgcontext.vector_dims(p_query) <> registration.dimensions THEN
        RAISE EXCEPTION 'late-interaction query dimension mismatch: expected %, found %',
            registration.dimensions,
            pgcontext.vector_dims(p_query)
            USING ERRCODE = '22023';
    END IF;

    previous_enable_seqscan := pg_catalog.current_setting('enable_seqscan');
    PERFORM pg_catalog.set_config('enable_seqscan', 'off', true);
    BEGIN
        RETURN QUERY EXECUTE pg_catalog.format(
            'SELECT tokens.point_id
               FROM pgcontext._collection_late_interaction_tokens AS tokens
              WHERE tokens.collection_id = $1
              ORDER BY (tokens.token_vector::pgcontext.vector(%s)) OPERATOR(pgcontext.<#>) $2
              LIMIT $3',
            registration.dimensions
        ) USING p_collection_id, p_query, p_limit;
    EXCEPTION WHEN others THEN
        PERFORM pg_catalog.set_config('enable_seqscan', previous_enable_seqscan, true);
        RAISE;
    END;
    PERFORM pg_catalog.set_config('enable_seqscan', previous_enable_seqscan, true);
END;
$$;

CREATE FUNCTION pgcontext._prepare_late_interaction_repair(
    p_collection_id bigint,
    p_source_table_oid oid,
    p_token_attnum int2
)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    registration pgcontext._collection_late_interaction%ROWTYPE;
    trigger_name text;
    index_name text;
BEGIN
    SELECT registrations.*
      INTO registration
      FROM pgcontext._collection_late_interaction AS registrations
      JOIN pgcontext._collections AS collections USING (collection_id)
      JOIN pg_catalog.pg_class AS source_class
        ON source_class.oid = p_source_table_oid
      JOIN pg_catalog.pg_namespace AS source_namespace
        ON source_namespace.oid = source_class.relnamespace
      JOIN pg_catalog.pg_attribute AS token_attribute
        ON token_attribute.attrelid = source_class.oid
       AND token_attribute.attname = registrations.token_column_name
       AND token_attribute.attnum = p_token_attnum
       AND token_attribute.attnum > 0
       AND NOT token_attribute.attisdropped
     WHERE registrations.collection_id = p_collection_id
       AND collections.source_table_oid = p_source_table_oid
       AND pg_catalog.pg_has_role(SESSION_USER, collections.owner_role, 'MEMBER')
       AND source_namespace.nspname = registrations.source_schema_name
       AND source_class.relname = registrations.source_table_name
       AND source_class.relkind = 'r'
       AND token_attribute.atttypid = 'pgcontext.vector[]'::pg_catalog.regtype;
    IF NOT FOUND OR NOT pg_catalog.has_table_privilege(
        SESSION_USER,
        p_source_table_oid,
        'SELECT'
    ) THEN
        RAISE EXCEPTION 'invalid or unauthorized late-interaction repair for collection %', p_collection_id
            USING ERRCODE = '42501';
    END IF;

    trigger_name := pg_catalog.format('pgcontext_late_interaction_%s', p_collection_id);
    EXECUTE pg_catalog.format(
        'DROP TRIGGER IF EXISTS %I ON %I.%I',
        trigger_name,
        registration.source_schema_name,
        registration.source_table_name
    );
    index_name := pg_catalog.format('pgcontext_late_interaction_%s_hnsw', p_collection_id);
    EXECUTE pg_catalog.format('DROP INDEX IF EXISTS pgcontext.%I', index_name);

    DELETE FROM pgcontext._collection_late_interaction_tokens
     WHERE collection_id = p_collection_id;
    UPDATE pgcontext._collection_late_interaction
       SET source_table_oid = p_source_table_oid,
           token_attnum = p_token_attnum,
           dimensions = NULL,
           hnsw_index_oid = NULL,
           point_count = 0,
           token_count = 0,
           status = 'building',
           updated_at = pg_catalog.now()
     WHERE collection_id = p_collection_id;

    EXECUTE pg_catalog.format(
        'CREATE TRIGGER %I AFTER INSERT OR UPDATE OF id, %I OR DELETE ON %I.%I '
        'FOR EACH ROW EXECUTE FUNCTION pgcontext._capture_late_interaction_tokens(%L)',
        trigger_name,
        registration.token_column_name,
        registration.source_schema_name,
        registration.source_table_name,
        p_collection_id::text
    );
END;
$$;

CREATE FUNCTION pgcontext._cleanup_late_interaction_registration()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = pg_catalog, pgcontext
AS $$
DECLARE
    registration pgcontext._collection_late_interaction%ROWTYPE;
    trigger_name text;
    index_name text;
    current_schema_name text;
    current_table_name text;
BEGIN
    SELECT *
      INTO registration
      FROM pgcontext._collection_late_interaction
     WHERE collection_id = OLD.collection_id;
    IF NOT FOUND THEN
        RETURN OLD;
    END IF;

    trigger_name := pg_catalog.format(
        'pgcontext_late_interaction_%s',
        OLD.collection_id
    );
    SELECT namespace.nspname, source_class.relname
      INTO current_schema_name, current_table_name
      FROM pg_catalog.pg_class AS source_class
      JOIN pg_catalog.pg_namespace AS namespace
        ON namespace.oid = source_class.relnamespace
     WHERE source_class.oid = registration.source_table_oid;
    IF FOUND THEN
        EXECUTE pg_catalog.format(
            'DROP TRIGGER IF EXISTS %I ON %I.%I',
            trigger_name,
            current_schema_name,
            current_table_name
        );
    END IF;

    index_name := pg_catalog.format(
        'pgcontext_late_interaction_%s_hnsw',
        OLD.collection_id
    );
    EXECUTE pg_catalog.format('DROP INDEX IF EXISTS pgcontext.%I', index_name);
    RETURN OLD;
END;
$$;

CREATE TRIGGER pgcontext_cleanup_late_interaction_registration
BEFORE DELETE ON pgcontext._collections
FOR EACH ROW
EXECUTE FUNCTION pgcontext._cleanup_late_interaction_registration();

SELECT pg_catalog.pg_extension_config_dump(
    'pgcontext._collection_late_interaction',
    ''
);
SELECT pg_catalog.pg_extension_config_dump(
    'pgcontext._collection_late_interaction_tokens',
    ''
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:323
-- requires:
--   Vector
--   HalfVec
--   SparseVec
--   BitVec
--   halfvec_l2_distance
--   halfvec_negative_inner_product
--   halfvec_cosine_distance
--   halfvec_l1_distance
--   sparsevec_l2_distance
--   sparsevec_negative_inner_product
--   sparsevec_cosine_distance
--   sparsevec_l1_distance
--   bitvec_hamming_distance
--   bitvec_jaccard_distance


CREATE OPERATOR pgcontext.<#> (LEFTARG = halfvec, RIGHTARG = halfvec, FUNCTION = pgcontext.halfvec_negative_inner_product, COMMUTATOR = OPERATOR(pgcontext.<#>));
CREATE OPERATOR pgcontext.<=> (LEFTARG = halfvec, RIGHTARG = halfvec, FUNCTION = pgcontext.halfvec_cosine_distance, COMMUTATOR = OPERATOR(pgcontext.<=>));
CREATE OPERATOR pgcontext.<+> (LEFTARG = halfvec, RIGHTARG = halfvec, FUNCTION = pgcontext.halfvec_l1_distance, COMMUTATOR = OPERATOR(pgcontext.<+>));
CREATE OPERATOR pgcontext.<#> (LEFTARG = sparsevec, RIGHTARG = sparsevec, FUNCTION = pgcontext.sparsevec_negative_inner_product, COMMUTATOR = OPERATOR(pgcontext.<#>));
CREATE OPERATOR pgcontext.<=> (LEFTARG = sparsevec, RIGHTARG = sparsevec, FUNCTION = pgcontext.sparsevec_cosine_distance, COMMUTATOR = OPERATOR(pgcontext.<=>));
CREATE OPERATOR pgcontext.<+> (LEFTARG = sparsevec, RIGHTARG = sparsevec, FUNCTION = pgcontext.sparsevec_l1_distance, COMMUTATOR = OPERATOR(pgcontext.<+>));
CREATE OPERATOR pgcontext.<%> (LEFTARG = bitvec, RIGHTARG = bitvec, FUNCTION = pgcontext.bitvec_jaccard_distance, COMMUTATOR = OPERATOR(pgcontext.<%>));
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_datum.rs:209
-- requires:
--   pgcontext_bootstrap
--   Vector


CREATE FUNCTION pgcontext._l2_distance_fast(pgcontext.vector, pgcontext.vector)
RETURNS real
AS 'MODULE_PATHNAME', 'pgcontext_l2_distance_fast'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION pgcontext._l2_distance_fast8(pgcontext.vector, pgcontext.vector)
RETURNS double precision
AS 'MODULE_PATHNAME', 'pgcontext_l2_distance_fast8'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION pgcontext._negative_inner_product_fast(pgcontext.vector, pgcontext.vector)
RETURNS real
AS 'MODULE_PATHNAME', 'pgcontext_negative_inner_product_fast'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION pgcontext._cosine_distance_fast(pgcontext.vector, pgcontext.vector)
RETURNS real
AS 'MODULE_PATHNAME', 'pgcontext_cosine_distance_fast'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION pgcontext._l1_distance_fast(pgcontext.vector, pgcontext.vector)
RETURNS real
AS 'MODULE_PATHNAME', 'pgcontext_l1_distance_fast'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:183
-- requires:
--   Vector
--   create_vector_fast_distance_functions


CREATE OPERATOR pgcontext.<#> (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext._negative_inner_product_fast,
    COMMUTATOR = OPERATOR(pgcontext.<#>)
);

CREATE OPERATOR pgcontext.<=> (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext._cosine_distance_fast,
    COMMUTATOR = OPERATOR(pgcontext.<=>)
);

CREATE OPERATOR pgcontext.<+> (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext._l1_distance_fast,
    COMMUTATOR = OPERATOR(pgcontext.<+>)
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:462
-- pgcontext::pgcontext::vector::vector_gt
CREATE  FUNCTION "vector_gt"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_gt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/grouped.rs:68
-- pgcontext::table_search::grouped::grouped_search
CREATE  FUNCTION "grouped_search"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"group_by" TEXT, /* String */
	"group_limit" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"group_value" TEXT,  /* String */
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'grouped_search_collection_named_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:563
-- pgcontext::pgcontext::vector::l1_distance
CREATE  FUNCTION "l1_distance"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'l1_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:110
-- pgcontext::query_builders::query_late_interaction
CREATE  FUNCTION "query_late_interaction"(
	"query_vectors" Vector[], /* Vec < Vector > */
	"candidates_per_query" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_late_interaction_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/named.rs:16
-- pgcontext::table_search::named::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_named_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/candidate_recheck.rs:172
-- pgcontext::table_search::candidate_recheck::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"filter" TEXT, /* Option < String > */
	"candidate_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_filtered_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/candidate_recheck.rs:122
-- pgcontext::table_search::candidate_recheck::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"candidate_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_named_vector_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query/late_interaction_ann.rs:709
-- pgcontext::hybrid_query::late_interaction_ann::search_late_interaction_ann
CREATE  FUNCTION "search_late_interaction_ann"(
	"collection" TEXT, /* String */
	"query_vectors" Vector[], /* Vec < Vector > */
	"vector_column" TEXT, /* String */
	"token_table" TEXT, /* String */
	"token_source_key_column" TEXT, /* String */
	"token_vector_column" TEXT, /* String */
	"candidates_per_query" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" double precision  /* f64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_late_interaction_ann_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/quantization_sql.rs:17
-- pgcontext::quantization_sql::binary_quantize
CREATE  FUNCTION "binary_quantize"(
	"vector" Vector /* Vector */
) RETURNS BitVec /* BitVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'binary_quantize_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/candidate_recheck.rs:276
-- pgcontext::table_search::candidate_recheck::search_mmap_hnsw_artifact
CREATE  FUNCTION "search_mmap_hnsw_artifact"(
	"collection" TEXT, /* String */
	"artifact_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"max_mapped_bytes" bigint, /* i64 */
	"candidate_limit" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_mmap_hnsw_artifact_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/quantization_sql.rs:54
-- pgcontext::quantization_sql::product_quantize
CREATE  FUNCTION "product_quantize"(
	"vector" Vector, /* Vector */
	"subvector_dimensions" INT, /* i32 */
	"codebooks" jsonb /* JsonB */
) RETURNS bytea /* Vec < u8 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'product_quantize_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:438
-- pgcontext::pgcontext::vector::vector_le
CREATE  FUNCTION "vector_le"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_le_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:422
-- pgcontext::pgcontext::vector::vector_cmp
CREATE  FUNCTION "vector_cmp"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_cmp_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/quantization_sql.rs:27
-- pgcontext::quantization_sql::scalar_quantize
CREATE  FUNCTION "scalar_quantize"(
	"vector" Vector, /* Vector */
	"min" real, /* f32 */
	"max" real, /* f32 */
	"levels" INT /* i32 */
) RETURNS bytea /* Vec < u8 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'scalar_quantize_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/candidate_recheck.rs:420
-- pgcontext::table_search::candidate_recheck::_mmap_hnsw_artifact_candidates
CREATE  FUNCTION "_mmap_hnsw_artifact_candidates"(
	"collection" TEXT, /* String */
	"artifact_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"max_mapped_bytes" bigint, /* i64 */
	"candidate_limit" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"score" real,  /* f32 */
	"generation_high_water" bigint  /* i64 */
)
STRICT SECURITY DEFINER 
SET search_path TO pg_catalog, pgcontext
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'mmap_hnsw_artifact_candidates_internal_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query.rs:70
-- pgcontext::hybrid_query::query
CREATE  FUNCTION "query"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"text_query" TEXT, /* String */
	"text_column" TEXT, /* String */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" double precision  /* f64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:611
-- pgcontext::pgcontext::vector::rerank_quantized_candidates
CREATE  FUNCTION "rerank_quantized_candidates"(
	"query" Vector, /* Vector */
	"point_ids" bigint[], /* Vec < i64 > */
	"original_vectors" Vector[], /* Vec < Vector > */
	"metric" TEXT, /* String */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"score" real  /* f32 */
)
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'rerank_quantized_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:507
-- pgcontext::pgcontext::vector_variants::sparsevec_from_vector
CREATE  FUNCTION "sparsevec_from_vector"(
	"vector" Vector /* Vector */
) RETURNS SparseVec /* SparseVec */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_from_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:572
-- pgcontext::pgcontext::vector::search
CREATE  FUNCTION "search"(
	"query" Vector, /* Vector */
	"point_ids" bigint[], /* Vec < i64 > */
	"vectors" Vector[], /* Vec < Vector > */
	"metric" TEXT, /* String */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"score" real  /* f32 */
)
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query.rs:122
-- pgcontext::hybrid_query::query
CREATE  FUNCTION "query"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"sparse_vector_name" TEXT, /* String */
	"sparse_query" SparseVec, /* SparseVec */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" double precision  /* f64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_collection_dense_sparse_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am.rs:225
-- pgcontext::hnsw_am::hnsw_l2_distance
CREATE  FUNCTION "hnsw_l2_distance"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS double precision /* f64 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_l2_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:523
-- pgcontext::pgcontext::vector::vector_dims
CREATE  FUNCTION "vector_dims"(
	"vector" Vector /* Vector */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_dims_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query/late_interaction.rs:80
-- pgcontext::hybrid_query::late_interaction::explain_late_interaction
CREATE  FUNCTION "explain_late_interaction"(
	"collection" TEXT, /* String */
	"query_vectors" Vector[], /* Vec < Vector > */
	"vector_column" TEXT /* String */
) RETURNS TABLE (
	"stage" TEXT,  /* String */
	"detail" TEXT,  /* String */
	"branch" TEXT,  /* Option < String > */
	"strategy" TEXT,  /* String */
	"status" QueryExplainStatus,  /* QueryExplainStatus */
	"estimated_candidates" bigint,  /* Option < i64 > */
	"candidate_budget" bigint  /* Option < i64 > */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'explain_late_interaction_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:432
-- pgcontext::pgcontext::vector::vector_lt
CREATE  FUNCTION "vector_lt"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_lt_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:551
-- pgcontext::pgcontext::vector::negative_inner_product
CREATE  FUNCTION "negative_inner_product"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'negative_inner_product_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:308
-- pgcontext::pgcontext::vector::vector_from_integer_array
CREATE  FUNCTION "vector_from_integer_array"(
	"values" INT[] /* Vec < i32 > */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_from_integer_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:416
-- pgcontext::pgcontext::vector::vector_avg_final
CREATE  FUNCTION "vector_avg_final"(
	"state" real[] /* Vec < f32 > */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_avg_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:456
-- pgcontext::pgcontext::vector::vector_ge
CREATE  FUNCTION "vector_ge"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_ge_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/quantization_sql.rs:39
-- pgcontext::quantization_sql::scalar_reconstruct
CREATE  FUNCTION "scalar_reconstruct"(
	"codes" bytea, /* Vec < u8 > */
	"min" real, /* f32 */
	"max" real, /* f32 */
	"levels" INT /* i32 */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'scalar_reconstruct_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:299
-- pgcontext::pgcontext::vector::vector_from_real_array
CREATE  FUNCTION "vector_from_real_array"(
	"values" real[] /* Vec < f32 > */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_from_real_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:655
-- pgcontext::pgcontext::vector::rerank_late_interaction
CREATE  FUNCTION "rerank_late_interaction"(
	"query_vectors" Vector[], /* Vec < Vector > */
	"point_ids" bigint[], /* Vec < i64 > */
	"candidate_vectors" Vector[], /* Vec < Vector > */
	"candidate_offsets" INT[], /* Vec < i32 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"score" real  /* f32 */
)
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'rerank_late_interaction_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:539
-- pgcontext::pgcontext::vector::l2_distance
CREATE  FUNCTION "l2_distance"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'l2_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/recommend.rs:64
-- pgcontext::table_search::recommend::recommend
CREATE  FUNCTION "recommend"(
	"collection" TEXT, /* String */
	"positive_vectors" Vector[], /* Vec < Vector > */
	"negative_vectors" Vector[], /* Vec < Vector > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'recommend_collection_from_vectors_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search.rs:78
-- pgcontext::table_search::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"filter" TEXT, /* Option < String > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_filtered_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/candidate_recheck.rs:74
-- pgcontext::table_search::candidate_recheck::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"candidate_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query/late_interaction_ann.rs:193
-- pgcontext::hybrid_query::late_interaction_ann::search_late_interaction_ann
CREATE  FUNCTION "search_late_interaction_ann"(
	"collection" TEXT, /* String */
	"query_vectors" Vector[], /* Vec < Vector > */
	"candidates_per_query" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" double precision  /* f64 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_owned_late_interaction_ann_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:557
-- pgcontext::pgcontext::vector::cosine_distance
CREATE  FUNCTION "cosine_distance"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'cosine_distance_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am/sql_contract.rs:4
-- requires:
--   pgcontext_bootstrap
--   Vector
--   HalfVec
--   SparseVec
--   BitVec
--   create_vector_distance_operators
--   create_vector_variant_distance_operators
--   create_vector_fast_distance_functions
--   hnsw_l2_distance
--   negative_inner_product
--   cosine_distance
--   l1_distance
--   halfvec_l2_distance
--   halfvec_negative_inner_product
--   halfvec_cosine_distance
--   halfvec_l1_distance
--   sparsevec_l2_distance
--   sparsevec_negative_inner_product
--   sparsevec_cosine_distance
--   sparsevec_l1_distance
--   bitvec_hamming_distance
--   bitvec_jaccard_distance


CREATE FUNCTION pgcontext.hnsw_handler(internal)
RETURNS index_am_handler
AS 'MODULE_PATHNAME', 'pgcontext_hnsw_handler'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR pgcontext.<-> (
    LEFTARG = pgcontext.vector,
    RIGHTARG = pgcontext.vector,
    FUNCTION = pgcontext._l2_distance_fast8,
    COMMUTATOR = OPERATOR(pgcontext.<->)
);

CREATE ACCESS METHOD pgcontext_hnsw
    TYPE INDEX
    HANDLER pgcontext.hnsw_handler;

CREATE OPERATOR CLASS pgcontext.vector_hnsw_ops
    DEFAULT FOR TYPE pgcontext.vector USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<-> (pgcontext.vector, pgcontext.vector) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.hnsw_l2_distance(pgcontext.vector, pgcontext.vector);

CREATE OPERATOR CLASS pgcontext.vector_hnsw_ip_ops
    FOR TYPE pgcontext.vector USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<#> (pgcontext.vector, pgcontext.vector) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.negative_inner_product(pgcontext.vector, pgcontext.vector);

CREATE OPERATOR CLASS pgcontext.vector_hnsw_cosine_ops
    FOR TYPE pgcontext.vector USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<=> (pgcontext.vector, pgcontext.vector) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.cosine_distance(pgcontext.vector, pgcontext.vector);

CREATE OPERATOR CLASS pgcontext.vector_hnsw_l1_ops
    FOR TYPE pgcontext.vector USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<+> (pgcontext.vector, pgcontext.vector) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.l1_distance(pgcontext.vector, pgcontext.vector);

CREATE OPERATOR pgcontext.<-> (
    LEFTARG = pgcontext.halfvec,
    RIGHTARG = pgcontext.halfvec,
    FUNCTION = pgcontext.halfvec_l2_distance,
    COMMUTATOR = OPERATOR(pgcontext.<->)
);

CREATE OPERATOR CLASS pgcontext.halfvec_hnsw_ops
    DEFAULT FOR TYPE pgcontext.halfvec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<-> (pgcontext.halfvec, pgcontext.halfvec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.halfvec_l2_distance(pgcontext.halfvec, pgcontext.halfvec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.halfvec_hnsw_ip_ops
    FOR TYPE pgcontext.halfvec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<#> (pgcontext.halfvec, pgcontext.halfvec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.halfvec_negative_inner_product(pgcontext.halfvec, pgcontext.halfvec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.halfvec_hnsw_cosine_ops
    FOR TYPE pgcontext.halfvec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<=> (pgcontext.halfvec, pgcontext.halfvec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.halfvec_cosine_distance(pgcontext.halfvec, pgcontext.halfvec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.halfvec_hnsw_l1_ops
    FOR TYPE pgcontext.halfvec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<+> (pgcontext.halfvec, pgcontext.halfvec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.halfvec_l1_distance(pgcontext.halfvec, pgcontext.halfvec),
    STORAGE pgcontext.vector;

CREATE OPERATOR pgcontext.<-> (
    LEFTARG = pgcontext.sparsevec,
    RIGHTARG = pgcontext.sparsevec,
    FUNCTION = pgcontext.sparsevec_l2_distance,
    COMMUTATOR = OPERATOR(pgcontext.<->)
);

CREATE OPERATOR CLASS pgcontext.sparsevec_hnsw_ops
    DEFAULT FOR TYPE pgcontext.sparsevec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<-> (pgcontext.sparsevec, pgcontext.sparsevec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.sparsevec_l2_distance(pgcontext.sparsevec, pgcontext.sparsevec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.sparsevec_hnsw_ip_ops
    FOR TYPE pgcontext.sparsevec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<#> (pgcontext.sparsevec, pgcontext.sparsevec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.sparsevec_negative_inner_product(pgcontext.sparsevec, pgcontext.sparsevec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.sparsevec_hnsw_cosine_ops
    FOR TYPE pgcontext.sparsevec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<=> (pgcontext.sparsevec, pgcontext.sparsevec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.sparsevec_cosine_distance(pgcontext.sparsevec, pgcontext.sparsevec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.sparsevec_hnsw_l1_ops
    FOR TYPE pgcontext.sparsevec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<+> (pgcontext.sparsevec, pgcontext.sparsevec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.sparsevec_l1_distance(pgcontext.sparsevec, pgcontext.sparsevec),
    STORAGE pgcontext.vector;

CREATE OPERATOR pgcontext.<~> (
    LEFTARG = pgcontext.bitvec,
    RIGHTARG = pgcontext.bitvec,
    FUNCTION = pgcontext.bitvec_hamming_distance,
    COMMUTATOR = OPERATOR(pgcontext.<~>)
);

CREATE OPERATOR CLASS pgcontext.bitvec_hnsw_hamming_ops
    FOR TYPE pgcontext.bitvec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<~> (pgcontext.bitvec, pgcontext.bitvec) FOR ORDER BY pg_catalog.integer_ops,
    FUNCTION 1 pgcontext.bitvec_hamming_distance(pgcontext.bitvec, pgcontext.bitvec),
    STORAGE pgcontext.vector;

CREATE OPERATOR CLASS pgcontext.bitvec_hnsw_jaccard_ops
    FOR TYPE pgcontext.bitvec USING pgcontext_hnsw AS
    OPERATOR 1 pgcontext.<%> (pgcontext.bitvec, pgcontext.bitvec) FOR ORDER BY pg_catalog.float_ops,
    FUNCTION 1 pgcontext.bitvec_jaccard_distance(pgcontext.bitvec, pgcontext.bitvec),
    STORAGE pgcontext.vector;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:452
-- pgcontext::pgcontext::vector_variants::halfvec_to_vector
CREATE  FUNCTION "halfvec_to_vector"(
	"vector" HalfVec /* HalfVec */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'halfvec_to_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:228
-- requires:
--   Vector
--   HalfVec
--   halfvec_from_real_array
--   halfvec_from_integer_array
--   halfvec_from_double_array
--   halfvec_to_real_array
--   halfvec_to_vector


CREATE CAST (real[] AS halfvec)
    WITH FUNCTION pgcontext.halfvec_from_real_array(real[]);

CREATE CAST (integer[] AS halfvec)
    WITH FUNCTION pgcontext.halfvec_from_integer_array(integer[]);

CREATE CAST (double precision[] AS halfvec)
    WITH FUNCTION pgcontext.halfvec_from_double_array(double precision[]);

CREATE CAST (halfvec AS real[])
    WITH FUNCTION pgcontext.halfvec_to_real_array(halfvec)
    AS ASSIGNMENT;

CREATE CAST (halfvec AS vector)
    WITH FUNCTION pgcontext.halfvec_to_vector(halfvec)
    AS ASSIGNMENT;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/named.rs:50
-- pgcontext::table_search::named::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"filter" TEXT, /* Option < String > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_named_vector_filtered_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search.rs:46
-- pgcontext::table_search::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/quantization_sql.rs:66
-- pgcontext::quantization_sql::product_reconstruct
CREATE  FUNCTION "product_reconstruct"(
	"codes" bytea, /* Vec < u8 > */
	"subvector_dimensions" INT, /* i32 */
	"codebooks" jsonb /* JsonB */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'product_reconstruct_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:320
-- pgcontext::pgcontext::vector::vector_from_double_array
CREATE  FUNCTION "vector_from_double_array"(
	"values" double precision[] /* Vec < f64 > */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_from_double_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:88
-- pgcontext::vector_variant_typmods::vector_enforce_typmod
CREATE  FUNCTION "vector_enforce_typmod"(
	"vector" Vector, /* Vector */
	"typmod" INT, /* i32 */
	"_explicit" bool /* bool */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_enforce_typmod_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query/late_interaction_ann.rs:801
-- pgcontext::hybrid_query::late_interaction_ann::explain_late_interaction_ann
CREATE  FUNCTION "explain_late_interaction_ann"(
	"collection" TEXT, /* String */
	"query_vectors" Vector[], /* Vec < Vector > */
	"vector_column" TEXT, /* String */
	"token_table" TEXT, /* String */
	"token_source_key_column" TEXT, /* String */
	"token_vector_column" TEXT, /* String */
	"candidates_per_query" INT /* i32 */
) RETURNS TABLE (
	"stage" TEXT,  /* String */
	"detail" TEXT,  /* String */
	"branch" TEXT,  /* Option < String > */
	"strategy" TEXT,  /* String */
	"status" QueryExplainStatus,  /* QueryExplainStatus */
	"estimated_candidates" bigint,  /* Option < i64 > */
	"candidate_budget" bigint  /* Option < i64 > */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'explain_late_interaction_ann_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am.rs:565
-- pgcontext::hnsw_am::_hnsw_masked_candidates
CREATE  FUNCTION "_hnsw_masked_candidates"(
	"index_relation" regclass, /* PgRelation */
	"query" Vector, /* Vector */
	"allowed_heap_tids" anyarray, /* AnyArray */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"heap_tid" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_masked_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:444
-- pgcontext::pgcontext::vector::vector_eq
CREATE  FUNCTION "vector_eq"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_eq_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/candidate_recheck.rs:223
-- pgcontext::table_search::candidate_recheck::search
CREATE  FUNCTION "search"(
	"collection" TEXT, /* String */
	"vector_name" TEXT, /* String */
	"vector" Vector, /* Vector */
	"filter" TEXT, /* Option < String > */
	"candidate_point_ids" bigint[], /* Vec < i64 > */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_collection_named_vector_filtered_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:545
-- pgcontext::pgcontext::vector::inner_product
CREATE  FUNCTION "inner_product"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS real /* f32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'inner_product_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/table_search/grouped.rs:17
-- pgcontext::table_search::grouped::grouped_search
CREATE  FUNCTION "grouped_search"(
	"collection" TEXT, /* String */
	"vector" Vector, /* Vector */
	"group_by" TEXT, /* String */
	"group_limit" INT, /* i32 */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"group_value" TEXT,  /* String */
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'grouped_search_collection_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query/late_interaction_ann.rs:273
-- pgcontext::hybrid_query::late_interaction_ann::explain_late_interaction_ann
CREATE  FUNCTION "explain_late_interaction_ann"(
	"collection" TEXT, /* String */
	"query_vectors" Vector[], /* Vec < Vector > */
	"candidates_per_query" INT /* i32 */
) RETURNS TABLE (
	"stage" TEXT,  /* String */
	"detail" TEXT,  /* String */
	"branch" TEXT,  /* Option < String > */
	"strategy" TEXT,  /* String */
	"status" QueryExplainStatus,  /* QueryExplainStatus */
	"estimated_candidates" bigint,  /* Option < i64 > */
	"candidate_budget" bigint  /* Option < i64 > */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'explain_owned_late_interaction_ann_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:517
-- pgcontext::pgcontext::vector_variants::sparsevec_to_vector
CREATE  FUNCTION "sparsevec_to_vector"(
	"vector" SparseVec /* SparseVec */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'sparsevec_to_vector_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variants.rs:294
-- requires:
--   Vector
--   SparseVec
--   sparsevec_from_real_array
--   sparsevec_to_real_array
--   sparsevec_from_vector
--   sparsevec_to_vector


CREATE CAST (real[] AS sparsevec)
    WITH FUNCTION pgcontext.sparsevec_from_real_array(real[])
    AS ASSIGNMENT;

CREATE CAST (sparsevec AS real[])
    WITH FUNCTION pgcontext.sparsevec_to_real_array(sparsevec)
    AS ASSIGNMENT;

CREATE CAST (vector AS sparsevec)
    WITH FUNCTION pgcontext.sparsevec_from_vector(vector)
    AS ASSIGNMENT;

CREATE CAST (sparsevec AS vector)
    WITH FUNCTION pgcontext.sparsevec_to_vector(sparsevec)
    AS ASSIGNMENT;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hnsw_am.rs:509
-- pgcontext::hnsw_am::_hnsw_candidates
CREATE  FUNCTION "_hnsw_candidates"(
	"index_relation" regclass, /* PgRelation */
	"query" Vector, /* Vector */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"heap_tid" TEXT,  /* String */
	"score" real  /* f32 */
)
STRICT 
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hnsw_candidates_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:450
-- pgcontext::pgcontext::vector::vector_ne
CREATE  FUNCTION "vector_ne"(
	"left" Vector, /* Vector */
	"right" Vector /* Vector */
) RETURNS bool /* bool */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_ne_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:210
-- requires:
--   Vector
--   vector_lt
--   vector_le
--   vector_eq
--   vector_ne
--   vector_ge
--   vector_gt
--   vector_cmp


CREATE OPERATOR pgcontext.< (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext.vector_lt,
    COMMUTATOR = OPERATOR(pgcontext.>),
    NEGATOR = OPERATOR(pgcontext.>=)
);

CREATE OPERATOR pgcontext.<= (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext.vector_le,
    COMMUTATOR = OPERATOR(pgcontext.>=),
    NEGATOR = OPERATOR(pgcontext.>)
);

CREATE OPERATOR pgcontext.= (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext.vector_eq,
    COMMUTATOR = OPERATOR(pgcontext.=),
    NEGATOR = OPERATOR(pgcontext.<>)
);

CREATE OPERATOR pgcontext.<> (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext.vector_ne,
    COMMUTATOR = OPERATOR(pgcontext.<>),
    NEGATOR = OPERATOR(pgcontext.=)
);

CREATE OPERATOR pgcontext.>= (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext.vector_ge,
    COMMUTATOR = OPERATOR(pgcontext.<=),
    NEGATOR = OPERATOR(pgcontext.<)
);

CREATE OPERATOR pgcontext.> (
    LEFTARG = vector,
    RIGHTARG = vector,
    FUNCTION = pgcontext.vector_gt,
    COMMUTATOR = OPERATOR(pgcontext.<),
    NEGATOR = OPERATOR(pgcontext.<=)
);

CREATE OPERATOR CLASS pgcontext.vector_ops
    DEFAULT FOR TYPE vector USING btree AS
    OPERATOR 1 pgcontext.< (vector, vector),
    OPERATOR 2 pgcontext.<= (vector, vector),
    OPERATOR 3 pgcontext.= (vector, vector),
    OPERATOR 4 pgcontext.>= (vector, vector),
    OPERATOR 5 pgcontext.> (vector, vector),
    FUNCTION 1 pgcontext.vector_cmp(vector, vector);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:12
-- pgcontext::query_builders::query_nearest
CREATE  FUNCTION "query_nearest"(
	"vector" Vector, /* Vector */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_nearest_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/hybrid_query/late_interaction.rs:40
-- pgcontext::hybrid_query::late_interaction::search_late_interaction
CREATE  FUNCTION "search_late_interaction"(
	"collection" TEXT, /* String */
	"query_vectors" Vector[], /* Vec < Vector > */
	"vector_column" TEXT, /* String */
	"limit" INT /* i32 */
) RETURNS TABLE (
	"point_id" bigint,  /* i64 */
	"source_key" TEXT,  /* String */
	"score" double precision  /* f64 */
)
STRICT
SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'search_late_interaction_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/query_builders.rs:23
-- pgcontext::query_builders::query_nearest
CREATE  FUNCTION "query_nearest"(
	"vector_name" TEXT, /* Option < String > */
	"vector" Vector, /* Vector */
	"filter" jsonb, /* Option < JsonB > */
	"limit" INT /* i32 */
) RETURNS jsonb /* JsonB */

SET search_path TO pg_catalog, pgcontext, public
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'query_nearest_configured_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:410
-- pgcontext::pgcontext::vector::vector_sum_final
CREATE  FUNCTION "vector_sum_final"(
	"state" real[] /* Vec < f32 > */
) RETURNS Vector /* Vector */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_sum_final_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:369
-- pgcontext::pgcontext::vector::vector_sum_transition
CREATE  FUNCTION "vector_sum_transition"(
	"state" real[], /* :: std :: option :: Option < Vec < f32 > > */
	"value" Vector /* Option < Vector > */
) RETURNS real[] /* :: std :: option :: Option < Vec < f32 > > */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_sum_transition_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:275
-- requires:
--   Vector
--   vector_sum_transition
--   vector_sum_final
--   vector_avg_final


CREATE AGGREGATE pgcontext.sum(vector) (
    SFUNC = pgcontext.vector_sum_transition,
    STYPE = real[],
    FINALFUNC = pgcontext.vector_sum_final
);

CREATE AGGREGATE pgcontext.avg(vector) (
    SFUNC = pgcontext.vector_sum_transition,
    STYPE = real[],
    FINALFUNC = pgcontext.vector_avg_final
);
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:332
-- pgcontext::pgcontext::vector::vector_to_real_array
CREATE  FUNCTION "vector_to_real_array"(
	"vector" Vector /* Vector */
) RETURNS real[] /* Vec < f32 > */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_to_real_array_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector.rs:157
-- requires:
--   Vector
--   vector_from_real_array
--   vector_from_integer_array
--   vector_from_double_array
--   vector_to_real_array


CREATE CAST (real[] AS vector)
    WITH FUNCTION pgcontext.vector_from_real_array(real[])
    AS ASSIGNMENT;

CREATE CAST (integer[] AS vector)
    WITH FUNCTION pgcontext.vector_from_integer_array(integer[]);

CREATE CAST (double precision[] AS vector)
    WITH FUNCTION pgcontext.vector_from_double_array(double precision[]);

CREATE CAST (vector AS real[])
    WITH FUNCTION pgcontext.vector_to_real_array(vector)
    AS ASSIGNMENT;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:74
-- pgcontext::vector_variant_typmods::vector_typmod_in
CREATE  FUNCTION "vector_typmod_in"(
	"modifiers" cstring[] /* Array < '_, & CStr > */
) RETURNS INT /* i32 */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:81
-- pgcontext::vector_variant_typmods::vector_typmod_out
CREATE  FUNCTION "vector_typmod_out"(
	"typmod" INT /* i32 */
) RETURNS cstring /* CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper';
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/vector_variant_typmods.rs:14
-- requires:
--   Vector
--   HalfVec
--   SparseVec
--   BitVec
--   vector_typmod_in
--   vector_typmod_out
--   vector_enforce_typmod
--   halfvec_typmod_in
--   halfvec_typmod_out
--   sparsevec_typmod_in
--   sparsevec_typmod_out
--   bitvec_typmod_in
--   bitvec_typmod_out
--   halfvec_enforce_typmod
--   sparsevec_enforce_typmod
--   bitvec_enforce_typmod


ALTER TYPE vector SET (
    TYPMOD_IN = pgcontext.vector_typmod_in,
    TYPMOD_OUT = pgcontext.vector_typmod_out
);

ALTER TYPE halfvec SET (
    TYPMOD_IN = pgcontext.halfvec_typmod_in,
    TYPMOD_OUT = pgcontext.halfvec_typmod_out
);

ALTER TYPE sparsevec SET (
    TYPMOD_IN = pgcontext.sparsevec_typmod_in,
    TYPMOD_OUT = pgcontext.sparsevec_typmod_out
);

ALTER TYPE bitvec SET (
    TYPMOD_IN = pgcontext.bitvec_typmod_in,
    TYPMOD_OUT = pgcontext.bitvec_typmod_out
);

CREATE CAST (halfvec AS halfvec)
    WITH FUNCTION pgcontext.halfvec_enforce_typmod(halfvec, integer, boolean)
    AS IMPLICIT;

CREATE CAST (sparsevec AS sparsevec)
    WITH FUNCTION pgcontext.sparsevec_enforce_typmod(sparsevec, integer, boolean)
    AS IMPLICIT;

CREATE CAST (bitvec AS bitvec)
    WITH FUNCTION pgcontext.bitvec_enforce_typmod(bitvec, integer, boolean)
    AS IMPLICIT;

CREATE CAST (vector AS vector)
    WITH FUNCTION pgcontext.vector_enforce_typmod(vector, integer, boolean)
    AS IMPLICIT;
/* </end connected objects> */

/* <begin connected objects> */
-- crates/context-pg/src/pgvector_ownership/trigger.rs:14
-- pgcontext::pgvector_ownership::trigger::_sync_pgvector_ownership_columns
CREATE FUNCTION "_sync_pgvector_ownership_columns"()
	RETURNS TRIGGER
	LANGUAGE c
	AS 'MODULE_PATHNAME', '_sync_pgvector_ownership_columns_wrapper';
/* </end connected objects> */

