Similarity Search Patterns

Similarity Search Patterns

Implements efficient similarity search with vector databases: distance metrics, index types, hybrid semantic and keyword search, and scaling retrieval to millions of vectors.

Skill files2 files

references/

SKILL.md65 lines
1
---
2
name: similarity-search-patterns
3
description: Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.
4
---
5
6
# Similarity Search Patterns
7
8
Patterns 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
47
Full 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

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,362 prompts

More by @OpenSourceBuffGuy

See all
Bearded hero sprints from exploding armored vehicle in rain prompt image

Bearded hero sprints from exploding armored vehicle in rain

Generates a seven-second action sequence of a bearded hero fleeing an exploding armored vehicle in a rainy alley, with timed beats, camera moves and negatives.

video-prompt, action, timed-beats, multi-shot, handheld, camera-movement, tracking-shot, cinematic, night-scene, rain, visual-effects, dramatic-lighting, motion-blur, negative-prompt, man, kling, photorealistic, cityscape, moody, trailer

Kaohsiung watercolor collage travel poster at sunset prompt image

Kaohsiung watercolor collage travel poster at sunset

Draws a vertical watercolour and photo-collage travel poster of Kaohsiung at sunset, with exact text strings placed in each corner and teal-beige overlays.

image-prompt, poster, watercolor, collage, typography, text-rendering, travel, cityscape, landmarks, vertical-format, pastel, golden-hour, illustration, ocean, graphic-design, gpt-image, chatgpt, for-designers, for-travelers

Vintage Pomegranate Plant Botanical Growth Atlas Poster prompt image

Vintage Pomegranate Plant Botanical Growth Atlas Poster

Draws a tall vintage botanical atlas poster of a pomegranate plant with eight numbered sections, a 19-step growth strip and bilingual Chinese and English labels.

image-prompt, infographic, poster, illustration, watercolor, ink-drawing, vintage, flowers, biology, education, text-rendering, vertical-format, multi-panel, exploded-view, muted-colors, typography, gpt-image, chatgpt, long-form, structured-output, for-teachers, for-students, step-by-step-guide, classical-art, symmetry

Reviews

Loading reviews…

Discussion

Loading comments…