Skip to content
Back to skills

Pgvector Search

ASecurity

Semantic search with Postgres + pgvector: embeddings, schema with a vector column, HNSW/IVFFlat indexes, similarity queries and RAG. Use to implement semantic search or retrieval on Postgres.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 14, 2026
ai-agentsgobashsqlnextjsgitdatabasebackend

Security analysis

A100/100

Scanned November 14, 2026

npx -y skills add SebastianLuser/claude-code-arcane --skill pgvector-search --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pgvector Search?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pgvector Search
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sebastianluser-pgvector-search/badge)](https://www.skillsdirectory.com/skills/sebastianluser-pgvector-search)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: pgvector-search
description: "Semantic search with Postgres + pgvector: embeddings, schema with a vector column, HNSW/IVFFlat indexes, similarity queries and RAG. Use to implement semantic search or retrieval on Postgres."
category: "backend"
argument-hint: "[setup|index|query|rag]"
user-invocable: true
allowed-tools: Read, Glob, Grep, Bash, Write, Edit, Task
---
# pgvector-search — Semantic search with Postgres

## MANDATORY WORKFLOW

**Before generating or modifying code/schema, complete these steps in order.**

### Step 0: Gather Requirements
1. **Embedding model** and dimension (e.g. OpenAI `text-embedding-3-small` = 1536; Cohere = 1024)
2. **Volume** of vectors (decides the index: HNSW for high recall, IVFFlat for large datasets/frequent writes)
3. **Distance metric:** cosine (`<=>`, default for text) / L2 (`<->`) / inner product (`<#>`)
4. Is it for RAG (retrieval + LLM) or just similarity ranking?

### Step 1: Enable the extension + schema
```sql
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE documents (
  id bigserial PRIMARY KEY,
  content text NOT NULL,
  embedding vector(1536) NOT NULL,
  metadata jsonb
);
```

### Step 2: Index
```sql
-- HNSW: best recall/latency, recommended by default
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);
-- IVFFlat (alternative for very large datasets): set lists ≈ rows/1000
```

### Step 3: Insert embeddings
Generate the embedding of `content` with the model and store it. (If you use Next + AI SDK, see the `ai-sdk-setup` skill.)
```ts
const { embedding } = await embed({ model, value: content });
await sql`INSERT INTO documents (content, embedding) VALUES (${content}, ${JSON.stringify(embedding)})`;
```

### Step 4: Similarity query
```sql
SELECT content, 1 - (embedding <=> $1) AS similarity
FROM documents
ORDER BY embedding <=> $1   -- uses the index
LIMIT 5;
```

### Step 5: Good practices
- **Chunk** the content before embedding (not whole documents)
- Filter by `metadata` (jsonb) + similarity for hybrid search
- `SET hnsw.ef_search` to tune recall vs latency
- Re-embed if the model changes (the dimension must match)
- Do not mix embeddings from different models in the same column

## Wrap-up

Verify the index is used (`EXPLAIN ANALYZE` must show Index Scan, not Seq Scan) and measure recall/latency with real queries. Schema + index + query validated → setup **READY**. Confirm schema changes with the user before applying them. Next step: the `ai-sdk-setup` skill to generate embeddings, or `database-indexing` for tuning.

---

_Inspired by `postgres-semantic-search` from [laguagu/claude-code-nextjs-skills](https://github.com/laguagu/claude-code-nextjs-skills). Adapted to the Arcane format. Related: the `database-indexing` skill._

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.