Skip to content
Skillpedia
Machine learning41k Β· #6726

similarity-search-patterns

What it does

This tool helps find similar information within large datasets, like searching for 'similar items' in a huge catalog. It uses advanced techniques to do this quickly and efficiently.

When to use it

  • βœ“When you want to build a search system that understands the meaning of your query.
  • βœ“When building a system that answers questions based on documents.
  • βœ“To create personalized recommendations for products or content.

Skill link

https://github.com/wshobson/agents/blob/main/plugins/llm-application-dev/skills/similarity-search-patterns/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/wshobson/agents/blob/main/plugins/llm-application-dev/skills/similarity-search-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œFind documents similar to this text about vegan cooking.”

5 new skills a week. 1 minute to read.

How it works

Internally, it converts your data into numbers (vectors) and uses mathematical methods to calculate which numbers are closest to each other. It organizes these numbers into special indexes for very fast searching.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Similarity Search Patterns

Patterns for implementing efficient similarity search in production systems.

When to Use This Skill

  • Building semantic search systems
  • Implementing RAG retrieval
  • Creating recommendation engines
  • Optimizing search latency
  • Scaling to millions of vectors
  • Combining semantic and keyword search

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

  • Use appropriate index - HNSW for most cases
  • Tune parameters - ef_search, nprobe for recall/speed
  • Implement hybrid search - Combine with keyword search
  • Monitor recall - Measure search quality
  • Pre-filter when possible - Reduce search space

Don'ts

  • Don't skip evaluation - Measure before optimizing
  • Don't over-index - Start with flat, scale up
  • Don't ignore latency - P99 matters for UX
  • Don't forget costs - Vector storage adds up
FAQ

What are 'distance metrics'?

These are mathematical formulas that measure how 'far' or 'close' two sets of numbers (vectors) are to each other. This helps in finding similar information.

What are 'index types'?

These are different ways to organize the numerical data to make searching faster. Some are more accurate, others faster, and each is good for a different data size.

What is 'hybrid search'?

It's combining meaning-based (semantic) search with exact keyword search. This way, you find results that are both semantically relevant and contain the words you typed.

Details

Original description by the author

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

repo: wshobson/agents

Popularity

GitHub stars
41k
Ranking position
#6726
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills