pgvector-semantic-search

pgvector-semantic-search is a skill for Claude Code, Codex from timescale/pg-aiguide. It costs 190 tokens per session (3,628 once invoked), scanned A, original, Apache-2.0.

A guide for adding meaning-based search to PostgreSQL using pgvector, an extension that stores and compares numerical representations of text. It covers vector columns, similarity searches, and search indexes.

In plain words
What is it for?
Use it to set up semantic search, nearest-neighbor lookups, and retrieval-augmented generation (RAG), where relevant stored information is retrieved for an AI response. It also covers HNSW and IVFFlat vector indexes.
Why use it?
It helps content match by meaning instead of requiring exact keywords. It also keeps the text and its search data in PostgreSQL, avoiding a separate search database.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Good fit Use it to set up semantic search, nearest-neighbor lookups, and retrieval-augmented generation (RAG), where relevant stored information is retrieved for an AI response. It also covers HNSW and IVFFlat vector indexes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/timescale/pg-aiguide/pgvector-semantic-search
About the project

pg-aiguide is a knowledge and tooling project that gives AI coding assistants version-aware PostgreSQL documentation and curated database practices. Developers use it through agent skills, an MCP server, or a Claude Code plugin to help coding tools generate better PostgreSQL code. The catalogue entries are its skills, instructions, MCP integration, and rule.

timescale/pg-aiguide · 1,835 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add timescale/pg-aiguide --skill pgvector-semantic-search
Clone the repo
git clone --depth 1 https://github.com/timescale/pg-aiguide

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pgvector-semantic-search

README.md
[![agentmods](https://agentmods.dev/badge/skills/timescale/pg-aiguide/pgvector-semantic-search.svg)](https://agentmods.dev/skills/timescale/pg-aiguide/pgvector-semantic-search)
Your own site
<a href="https://agentmods.dev/skills/timescale/pg-aiguide/pgvector-semantic-search"><img src="https://agentmods.dev/badge/skills/timescale/pg-aiguide/pgvector-semantic-search.svg" alt="Measured on agentmods" height="20"></a>
Per session 190 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,628 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • Socket pass 8 Apr 2026
  • Snyk pass 8 Apr 2026
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00190 $0.03628
Opus 5 $0.00095 $0.01814
Sonnet 5 $0.00038 $0.00726
Haiku 4.5 $0.00019 $0.00363

Measured 8d ago against content hash 0c23028b9bc8, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

pgvector-semantic-search scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/pgvector-semantic-search/SKILL.md · 345 lines

How it starts

The opening of the file, as written. The whole thing — 345 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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).

Golden Path (Default Setup)

Use this configuration unless you have a specific reason not to.

  • Embedding column data type: halfvec(N) where N is your embedding dimension (must match everywhere). Examples use 1536; replace with your dimension N.
  • Distance: cosine (<=>)
  • Index: HNSW (m = 16, ef_construction = 64). Use halfvec_cosine_ops and query with <=>.
  • Query-time recall: SET hnsw.ef_search = 100 (good starting point from published benchmarks, increase for higher recall at higher latency)
  • Query pattern: ORDER BY embedding <=> $1::halfvec(N) LIMIT k

This setup provides a strong speed–recall tradeoff for most text-embedding workloads.

Core Rules

  • Enable the extension in each database: CREATE EXTENSION IF NOT EXISTS vector;
  • Use HNSW indexes by default—superior speed-recall tradeoff, can be created on empty tables, no training step required. Only consider IVFFlat for write-heavy or memory-bound workloads.
  • Use halfvec by default—store and index as halfvec for 50% smaller storage and indexes with minimal recall loss.
  • Index after bulk loading initial data for best build performance.
  • Create indexes concurrently in production: CREATE INDEX CONCURRENTLY ...
  • Use cosine distance by default (<=>): For non-normalized embeddings, use cosine. For unit-normalized embeddings, cosine and inner product yield identical rankings; default to cosine.
  • Match query operator to index ops: Index with halfvec_cosine_ops requires <=> in queries; halfvec_l2_ops requires <->; mismatched operators won't use the index.
  • Always cast query vectors explicitly ($1::halfvec(N)) to avoid implicit-cast failures in prepared statements.
  • Always use the same embedding model for data and queries. Similarity search only works when the model generating the vectors is the same.

Read the full file on GitHub · 345 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 345 lines · 190 tokens per session scan A 0c23028b9bc8

Subscribe to this mod's changes

pgvector-semantic-search is a skill published in the GitHub repository timescale/pg-aiguide (1,835 stars, last pushed 3d ago), licensed Apache-2.0. It adds 190 tokens to every session and 3,628 once invoked, about $0.0010 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

laravel-vector-search

Use when implementing semantic/vector search in Laravel 13 with PostgreSQL + pgvector.

fusengine/agents · 22 tokens

azure-horizondb

Expert knowledge for Azure Horizondb development including troubleshooting, best practices, decision making, architecture & design patterns, limits & quotas, security, configuration, integrations & coding patterns, and deployment. Use when using azureai SQL/embeddings, pgvector tuning, Apache AGE graphs, hybrid…

MicrosoftDocs/Agent-Skills · 95 tokens

030201-pgvector-embeddings

Vector search with pgvector — embedding generation (OpenAI or hash), HNSW indexing, cosine similarity search, and enriched product JOIN queries.

natuleadan/skills · 38 tokens

rag-architect

Designs and implements production-grade RAG systems by chunking documents, generating embeddings, configuring vector stores, building hybrid search pipelines, applying reranking, and evaluating retrieval quality. Use when building RAG systems, vector databases, or knowledge-grounded AI applications requiring semantic…

Jeffallan/claude-skills · 73 tokens

database-optimizer

Optimizes database queries and improves performance across PostgreSQL and MySQL systems. Use when investigating slow queries, analyzing execution plans, or optimizing database performance. Invoke for index design, query rewrites, configuration tuning, partitioning strategies, lock contention resolution.

Jeffallan/claude-skills · 54 tokens

postgres-pro

Use when optimizing PostgreSQL queries, configuring replication, or implementing advanced database features. Invoke for EXPLAIN analysis, JSONB operations, extension usage, VACUUM tuning, performance monitoring.

Jeffallan/claude-skills · 41 tokens