\"algo-nlp-similarity\"

SkillDocs & knowledge

This skill gives your AI the ability to measure how similar texts are, using both word-level and meaning-based comparison. Your AI can find documents that match, spot near-duplicates, and gauge how close two passages are in meaning. It is useful for matching and deduplicating text instead of reading everything yourself.

Available today. Use it from your connected AI after setup.

After adding the skill, give your AI two or more texts and ask how similar they are, or share a set of documents and ask it to find duplicates. Plain requests like 'how similar are these texts' are enough.

Then ask your AI: use the \"algo-nlp-similarity\" skill

What your AI can do with it

  • Find documents similar to one you provide
  • Detect near-duplicate texts in a collection
  • Measure how close two passages are in meaning
  • Compare texts using both word overlap and meaning-based methods
  • Identify duplicates when cleaning up a set of documents

What this skill tells your AI

The instructions your AI receives, as published by charlieviettq/awesome-agent-skill in .claude/skills/algo-nlp-similarity/SKILL.md and read by ahel’s review.

Overview

Text similarity measures how close two texts are in meaning or surface form. Lexical methods (Jaccard, cosine on TF-IDF) compare word overlap. Semantic methods (sentence embeddings) capture meaning even with different words. Choice depends on whether you need exact matching or meaning matching.

When to Use

Trigger conditions:

  • Finding similar or duplicate documents in a collection
  • Matching queries to FAQ answers or knowledge base entries
  • Detecting plagiarism or content reuse

When NOT to use:

  • For topic-level grouping (use topic modeling / LDA)
  • For entity extraction from text (use NER)

Algorithm

IRON LAW: Lexical Similarity ≠ Semantic Similarity
"The car is fast" and "The automobile is speedy" have LOW lexical
similarity (different words) but HIGH semantic similarity (same meaning).
"Bank of the river" and "Bank account" have HIGH lexical similarity
but LOW semantic similarity. Choose the method that matches your
definition of "similar."

Phase 1: Input Validation

Determine: similarity type needed (lexical or semantic), text preprocessing requirements, scale (pairwise vs all-pairs vs query-to-corpus). Gate: Texts preprocessed, method selected.

Phase 2: Core Algorithm

Lexical methods:

  • Jaccard: |A∩B| / |A∪B| on word sets
  • Cosine on TF-IDF vectors: cos(θ) = (A·B) / (|A|×|B|)

Semantic methods:

  • Sentence embeddings: encode texts with sentence-transformers (all-MiniLM-L6-v2)
  • Cosine similarity on embedding vectors
  • For large-scale: use FAISS or Annoy for approximate nearest neighbor search

Phase 3: Verification

Spot-check: highly similar pairs should be genuinely similar. Low-similarity pairs should be genuinely different. Check threshold calibration. Gate: Similarity scores align with human judgment on sample pairs.

Phase 4: Output

Return similarity scores or nearest neighbors.

Output Format

{
  "similarities": [{"text_a": "doc1", "text_b": "doc5", "score": 0.92, "method": "semantic_cosine"}],
  "metadata": {"method": "sentence-transformers", "model": "all-MiniLM-L6-v2", "pairs_computed": 500}
}

Examples

Sample I/O

Input: Text A: "How to reset my password", Text B: "I forgot my login credentials" Expected: Lexical (Jaccard) ≈ 0.07 (almost no word overlap). Semantic ≈ 0.82 (same intent).

Edge Cases

InputExpectedWhy
Identical textsScore = 1.0Exact match
Empty textUndefined or 0Handle gracefully
Different languagesLexical=0, semantic depends on modelMultilingual models can match cross-language

Gotchas

  • Threshold is use-case specific: 0.8 similarity might mean "duplicate" for deduplication but "somewhat related" for recommendation. Calibrate threshold on labeled examples.
  • Text length effects: Cosine on TF-IDF is sensitive to document length. Very short texts have sparse vectors with unreliable similarity. Use embeddings for short texts.
  • Embedding model choice: Different models have different strengths. all-MiniLM-L6-v2 is fast but less accurate than larger models. Match model to performance needs.
  • Computational scaling: All-pairs similarity on N documents is O(N²). For large corpora, use approximate methods (locality-sensitive hashing, FAISS).
  • Domain adaptation: General-purpose embedding models may not capture domain-specific similarity (legal, medical). Fine-tune on domain data for best results.

References

  • For embedding model comparison and benchmarks, see references/model-benchmarks.md
  • For approximate nearest neighbor search at scale, see references/ann-search.md

Signals

GitHub stars
26
Forks
9
Last commit
Jul 2026
Advanced
Catalog kind
skill
Gateway key
algo-nlp-similarity
Source
github.com/charlieviettq/awesome-agent-skill