postgres-semantic-search — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited postgres-semantic-search (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Decisions, measured findings and silent failure modes for search built on Postgres, plus tested SQL building blocks in scripts/. Syntax the official docs cover well is left to them; what is here goes wrong without an error.
terms, full questions, which languages. That decides which arms you need.
lookup or vector search. For approximate vector search, keep exact vector search as the recall baseline.
the queries that need it (hybrid-search.md).
(reranking.md).
Change one thing at a time. Predefine the acceptance rule; by default require a gain beyond measured run-to-run spread on the affected query population, without a material loss on the other eval set. Inspect per-query wins/losses and require the agreed latency and cost budget to hold. The numerical findings below are corpus-specific observations, not universal performance guarantees.
vector(N) indexes up to 2,000;up to 4,000 index a halfvec cast (or use a halfvec column); above that, binary quantization or Matryoshka truncation.
count decides it: measure recall and latency against exact search.
the provider's current docs, prefer multilingual models for non-English text, and evaluate on the target language before committing.
keyword alone was weak on long questions (24 % right first), vector alone on short terms (53 %); hybrid tied vector on long questions and led on short terms (53 % and 93 %; hybrid-search.md).
pg_search). Plain FTS with the fixes below is often enough.
These return fewer rows, zero rows or plausible results, never an error.
pgvector (pgvector.md):
LIMIT, or a selective WHERE, silently returns fewer. Enable hnsw.iterative_scan (off by default), or use partial indexes or partitions.
recall against exact search stops moving. If EXPLAIN shows a seq scan, tuning does nothing, and the seq scan may be the faster plan.
inside it.
SET LOCAL in thesame transaction, or a function-level SET.
returns nothing for another. 1 - (a <#> b) is not cosine similarity.
{0.1,0.2} and Drizzle'ssql template expands an array into ($1, $2, ...); vector input rejects both. Send JSON.stringify(embedding) and cast with ::vector.
Keyword (keyword-search.md):
plainto_tsquery and unquoted plain input to websearch_to_tsqueryAND bare terms**, so long questions can match nothing. For plain-input retrieval, consider OR and ts_rank_cd; preserve explicit web-search quotes, OR and exclusions.
Fold only decorative accents, inside a text search configuration.
stemming. Normalize them consistently without deleting meaningful ZWNJ/ZWJ.
an ORM migration. If hybrid and vector-only return identical lists, the keyword arm may be absent or ineffective: check NULL/population counts and keyword-only results before diagnosing it.
hyphenated tokens (prefix_tsquery.sql).
<% for prefixes and short queriesagainst long text.
Ratios vary by model and text: with OpenAI's cl100k_base (text-embedding-3), Finnish runs about 2.5 characters per token against 4 or more for English, so an English-tuned character cap is about twice too generous. The endpoint rejects the chunk and often fails the whole batch.
12 points even with a multilingual embedding model. Translate into a sentence, not a keyword list (a keyword list scored 14 points below no translation on one corpus), and consider two-pass fusion.
and its generic word takes over the ranking. Trim parts an order of magnitude commoner than the rest of their own phrase.
arm (Postgres finnish) lifted keyword-only search but not hybrid; a dictionary lemmatizer did worse than the stemmer on spoken and domain text; compound splitting flooded the arm. Re-measure on the target text. Prefix matching never reaches the base form of an inflected query (keyword-search.md).
fine-grained search over the subtitle cues inside the matched segment finds the moment.
Details and measurements: hybrid-search.md.
and deepen only if the short-term set holds. Cross-encoders score "mentions X" rather than "is about X" and promote passing mentions of short terms: on a Finnish transcript corpus, reordering all 30 cut short-term Hit@1 from 0.93 to 0.60–0.80, the top 10 still cost some models a term or two, and the top 5 cost none for six rerankers. Re-measure depth on your own sets.
thirty points on one corpus). Every criterion must be checkable from the text sent, and the source title belongs in the reranker input.
Measured on a 2-core CPU: a ~120M multilingual cross-encoder added about 0.3 s, while 568M–600M models took 10–25 s. On a data-centre GPU, Qwen3-Reranker-8B was the only model clearly more accurate than that small CPU model (reranking.md). Hosted rerankers need no infrastructure but receive the candidate text. A GPU that comes and goes can serve first, with the CPU model as the timeout fallback. Measure p95 on the target hardware.
first stage missed.
Numbers, model trade-offs and adoption rules: reranking.md.
For a new sample database, use setup.sql, then indexes.sql and selected function files. For an existing database, review/adapt them as migrations: they assume documents(id, title, content, metadata, embedding vector(1536)) and chunks(id, document_id, chunk_index, content, embedding): change the names and dimension in every file together. Some function files drop older signatures; review dependent objects before applying them. These are building blocks, not a complete production migration/authorization policy. None sets hnsw.ef_search; the caller does.
| File | Functions (real parameter names) |
|---|---|
| semantic_search.sql | match_documents(query_embedding, match_threshold, match_count), match_documents_filtered(query_embedding, filter_metadata, match_threshold, match_count), match_chunks(query_embedding, match_threshold, match_count); match_threshold NULL = plain top-k |
| hybrid_search_fts.sql | hybrid_search_fts(query_embedding, query_text, match_count, rrf_k, fts_language, vector_weight, keyword_weight); either input may be NULL |
| hybrid_search_bm25.sql | hybrid_search_bm25(...), hybrid_search_chunks_bm25(...): same parameters without fts_language; needs pg_search |
| fuzzy_search.sql | fuzzy_search_trigram(query_text, similarity_threshold, max_results), autocomplete_search(search_prefix, max_results), hybrid_search_fuzzy_semantic(query_text, query_embedding, max_results, rrf_k) |
| prefix_tsquery.sql | prefix_tsquery(config, text [, join]) |
| setup.sql, indexes.sql | Extensions, example tables, indexes |
Supabase .rpc() binds arguments by name, so a misspelled key fails at call time:
const { data, error } = await supabase.rpc('hybrid_search_fts', {
query_embedding: embedding, // number[]
query_text: userQuery,
match_count: 10,
fts_language: 'simple',
});
// Drizzle or node-postgres: send the vector as text and cast it
await db.execute(sql`SELECT * FROM match_documents(${JSON.stringify(embedding)}::vector, NULL, 10)`);tuning, planner choice, filters and thresholds, poolers, builds, operators.
and language configs, dead keyword arms, prefix matching, trigrams, ParadeDB.
chunking, transcripts, off-language queries, synonym expansion.
relevance question, headroom, adoption.
four ways a measurement misleads.
SELECT extversion FROM pg_extension WHERE extname = 'vector'. 0.8.0+ for iterative scans. Check current stable releases: 0.8.2 fixed a buffer overflow in parallel HNSW builds, 0.8.3 and 0.8.4 HNSW vacuum corruption and errors, 0.8.7 a buffer overflow in IVFFlat builds. Read the current index-fix and upgrade notes before upgrading. Releases ship as git tags only, so read the CHANGELOG, not the empty Releases tab.
API moves quickly; see keyword-search.md.
| Need | Skill |
|---|---|
| General Postgres schema, indexes, RLS, pooling | supabase-postgres-best-practices (Supabase plugin or supabase/agent-skills) |
| Chatbot orchestration, sessions, tool calls | nextjs-chatbot |
| Embedding calls through the AI SDK | ai-sdk |
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.