Similarity Search Patterns

作者 wshobson46891e7e60da無授權條款收錄於 2026年10月8日更新於 2026年10月8日

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

AI 產生的概覽

提供使用向量資料庫實作高效率相似度搜尋的指引,涵蓋距離度量、索引類型與調校實務。

功能
此技能提供在正式環境系統中實作相似度搜尋的模式。它說明餘弦、歐幾里得、點積與曼哈頓等距離度量,並依複雜度、召回率與適用資料規模比較 Flat、HNSW 與 IVF+PQ 等索引類型。它也列出參數調校、混合搜尋、召回率監控、預先過濾與成本意識等最佳實務,並在參考檔案中提供更多範本與詳細範例。
適用情境
適用於建置語意搜尋或 RAG 檢索、實作最近鄰查詢、建立推薦引擎,以及最佳化與擴展向量搜尋延遲的情境。也適合需要選擇索引類型並權衡召回率與速度的團隊。
執行需求
未附指令碼,僅為說明性內容。它引用配套檔案 references/details.md 以取得範本與詳細範例。未說明需要特定工具、套件、執行環境、憑證或網路存取。

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

來源與署名

來源:wshobson/agents位於plugins/llm-application-dev/skills/similarity-search-patterns提交46891e7

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架