Similarity search patterns

From mtecoYY/ai-baike · View interactive version

Similarity search patterns is an AI agent skill from the GitHub repository mtecoYY/ai-baike. Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.

How to use this skill

Skill file

Similarity Search Patterns

Patterns for implementing efficient similarity search in production systems.

When to Use This Skill

Core Concepts

1. Distance Metrics

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

2. Index Types

┌─────────────────────────────────────────────────┐
│                 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        │
└─────────────┴───────────────┴───────────────────┘

Templates and detailed worked examples

Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.

Best Practices

Do's

Don'ts

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.