How to Fix “operator does not exist: vector <=> vector” in Supabase and pgvector
The extension is installed and the operator exists. Your function just can't see the schema it lives in.
On this page
- Why it works in one place and not the other
- 1. Confirm where the extension actually lives
- 2. Qualify the operator
- 3. The alternative, and why it's second choice
- 4. When the type is the problem, not the schema
- 5. Test the function the way your app calls it
- Match your symptom to the fix
- When it still fails
Your similarity search works in the SQL editor. Called from your application through a database function, it fails:
42883: operator does not exist: extensions.vector <=> extensions.vector
The extension is installed. The column is the right type. The query is the same query. And the error says an operator that definitely exists does not exist.
#Why it works in one place and not the other
| Where | search_path | Finds <=>? |
|---|---|---|
| SQL editor | Default, includes extensions | Yes |
Function with SET search_path = '' |
Empty | No |
| Function with no search_path set | Caller's, usually fine | Usually |
| Application connection | Role default | Depends |
The pattern is always the same. The operator is found by name lookup along the search path, and anything that empties or narrows that path hides it. Nothing about the extension or the data changed.
#1. Confirm where the extension actually lives
Don't assume extensions — check, because it takes one query and the answer determines what you qualify with:
select e.extname, n.nspname as schema
from pg_extension e
join pg_namespace n on n.oid = e.extnamespace
where e.extname = 'vector';
On Supabase this returns extensions. Qualify with whatever it actually says. On a plain Postgres where somebody ran create extension vector without specifying a schema, it's usually public — in which case this error has a different cause and you should go to section 4.
#2. Qualify the operator
This is the fix I'd use. It's explicit, it's local to the query, and it keeps the security posture that caused the problem in the first place:
create or replace function match_documents(
query_embedding extensions.vector(1536),
match_count int
)
returns table (id bigint, content text, similarity float)
language sql stable
set search_path = ''
as $$
select
d.id,
d.content,
1 - (d.embedding OPERATOR(extensions.<=>) query_embedding) as similarity
from public.documents d
order by d.embedding OPERATOR(extensions.<=>) query_embedding
limit match_count;
$$;
Three details matter there and all 3 are easy to miss. The OPERATOR(schema.op) syntax is how you name an operator explicitly. The parameter type needs qualifying too — extensions.vector, not vector. And every table reference needs its schema, because an empty search path hides public as surely as it hides extensions.
#3. The alternative, and why it's second choice
You can put the extensions schema back on the path instead:
set search_path = public, extensions;
It works and it's less typing. I'd still qualify the operator. This reintroduces the mutable search path the security guidance warns about, and it does so for every statement in the function rather than for the 1 operator that needed it. On a function that only reads your own documents the practical risk is small. It's still the broader change, and broader changes are the ones that surprise somebody later.
Setting it per role is a third option. It's the least contained of the 3, since it changes behaviour for everything connecting as that role.
#4. When the type is the problem, not the schema
A closely related error names 2 different types:
operator does not exist: vector <=> double precision
That's not a schema problem at all. You're passing an array of numbers where a vector is expected, and Postgres is telling you it has no operator for that combination. Cast it explicitly:
d.embedding <=> $1::vector
This usually appears when an embedding arrives as JSON. A JSON array of floats is not automatically a vector. Worth checking the dimension at the same time — a mismatch there produces a different error, covered in the Pinecone dimension guide, and the same reasoning applies to pgvector.
#5. Test the function the way your app calls it
Do not test in the SQL editor. That is the whole trap.
The editor runs with a search path that finds everything, so a broken function passes there and fails in production. I test with a direct call to the function instead, through the same client the application uses, because that is the only run that proves anything.
Write the test before you need it. A tiny script that calls the function with a known embedding and asserts it returns rows catches this class of bug in seconds, and it keeps catching it every time somebody edits the function later.
One more thing worth doing once. Grep your migrations for any function that sets an empty search path and uses an extension type or operator. If one exists, it has this bug too, and it is waiting for the first call from outside the editor.
#Match your symptom to the fix
| What you're seeing | Likely cause | Go to |
|---|---|---|
| Works in SQL editor, fails in a function | Empty search path | 2 |
extensions.vector <=> extensions.vector |
Operator not qualified | 2 |
vector <=> double precision |
Missing cast | 4 |
| Fails from the app, works in editor | Role search path | 3 |
| Function not found at all | Schema missing on the call too | 2 |
#When it still fails
Check the operator you're using exists for your distance metric. pgvector provides different operators for cosine, inner product and L2 distance. An index built for one doesn't serve a query using another. The query still runs. It just ignores the index and gets slow rather than failing, which is a worse outcome than an error.
If the function runs but returns nothing, the problem has moved from resolution to data. Confirm rows exist with a non-null embedding, and check the similarity threshold your function applies. A threshold that made sense for one embedding model is often wrong for another, because the distributions differ.
Frequently asked questions
Why does Supabase put pgvector in extensions?
To keep extension objects out of your application schema, which makes permissions and migrations cleaner. The cost is that unqualified references stop resolving once you narrow the search path.
Is setting search_path = '' worth the trouble?
It's the recommended posture for security-definer functions, because it stops a caller influencing name resolution inside your function. Qualifying names is the price, and it's a small one.
Do I have to qualify the parameter type too?
Yes, with an empty search path. A parameter declared as plain vector won't resolve, and the error points at the operator rather than the parameter, which sends people hunting in the wrong place.
Does this apply to self-hosted Postgres?
Only if you installed the extension into a non-default schema or narrowed the search path yourself. A straightforward install into public doesn't hit this.
Written by
Vemuri Abhiram
Founder & Editor
Vemuri Abhiram is the founder and editor of Underread, where he writes about AI tools, software, and practical technology. He covers hands-on tool reviews, detailed guides, product comparisons, and emerging technologies.
You might also like
How to Fix “CUDA out of memory” When Running a Local LLM
Why a model that loaded yesterday runs out of VRAM today, and the 5 fixes in the order that costs you the least quality.
Vemuri Abhiram6 min read
How to Fix “The requested webhook is not registered” in n8n (404)
Why an n8n webhook works while you watch it and 404s afterwards, and the 5 causes ranked by how often they're the answer.
Vemuri Abhiram5 min read
How to Fix Cloudflare Error 524 on Long LLM Requests (Without an Enterprise Plan)
Why a slow model call dies at exactly 100 seconds behind Cloudflare, and why streaming fixes it when raising timeouts can't.
Vemuri Abhiram6 min read
More from Underread, once a week.
The guides worth reading and the tests worth trusting. One email, every Friday.
No spam. Unsubscribe in one click.

