pgvector Query Builder
client-side · zero network calls · no telemetry · no login
// build query
// presetsThree operators. Three use cases.
Every pgvector distance metric maps to a different mathematical notion of similarity. Picking the wrong one silently returns valid-looking but semantically wrong results.
| Metric | Operator | Best for | Avoid when |
|---|---|---|---|
| Cosine distance | <=> | Normalized embeddings (OpenAI, Cohere, most sentence-transformers). The default for RAG. Measures angle, ignores magnitude. | Embeddings are not normalized to unit length. |
| L2 distance | <-> | Raw un-normalized vectors where magnitude carries meaning. Some image embeddings trained on L2. | Typical text embeddings — cosine is almost always better. |
| Inner product | <#> | Models explicitly trained with dot-product similarity. Note: pgvector sorts ASC — invert sign for max similarity. | Generic embedding models without a known training objective. |
Quick rule: OpenAI text-embedding-3-*, Cohere Embed, or any standard sentence-transformers model — use cosine (<=>).
HNSW vs IVFFlat
pgvector ships two approximate nearest-neighbor index types with different operational tradeoffs.
| Factor | HNSW | IVFFlat |
|---|---|---|
| Build time | Slower (builds the graph) | Faster (builds the inverted file) |
| Query speed | Faster at query time | Slower, especially at high recall |
| Memory | Higher — stores graph edges | Lower baseline |
| Recall | Higher out of the box | Requires tuning lists and probes |
| Incremental inserts | Handles well | Degrades; rebuild periodically |
| Recommended for | Most production RAG applications | Constrained memory, large static datasets |
Start with HNSW, m=16, ef_construction=64. Tune ef_search at query time for recall. Set SET hnsw.ef_search = 100; in the session before querying.
How to confirm this tool never phones home
Open DevTools (F12 or Cmd+Option+I), click the Network tab, then use the query builder above. After the page finishes loading its fonts and CSS, build a query and watch the Network tab. Zero new requests fire. All computation runs in the browser JavaScript engine — no data leaves your machine.
Septim Drills includes 25 Claude Code production skills covering SQL migrations, query optimization, and pgvector integration patterns. Drop into ~/.claude/skills/, reference by name, ship faster.