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.mdCopy 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
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
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
Comments
- β¦
More skills from this repository
screen-reader-testing
41kHas your agent test websites using screen readers to ensure they are accessible.
wcag-audit-patterns
41kHelps your agent audit websites for accessibility and fix issues according to WCAG guidelines.
multi-reviewer-patterns
41kEnables your agent to coordinate parallel code reviews, deduplicating findings and consolidating reports.
parallel-debugging
41kAllows the agent to debug complex issues with parallel investigations and root cause analysis.
Similar skills
pytorch-patterns
280kHelps your agent use PyTorch for machine learning models. It applies best practices for efficient model training and ensures reproducible results.
evm-token-decimals
280kHelps your agent avoid errors with decimal numbers across different blockchain networks. It ensures token values are accurate in transactions and calculations.
ito-inference
280kLets your agent check the availability of AI models for use. It connects the compute request with the ready model service.