Skip to content
Skillpedia
Machine learning41k · #4893

similarity-search-patterns

Helps your agent find similar items in large datasets. It's useful for building similarity searches or finding an item's nearest neighbors.

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.

Example of what to ask your AI

“Find documents similar to this text about vegan cooking.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

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

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

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add wshobson/agents --skill similarity-search-patterns

Or download just the file:

curl -L https://raw.githubusercontent.com/wshobson/agents/main/plugins/llm-application-dev/skills/similarity-search-patterns/SKILL.md -o SKILL.md
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
#4893
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills