design-postgis-tables
Comprehensive PostGIS spatial table design reference covering geometry types, coordinate systems, spatial indexing, and performance patterns for location-based…
Use this skill for setting up vector similarity search with pgvector for AI/ML embeddings, RAG applications, or semantic search. **Trigger when user asks to:** - Store or search vector embeddings in PostgreSQL - Set up semantic search, similarity search, or nearest neighbor
$ npx -y skills add timescale/pg-aiguide --skill pgvector-semantic-search --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/pgvector-semantic-searchContext preview
The summary Claude sees to decide when to auto-load this skill.
Use this skill for setting up vector similarity search with pgvector for AI/ML embeddings, RAG applications, or semantic search. **Trigger when user asks to:** - Store or search vector embeddings in PostgreSQL - Set up semantic search, similarity search, or nearest neighbor
name: pgvector-semantic-search description: | Use this skill for setting up vector similarity search with pgvector for AI/ML embeddings, RAG applications, or semantic search. **Trigger when user asks to:** - Store or search vector embeddings in PostgreSQL - Set up semantic search, similarity search, or nearest neighbor search - Create HNSW or IVFFlat indexes for vectors - Implement RAG (Retrieval Augmented Generation) with PostgreSQL - Optimize pgvector performance, recall, or memory usage - Use binary quantization for large vector datasets **Keywords:** pgvector, embeddings, semantic search, vector similarity, HNSW, IVFFlat, halfvec, cosine distance, nearest neighbor, RAG, LLM, AI search Covers: halfvec storage, HNSW index configuration (m, ef_construction, ef_search), quantization strategies, filtered search, bulk loading, and performance tuning. license: Apache-2.0 compatibility: Requires PostgreSQL 15+ with the pgvector extension metadata: author: tigerdata
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.
This setup provides a strong speed–recall tradeoff for most text-embedding workloads.
-- 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](https://github.com/pgvector/pgvector).
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;
#
AI-optimized PostgreSQL expertise for coding assistants pg-aiguide helps AI coding tools write dramatically better PostgreSQL code.
Repo: timescale/pg-aiguide
Comprehensive PostGIS spatial table design reference covering geometry types, coordinate systems, spatial indexing, and performance patterns for location-based…
Use this skill for general PostgreSQL table design. **Trigger when user asks to:** - Design PostgreSQL tables, schemas, or data models when creating new tables…
Use this skill to analyze an existing PostgreSQL database and identify which tables should be converted to Timescale/TimescaleDB hypertables. **Trigger when…
Use this skill to migrate identified PostgreSQL tables to Timescale/TimescaleDB hypertables with optimal configuration and validation. **Trigger when user asks…
Use this skill for planning, testing, and safely executing PostgreSQL schema migrations — especially when working with production data or shared databases.…
Use this skill to implement hybrid search combining BM25 keyword search with semantic vector search using Reciprocal Rank Fusion (RRF). **Trigger when user…