Calculate document frequency for two terms

Read identifiers and quoted passages in short groups. · 178 words

Document frequency (DF) is the number of documents in a collection that contain a term at least once. It does not count repeated occurrences inside one document. Imagine five library records. The term "planetarium" occurs in the science-center record and the school-trip record. The term "telescope" occurs in those two records, the store record, and the weather record. The city record contains neither term. Thus, DF("planetarium") = 2 and DF("telescope") = 4. A low-DF term is rare, so it can be a useful retrieval clue.

A retrieval system can use these counts to favor distinctive words. If the query is "Which record mentions a planetarium and a bus?", the system first finds the two records containing "planetarium." It can then compare the other query term and rank the school-trip record first because that record also contains "bus." The retrieved record is passed to a generator. The generator should say, "The school bus visits the planetarium on Friday," only because that fact appears in the record. Grounding means tying the answer to retrieved evidence rather than adding outside information.

Check your recall

In the five-record collection, what are the document frequencies of "planetarium" and "telescope"?

Check your answer

"planetarium" has document frequency 2, while "telescope" has document frequency 4.

Sources and credits

Original KeyTouch lesson. Background reading · Lewis et al. · Retrieval-Augmented Generation.