This one is a trap. You build your vector database. You embed thousands of records. You run a semantic search query. You get zero results. No error. Just silence.
Here is what is happening and how to fix it.
The Silent Failure Pattern
Supabase pgvector similarity search requires a custom RPC (Remote Procedure Call) function in your database - typically called something like match_knowledge_base. This function takes a query embedding, compares it against all stored vectors using cosine similarity, and returns the top matches above a threshold.
If that function doesn’t exist, the API call returns a 404 error. If your application code catches all exceptions broadly (except Exception: results = []), it silently swallows that 404 and returns an empty list. No error in your logs. No indication anything is wrong. Just zero results.
The Fix: Create the RPC Function
Run this SQL in your Supabase SQL editor, replacing the table and column names to match your schema:
CREATE OR REPLACE FUNCTION match_knowledge_base(
query_embedding vector(1536),
match_count int DEFAULT 5,
match_threshold float DEFAULT 0.5
)
RETURNS TABLE(id text, title text, content text, similarity float)
LANGUAGE plpgsql AS $$
BEGIN
RETURN QUERY
SELECT k.id, k.title, k.content,
1 - (k.embedding <=> query_embedding) AS similarity
FROM knowledge_base k
WHERE k.embedding IS NOT NULL
AND 1 - (k.embedding <=> query_embedding) > match_threshold
ORDER BY k.embedding <=> query_embedding
LIMIT match_count;
END;
$$;
The Lesson
Never catch exceptions broadly in production AI systems. If a semantic search returns zero results, that should throw a visible error, not silently fall back to an empty list. Build explicit error handling that distinguishes between “no results found” and “the search function doesn’t exist.”
Check your RPC functions first whenever a vector search returns nothing.
Related reading:
- Why Your AI Forgets Everything
- Obsidian as an AI Knowledge Capture System
- My Portable Brain Architecture
Found this useful? Check out the Learn section for structured micro-lessons on building AI systems, or read more on the blog for more practical guides.
Find me across the web
Stay curious, my AI friend. It's the secret sauce - think like you are seven. - Ryan
