What is TF-IDF?
TF-IDF weights a word by how often it appears in a document and how rare it is across the collection. BM25 is a refinement of it.
In short. TF-IDF is a word weight that multiplies how often a word appears in a document by how rare the word is across the collection. It stands for term frequency, inverse document frequency. A word that is frequent in one document and rare elsewhere gets a high weight, and a word found in almost every document gets almost none. BM25, a common keyword ranking function, is a refinement of TF-IDF.
On this page 7 sections
The evidence
- Confirmed:
Introduction to Information Retrieval defines the tf-idf weight of a term in a document as its term frequency multiplied by its inverse document frequency. The inverse document frequency is the log of the number of documents divided by the number that contain the term.1Introduction to Information Retrieval, Cambridge University Press
Cambridge University Press textbook, online edition. Checked Dec 1, 2026.
- Confirmed:
The weight is highest when a term occurs many times within a small number of documents, and lowest when the term occurs in virtually all documents.1Introduction to Information Retrieval, Cambridge University Press
Cambridge University Press textbook, online edition. Checked Dec 1, 2026.
- Confirmed:
Confirmed by the platform
TF-IDF scores how much a word says about a document. It is one of the oldest ideas in keyword search, and the BM25 ranking that AI retrieval systems still run is a refinement of it.
#How is TF-IDF calculated?
TF-IDF multiplies two numbers for each word in each document. The tf-idf chapter of Introduction to Information Retrieval, a Cambridge University Press textbook, defines them as follows:1
- Term frequency (tf) is the number of times the word occurs in the document.
- Inverse document frequency (idf) is log(N / df), where N is the number of documents in the collection and df is the number of documents that contain the word.
The textbook's section on inverse document frequency explains the second number. The idf of a rare term is high, and the idf of a frequent term is likely to be low. The base of the logarithm does not change the ranking.2
Take a collection of 1,000,000 documents and base-10 logarithms. A word that appears in 10 documents has an idf of log(100,000), which is 5. If it occurs 3 times in a page, its tf-idf weight there is 15. A word that appears in all 1,000,000 documents has an idf of log(1), which is 0, so its weight is 0 in every document.
#What does TF-IDF do in search ranking?
TF-IDF lets rare, specific words decide a match. Microsoft's page on full text search in Azure AI Search gives an example. In an index of all Wikipedia articles, for the query "the president", documents that match on "president" are more relevant than documents that match on "the".3
The textbook also treats each document as a vector, with one tf-idf weight for each word in the dictionary and 0 for the words it does not contain.1 Search systems compare such vectors with cosine similarity. The document frequency comes from the dictionary of the inverted index.
#What is the difference between TF-IDF and BM25?
BM25 is a refinement of TF-IDF. Anthropic's post on Contextual Retrieval says TF-IDF measures how important a word is to a document in a collection. BM25 also considers document length and applies a saturation function to term frequency, which helps prevent common words from dominating the results.5 BM25 explains the formula.
#Is TF-IDF still used in AI search?
TF-IDF and its refinement BM25 are still in use. The Dense Passage Retrieval paper called sparse vector models such as TF-IDF and BM25 the de facto method for passage retrieval in open-domain question answering in 2020.4 Anthropic's description of a standard RAG pipeline creates TF-IDF encodings and embeddings for each chunk, then uses BM25 for exact matches and embeddings for meaning.5
What is semantic search? compares keyword weighting of this kind with search by embeddings.
Read next
AI search
What is semantic search and how does it differ from keyword search?
Semantic search matches the meaning of a query, often with vector embeddings. Keyword search matches its words. Hybrid search runs both and merges the results.
AI search
What is retrieval-augmented generation (RAG)?
RAG retrieves documents at query time and gives them to a language model to write a cited answer. How ChatGPT, Claude, Google, Bing and Perplexity use it.
LLMs
What are vector embeddings?
A vector embedding is a list of numbers that represents the meaning of text. OpenAI's text-embedding-3-large returns 3,072 of them by default.
Related terms
Questions
What does TF-IDF stand for?
Term frequency, inverse document frequency. Term frequency counts how often a word appears in a document. Inverse document frequency is high for words that few documents contain.
How is TF-IDF different from BM25?
BM25 builds on TF-IDF. Anthropic says BM25 also considers document length and applies a saturation function to term frequency, which helps prevent common words from dominating the results.
Can TF-IDF match synonyms?
No. TF-IDF weights only the words that a document contains, so a document that uses a synonym gets no weight for the query word. Dense retrieval compares embeddings to match meaning instead.
About this page
Researched and reviewed by Promptly Found. Reviewed Dec 1, 2026. Next review due Mar 2027.
Notes
- 1
- 2
- 3
- 4
- 5
Cite this page
Promptly Found. (2026, December 1). What is TF-IDF? https://promptlyfound.com/glossary/tf-idf
Revisions 1
- First published.