CtrlK
BlogDocsLog inGet started
Tessl Logo

g14wxz/retrieval-threshold-guard

Enforces minimum similarity thresholds on vector retrieval to prevent RAG hallucination from weak matches.

97

Quality

97%

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

retrieval-guard-rules.mdrules/

Retrieval Guard Rules

FATAL Constraints

  • Returning weak matches instead of empty results is FATAL. When no vectors meet the similarity threshold, the RPC MUST return an empty result set. NEVER fall back to returning the "best available" match below threshold. Weak matches cause downstream hallucination.
  • A match_threshold below 0.5 is FATAL. The threshold parameter MUST NEVER accept values below 0.5. The RPC MUST raise an exception if a caller passes a sub-0.5 threshold.
  • Missing WHERE similarity filter is FATAL. Every vector retrieval RPC MUST include WHERE similarity >= match_threshold in the query. Omitting this filter renders the threshold parameter decorative.

Mandatory Behaviors

  • MUST expose match_threshold as a configurable parameter with a default value >= 0.5.
  • MUST include a runtime guard (IF match_threshold < 0.5 THEN RAISE EXCEPTION) at the top of every retrieval function.
  • MUST order results by similarity descending and apply LIMIT match_count.
  • MUST compute similarity as 1 - (embedding <=> query_embedding) for cosine distance.
  • MUST NOT use <-> (L2 distance) unless the embedding model explicitly requires Euclidean distance.
  • MUST grant EXECUTE to authenticated only — NEVER to anon unless the caller explicitly overrides.

tile.json