Skip to content

Supabase RPC Functions

PostgreSQL functions called from the frontend via supabase.rpc().

Search Functions

pip_ai_search_specs

Hybrid semantic + keyword search for spec sections.

typescript
const { data } = await supabase.rpc('pip_ai_search_specs', {
  query_embedding: embeddingVector,  // vector(1536)
  query_text: 'window shade',
  filter_brand: 'Holiday Inn Express',
  filter_areas: ['guest-room'],
  match_threshold: 0.7,
  match_count: 10,
})
ParameterTypeRequiredDescription
query_embeddingvector(1536)YesEmbedding vector
query_texttextYesKeyword search text
filter_brandtextYesBrand filter (isolation)
filter_areastext[]NoArea filter
match_thresholdfloatNoMin similarity (default: 0.70)
match_countintNoMax results (default: 10)

Returns: id, spec_number, title, category, brand_name, area, similarity

Auth Functions

pip_ai_check_is_admin()

Check if current user is admin. Uses SECURITY DEFINER to avoid RLS recursion.

typescript
const { data: isAdmin } = await supabase.rpc('pip_ai_check_is_admin')

pip_ai_get_my_profile()

Get current user's profile.

pip_ai_promote_to_admin(user_id)

Promote user to admin (admin only).

pip_ai_demote_to_user(user_id)

Demote admin to user (admin only).

pip_ai_list_users()

List all users (admin only).

pip_ai_deactivate_user(user_id) / pip_ai_reactivate_user(user_id)

Soft-ban/unban user (admin only).

Activity Functions

pip_ai_log_activity

Record an activity log entry.

typescript
await supabase.rpc('pip_ai_log_activity', {
  p_project_id: projectId,
  p_action: 'match_approved',
  p_details: { matchId, pipItemId, specSectionId }
})

Project Membership Functions

pip_ai_is_project_member(project_id)

Check if current user is a member of a project.

pip_ai_can_edit_project(project_id)

Check if current user can edit a project (owner/editor/admin).

pip_ai_get_project_role(project_id)

Get user's role in a project.

Built with VitePress