Semantic search finds content by meaning rather than exact keywords. An embedding model converts text into high-dimensional vectors, where similar meanings map to nearby points. pgvector stores these vectors in PostgreSQL and uses approximate nearest neighbor (ANN) indexes to find the closest matches quickly—scaling to millions of rows without leaving the database. Store your text alongside its embedding, then query by converting your search text to a vector and returning the rows with the small
Works with
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionpgvector-semantic-searchExecute the skills CLI command in your project's root directory to begin installation:
Fetches pgvector-semantic-search from timescale/pg-aiguide and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate pgvector-semantic-search. Access via /pgvector-semantic-search in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
0
total installs
0
this week
1.7K
GitHub stars
0
upvotes
Run in your terminal
0
installs
0
this week
1.7K
stars
Semantic search finds content by meaning rather than exact keywords. An embedding model converts text into high-dimensional vectors, where similar meanings map to nearby points. pgvector stores these vectors in PostgreSQL and uses approximate nearest neighbor (ANN) indexes to find the closest matches quickly—scaling to millions of rows without leaving the database. Store your text alongside its embedding, then query by converting your search text to a vector and returning the rows with the smallest distance.
This guide covers pgvector setup and tuning—not embedding model selection or text chunking, which significantly affect search quality. Requires pgvector 0.8.0+ for all features (halfvec, binary_quantize, iterative scan).
Use this configuration unless you have a specific reason not to.
halfvec(N) where N is your embedding dimension (must match everywhere). Examples use 1536; replace with your dimension N.<=>)m = 16, ef_construction = 64). Use halfvec_cosine_ops and query with <=>.SET hnsw.ef_search = 100 (good starting point from published benchmarks, increase for higher recall at higher latency)ORDER BY embedding <=> $1::halfvec(N) LIMIT kThis setup provides a strong speed–recall tradeoff for most text-embedding workloads.
CREATE EXTENSION IF NOT EXISTS vector;halfvec by default—store and index as halfvec for 50% smaller storage and indexes with minimal recall loss.CREATE INDEX CONCURRENTLY ...<=>): For non-normalized embeddings, use cosine. For unit-normalized embeddings, cosine and inner product yield identical rankings; default to cosine.halfvec_cosine_ops requires <=> in queries; halfvec_l2_ops requires <->; mismatched operators won't use the index.$1::halfvec(N)) to avoid implicit-cast failures in prepared statements.halfvec(N)halfvec(N)bit(N) in a generated columnvector / halfvec / bit without explicit castsbinary_quantize() on table columns inside ORDER BY; store it insteadhalfvec(1536) column requires query vectors cast as ::halfvec(1536).-- Store and index as halfvec
CREATE TABLE items (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
contents TEXT NOT NULL,
embedding halfvec(1536) NOT NULL -- NOT NULL requires embeddings generated before insert, not async
);
CREATE INDEX ON items USING hnsw (embedding halfvec_cosine_ops);
-- Query: returns 10 closest items. $1 is the embedding of your search text.
SELECT id, contents FROM items ORDER BY embedding <=> $1::halfvec(1536) LIMIT 10;
For other distance operators (L2, inner product, etc.), see the pgvector README.
The recommended index type. Creates a multilayer navigable graph with superior speed-recall tradeoff. Can be created on empty tables (no training step required).
CREATE INDEX ON items USING hnsw (embedding halfvec_cosine_ops);
-- With tuning parameters
CREATE INDEX ON items USING hnsw (embedding halfvec_cosine_ops) WITH (m = 16, ef_construction = 64);
| Parameter | Default | Description |
|---|---|---|
m |
16 | Max connections per layer. Higher = better recall, more memory |
ef_construction |
64 | Build-time candidate list. Higher = better graph quality, slower build |
hnsw.ef_search |
40 | Query-time candidate list. Higher = better recall, slower queries. Should be ≥ LIMIT. |
ef_search tuning (rough guidelines—actual results vary by dataset):
| ef_search | Approx Recall | Relative Speed |
|---|---|---|
| 40 | lower (~95% on some benchmarks) | 1x (baseline) |
| 100 | higher | ~2x slower |
| 200 | very-high | ~4x slower |
| 400 | near-exact | ~8x slower |
-- Set search parameter for session
SET hnsw.ef_search = 100;
-- Set for single query
BEGIN;
SET LOCAL hnsw.ef_search = 100;
SELECT id, contents FROM items ORDER BY embedding <=> $1::halfvec(1536) LIMIT 10;
COMMIT;
Default to HNSW. Use IVFFlat only when HNSW’s operational costs matter more than peak recall.
Choose IVFFlat if:
Avoid IVFFlat if you need:
Notes:
lists and ivfflat.probes; higher probes = better recall, slower queries.Starter config:
CREATE INDEX ON items
USING ivfflat (embedding halfvec_cosine_ops)
WITH (lists = 1000);
SET ivfflat.probes = 10;
halfvec by default for storage and indexing.halfvec (m=16) (order-of-magnitude); 3072-dim is ~2×; m=32 roughly doubles HNSW link/graph overhead.halfvec doesn’t fit, use binary quantization + re-ranking.Approximate halfvec capacity at m=16, 1536-dim (assumes RAM mostly available for index caching):
| RAM | Approx max halfvec vectors |
|---|---|
| 16 GB | ~2–3M vectors |
| 32 GB | ~4–6M vectors |
| 64 GB | ~8–12M vectors |
| 128 GB | ~16–25M vectors |
For 3072-dim embeddings, divide these numbers by ~2.
For m=32, also divide capacity by ~2.
If the index cannot fit in memory at this scale, use binary quantization.
These are ranges, not guarantees. Validate by monitoring cache residency and p95/p99 latency under load.
32× memory reduction. Use with re-ranking for acceptable recall.
-- Table with generated column for binary quantization
CREATE TABLE items (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
contents TEXT NOT NULL,
embedding halfvec(1536) NOT NULL,
embedding_bq bit(1536) GENERATED ALWAYS AS (binary_quantize(embedding)::bit(1536)) STORED
);
CREATE INDEX ON items USING hnsw (embedding_bq bit_hamming_ops);
-- Query with re-ranking for better recall
-- ef_search must be >= inner LIMIT to retrieve enough candidates
SET hnsw.ef_search = 800;
WITH q AS (
SELECT binary_quantize($1::halfvec(1536))::bit(1536) AS qb
)
SELECT *
FROM (
SELECT i.id, i.contents, i.embedding
FROM items i, q
ORDER BY i.embedding_bq <~> q.qb -- computes binary distance using index
LIMIT 800
) candidates
ORDER BY candidates.embedding <=> $1::halfvec(1536) -- computes halfvec distance (no index), more accurate than binary
LIMIT 10;
The 80× oversampling ratio (800 candidates for 10 results) is a reasonable starting point. Binary quantization loses precision, so more candidates are needed to find true nearest neighbors during re-ranking. Increase if recall is insufficient; decrease if re-ranking latency is too high.
| Scale | Vectors | Config | Notes |
|---|---|---|---|
| Small | <100K | Defaults | Index optional but improves tail latency |
| Medium | 100K–5M | Defaults | Monitor p95 latency; most common production range |
| Large | 5M+ | ef_construction=100+ |
Memory residency critical |
| Very Large | 10M+ | Binary quantization + re-ranking | Add RAM or partition first if possible |
Tune ef_search first for recall; only increase m if recall plateaus and memory allows. Under concurrency, tail latency spikes when the index doesn't fit in memory. Binary quantization is an escape hatch—prefer adding RAM or partitioning first.
Filtered vector search requires care. Depending on filter selectivity and query shape, filters can cause early termination (too few rows, missing results) or increase work (latency).
By default, HNSW may stop early when a WHERE clause is present, which can lead to fewer results than expected. Iterative scan allows HNSW to continue searching until enough filtered rows are found.
Enable iterative scan when filters materially reduce the result set.
-- Enable iterative scans for filtered queries
SET hnsw.iterative_scan = relaxed_order;
SELECT id, contents
FROM items
WHERE category_id = 123
ORDER BY embedding <=> $1::halfvec(1536)
LIMIT 10;
If results are still sparse, increase the scan budget:
SET hnsw.max_scan_tuples = 50000;
Trade-off: increasing hnsw.max_scan_tuples improves recall but can significantly increase latency.
When iterative scan is not needed:
Highly selective filters (under ~10k rows) Use a B-tree index on the filter column so Postgres can prefilter before ANN.
CREATE INDEX ON items (category_id);
Low-cardinality filters (few distinct values) Use partial HNSW indexes per filter value.
CREATE INDEX ONPrerequisites
Time Estimate
15-45 minutes depending on use case complexity
Steps
Common Pitfalls
✓ Do
✗ Don't
💡 Pro Tips
✓ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
kostja94/marketing-skills
aaaaqwq/claude-code-skills
agentbay-ai/agentbay-skills
glebis/claude-skills
shopmeskills/mcp
wuchubuzai2018/expert-skills-hub
pgvector-semantic-search reduced setup friction for our internal harness; good balance of opinion and flexibility.
pgvector-semantic-search reduced setup friction for our internal harness; good balance of opinion and flexibility.
Keeps context tight: pgvector-semantic-search is the kind of skill you can hand to a new teammate without a long onboarding doc.
We added pgvector-semantic-search from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
pgvector-semantic-search is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
I recommend pgvector-semantic-search for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
I recommend pgvector-semantic-search for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
Keeps context tight: pgvector-semantic-search is the kind of skill you can hand to a new teammate without a long onboarding doc.
Solid pick for teams standardizing on skills: pgvector-semantic-search is focused, and the summary matches what you get after install.
pgvector-semantic-search has been reliable in day-to-day use. Documentation quality is above average for community skills.
showing 1-10 of 64