pgvector-semantic-search

Configure pgvector indexes and queries for semantic similarity search in PostgreSQL.

Updated Jul 12, 2025
One-click install
npx skills add https://github.com/kpayakv2/check-products --skill pgvector-semantic-search-kpayakv2
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pgvector-semantic-search
Source: https://github.com/kpayakv2/check-products/tree/main/.agents/skills/pgvector-semantic-search
Command: npx skills add https://github.com/kpayakv2/check-products --skill pgvector-semantic-search-kpayakv2

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up vector similarity search in PostgreSQL involves many tuning decisions—index type, distance operator, storage type, and recall parameters—and wrong choices lead to slow queries, poor recall, or out-of-memory failures. This Skill provides proven defaults and tuning guidance for pgvector so searches stay fast and accurate at scale. ## Core Features & Use Cases - Index Configuration: Set up HNSW indexes with tuned m, ef_construction, and ef_search parameters, plus guidance on when IVFFlat is appropriate. - Storage Optimization: Use halfvec for 50% smaller storage and binary quantization with re-ranking for datasets exceeding 10M vectors. - Filtered Search: Apply iterative scan, partial indexes, B-tree prefiltering, or partitioning strategies for selective WHERE clauses. - Use Case: You are building a RAG application that stores product embeddings in PostgreSQL. Use this Skill to create the table and HNSW index, write the similarity query with proper casts, and tune ef_search until recall meets your target. ## Quick Start Set up a pgvector HNSW index and cosine similarity query for my embeddings table in PostgreSQL.

Frequently Asked Questions about pgvector-semantic-search

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up vector similarity search in PostgreSQL?▼

Enable the pgvector extension with CREATE EXTENSION vector, store embeddings in a vector or halfvec column, and create an HNSW index with the matching ops class. Query using ORDER BY embedding <=> query_vector with a LIMIT clause.

HNSW vs IVFFlat index for pgvector, which should I use?▼

HNSW is the recommended default because it offers a better speed-recall tradeoff, works on empty tables, and needs no training step. Use IVFFlat only for write-heavy workloads, tight memory constraints, or when you rebuild indexes frequently.

Why does my pgvector query not use the index?▼

The index is skipped when the query lacks ORDER BY with a distance operator plus LIMIT, when the operator does not match the index ops class, or when the query vector is not explicitly cast. Cast query vectors explicitly, for example $1::halfvec(1536).

How do I improve recall for filtered vector search in pgvector?▼

Enable iterative scan with SET hnsw.iterative_scan = relaxed_order so HNSW continues searching until enough filtered rows are found. For highly selective filters, use a B-tree prefilter, partial HNSW indexes, or partition by the filter key.

When should I use binary quantization with pgvector?▼

Use binary quantization when the HNSW index no longer fits in memory, typically beyond 10M vectors. Store a quantized bit column, search it with hamming distance, then re-rank an oversampled candidate set using the full halfvec embeddings.