wshobson/similarity-search-patterns
Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.
npx skills add https://github.com/wshobson/agents --skill similarity-search-patterns
Patterns for implementing efficient similarity search in production systems.
| Metric | Formula | Best For |
| ------------------ | ------------------ | --------------------- | --- | -------------- |
| Cosine | 1 - (A·B)/(‖A‖‖B‖) | Normalized embeddings |
| Euclidean (L2) | √Σ(a-b)² | Raw embeddings |
| Dot Product | A·B | Magnitude matters |
| Manhattan (L1) | Σ | a-b | | Sparse vectors |
┌─────────────────────────────────────────────────┐
│ Index Types │
├─────────────┬───────────────┬───────────────────┤
│ Flat │ HNSW │ IVF+PQ │
│ (Exact) │ (Graph-based) │ (Quantized) │
├─────────────┼───────────────┼───────────────────┤
│ O(n) search │ O(log n) │ O(√n) │
│ 100% recall │ ~95-99% │ ~90-95% │
│ Small data │ Medium-Large │ Very Large │
└─────────────┴───────────────┴───────────────────┘
Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.
Take wshobson/similarity-search-patterns from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.