AI GLOSSARY · AI CONCEPTS

TF-IDF

Markdown version · Wikidata Q796584

Definition

TF-IDF (term frequency, inverse document frequency) is a way to weight words in a document. A word scores high when it appears often in that document but in few other documents of the collection.

Also called: tf idf, tfidf, term frequency inverse document frequency, tf-idf weighting, tf-idf score.

In plain language

TF-IDF is a scoring trick for text. Imagine searching a pile of recipes for one that is about saffron. The word the appears everywhere, so it tells you nothing, while saffron appears in only a few recipes, so a recipe that mentions it often is probably about it. TF-IDF multiplies how often a word appears in one document by how rare the word is across all documents. It does not understand meaning: it treats words as separate tokens and cannot tell that two different words mean the same thing.

Technical definition

TF-IDF is the product of term frequency and inverse document frequency. Wikipedia describes a high tf-idf weight as reached by a high term frequency in the given document combined with a low document frequency across the collection. Scikit-learn defines tf-idf(t,d) = tf(t,d) times idf(t), with a smoothed idf by default and L2 normalisation of each row.

Worked examples in this catalogue

Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.

  1. Skill by Skill Almanac · Illustrative, not executed

    keyword-density-count 41/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    The skill counts how often each keyword or phrase appears in plain page text and reports case-insensitive, whole-word counts and density figures.
    Why it exercises the concept
    Counting how often a word appears in one text is the term-frequency half of the idea. The skill has no inverse-document-frequency step, so it shows only half of TF-IDF.
  2. Skill by Skill Almanac · Illustrative, not executed

    duplicate-passage-finder 41/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    The skill finds exact and near-duplicate paragraphs across a folder of text and Markdown files and reports each group with its file and line number.
    Why it exercises the concept
    Comparing passages across a set of files is a task where word-level comparison matters. The skill's description does not say it uses TF-IDF, so treat it as an adjacent task.
  3. Guide · Illustrative, not executed

    What Is RAG? Retrieval-Augmented Generation Explained

    What you see
    A guide to retrieval-augmented generation, in which an agent looks up passages from your documents and gives them to the model before it answers.
    Why it exercises the concept
    The guide describes the retrieval step, where an agent looks up passages from your documents before the model answers. TF-IDF is background here, not something the guide names.

How it shows up when you use agents

TF-IDF is classic keyword scoring from natural language processing. You meet it when an agent searches a folder of documents or a codebase and ranks files by the words they contain. See BM25 for a related ranking function.

See Embedding for the vector alternative; the semantic search entry explains meaning-based search. In retrieval-augmented generation, the retrieval step can use keyword scoring, embeddings or both, and the what is RAG guide walks through the flow.

What breaks when TF-IDF is misunderstood: a search for one phrase misses a document that uses different words for the same idea, because TF-IDF matches words. A next step in a Claude Code or Codex session is to ask what ranking method a search tool uses before trusting its results, and to test it with a query you know the answer to. In scikit-learn the method is available as a vectorizer, so a script an agent writes for you may use it without saying so.

Common confusions

  • TF-IDF versus embeddings. TF-IDF scores words by counts and rarity. Embeddings place text in a space where similar meanings sit close together.
  • TF-IDF versus BM25. BM25 is a separate ranking function; see BM25.
  • Term frequency versus TF-IDF. Term frequency alone favours common words. The idf part lowers the weight of words found in many documents.
  • Myth: TF-IDF understands what a document is about. It counts words. It has no model of meaning.

Terms that mention TF-IDF

3 terms mention this one

More in AI concepts

Next steps

  1. What Is RAG? Retrieval-Augmented Generation Explained The long-form guide.
  2. keyword-density-count A skill that exercises it.
  3. BM25 Related term.
  4. Embedding Related term.
  5. All glossary terms A to Z and by family.

Sources

Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.

Review record

Last verified

Drafted by claude-sonnet-5-5; sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .

Change log (4)
  • : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
  • : First version.
  • : Verifier pass: removed textbook-only claims and the unreadable PDF source, added the Wikipedia tf-idf page, reworded BM25, embedding and RAG-guide lines.
  • : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.