-
-
Notifications
You must be signed in to change notification settings - Fork 172
Description
Bug report
Describe the bug
When using supabase gen types typescript with RPC functions that have vector parameters, the generated types are string, but the actual Supabase client requires number[] to work correctly.
This is different from the closed issue #578 which focused on table columns. For RPC functions, the workaround of using JSON.stringify() does NOT work - it causes the query to fail or return zero results.
To Reproduce
- Create a hybrid search function using pgvector:
CREATE OR REPLACE FUNCTION match_documents(
query_embedding vector(1536),
match_count int DEFAULT 5
)
RETURNS TABLE (
id uuid,
content text,
similarity float
)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT
documents.id,
documents.content,
(1 - (documents.embedding <=> query_embedding)) AS similarity
FROM documents
ORDER BY documents.embedding <=> query_embedding
LIMIT match_count;
END;
$$;
-
Generate types:
supabase gen types typescript --project-id <project-id> > types/supabase.ts -
Observe generated types:
Functions: {
match_documents: {
Args: {
query_embedding: string // ❌ Generated as string
match_count?: number
}
Returns: { /* ... */ }[]
}
}
- Try to call the function:
// Get embedding from OpenAI (returns number[])
const embedding = [0.1, 0.2, 0.3, /* ... 1536 floats */];
// ❌ TypeScript error: number[] is not assignable to string
const { data } = await supabase.rpc("match_documents", {
query_embedding: embedding,
});
Expected behavior
The generated type for vector parameters should be number[]:
Functions: {
match_documents: {
Args: {
query_embedding: number[] // ✅ Should be number[]
match_count?: number
}
}
}
What DOES work vs what DOESN'T:
INSERT into table column:
JSON.stringify()→ ✅ Works- Raw
number[]→ ❌ Fails
RPC function parameter:
JSON.stringify()→ ❌ Fails- Raw
number[]→ ✅ Works
This inconsistency makes it impossible to have correct types for both use cases.
Current workarounds (all bad)
Use any type for Supabase client - loses all type safety
Use @ts-expect-error - suppresses errors but doesn't fix the type
Manually edit generated types - gets overwritten on regeneration
Environment
Supabase CLI version: latest
pgvector extension: enabled
TypeScript version: 5.x
supabase-js version: 2.86.2
Why this matters
Vector similarity search via RPC functions is a common pattern for AI/RAG applications. The current type generation makes it impossible to build type-safe applications using this pattern.
Proposed solution
Map vector and vector(n) types to number[] in TypeScript generation for function parameters.
Related issues
#578 - Closed as not planned, but only addressed table columns, not RPC functions