Enforces minimum similarity thresholds on vector retrieval to prevent RAG hallucination from weak matches.
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Enforces minimum similarity thresholds on vector retrieval to prevent RAG hallucination from weak matches.
Vector similarity search always returns results, even when those results are semantically irrelevant. Without a hard threshold, low-confidence matches flow into LLM context and produce hallucinated answers. This tile enforces a configurable but floor-limited similarity threshold on all retrieval RPCs, guaranteeing that empty results are returned when no strong matches exist.
match_documents(
query_embedding VECTOR(1536),
match_threshold FLOAT DEFAULT 0.75,
match_count INT DEFAULT 10
) RETURNS TABLE (id UUID, content TEXT, similarity FLOAT)0.75 (configurable per deployment).0.5 — the function raises an exception if a value below 0.5 is passed.1 - (embedding <=> query_embedding) (cosine distance).const { data } = await supabase.rpc('match_documents', {
query_embedding: embedding,
match_threshold: 0.8,
match_count: 5,
});
// data is [] when no matches meet the thresholdhybrid-search-rrf-pattern — provides the base retrieval pattern that this tile augments with threshold guards.Runs after hybrid-search-rrf-pattern establishes the base search RPC. This tile wraps or modifies that RPC to add threshold enforcement. Downstream consumers (LLM chains, API endpoints) MUST handle empty result sets gracefully.