Skills · Data & AI

Similarity Search Patterns

Unverified30/40

Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add similarity-search-patterns

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.

The whole source

No sign-in, no blur, nothing truncated
similarity-search-patterns/SKILL.md65 lines2.7 KBRawView on GitHub
Frontmatter — 2 properties
namesimilarity-search-patterns
descriptionImplement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.
1---
2name: similarity-search-patterns
3description: Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.
4---A5No allowed-tools declared — no way to tell what this skill may touch
5 
6# Similarity Search Patterns
7 
8Patterns for implementing efficient similarity search in production systems.
9 
10## When to Use This Skill
11 
12- Building semantic search systems
13- Implementing RAG retrieval
14- Creating recommendation engines
15- Optimizing search latency
16- Scaling to millions of vectors
17- Combining semantic and keyword search
18 
19## Core Concepts
20 
21### 1. Distance Metrics
22 
23| Metric | Formula | Best For |
24| ------------------ | ------------------ | --------------------- | --- | -------------- |
25| **Cosine** | 1 - (A·B)/(‖A‖‖B‖) | Normalized embeddings |
26| **Euclidean (L2)** | √Σ(a-b)² | Raw embeddings |
27| **Dot Product** | A·B | Magnitude matters |
28| **Manhattan (L1)** | Σ | a-b | | Sparse vectors |
29 
30### 2. Index Types
31 
32```
33┌─────────────────────────────────────────────────┐
34│ Index Types │
35├─────────────┬───────────────┬───────────────────┤
36│ Flat │ HNSW │ IVF+PQ │
37│ (Exact) │ (Graph-based) │ (Quantized) │
38├─────────────┼───────────────┼───────────────────┤
39│ O(n) search │ O(log n) │ O(√n) │
40│ 100% recall │ ~95-99% │ ~90-95% │
41│ Small data │ Medium-Large │ Very Large │
42└─────────────┴───────────────┴───────────────────┘
43```
44 
45## Templates and detailed worked examples
46 
47Full template library and detailed worked examples live in `references/details.md`. Read that file when you need the concrete templates.
48 
49## Best Practices
50 
51### Do's
52 
53- **Use appropriate index** - HNSW for most cases
54- **Tune parameters** - ef_search, nprobe for recall/speed
55- **Implement hybrid search** - Combine with keyword search
56- **Monitor recall** - Measure search quality
57- **Pre-filter when possible** - Reduce search space
58 
59### Don'ts
60 
61- **Don't skip evaluation** - Measure before optimizing
62- **Don't over-index** - Start with flat, scale up
63- **Don't ignore latency** - P99 matters for UX
64- **Don't forget costs** - Vector storage adds up
65 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Data & AI