Skip to content
induwara.lk
induwara.lkMachine Learning · Metrics

Precision@K and Recall@K Calculator

Score the top-K results of a retriever, search ranker or RAG pipeline in seconds. Paste a ranked 0/1 relevance list, or type the counts, and get Precision@K, Recall@K, F1@K and Hit Rate@K with a per-K breakdown. No signup, no ads.

By Induwara AshinsanaUpdated Jul 6, 2026
Precision@K & Recall@K calculator

For each retrieved result in ranked order, enter 1 if it is relevant or 0 if not. Separate with commas, spaces, or new lines. Binary only, up to 1000 items.5 item(s), 3 marked relevant.

How many relevant items exist for this query in the whole collection.

How deep into the ranked list to evaluate. Max = list length.

Examples
Precision@3
0.6667
2 / 3 = 66.67%
Recall@3
0.5000
2 / 4 = 50%
F1@3
0.5714
57.14%
Hit Rate@3
1
≥ 1 relevant in top-K

2 of your top-3 results were relevant (Precision@3 = 67%), which captures 50% of all 4 relevant items (Recall@3 = 50%).

Moderate, a fair share of the top-K is noise.

Step-by-step working

  1. hits@K = relevant items in the top K = 2
  2. Precision@K = hits / K = 2 / 3 = 0.6667
  3. Recall@K = hits / R = 2 / 4 = 0.5000
  4. F1@K = 2·P·R / (P + R) = 0.5714 [cross-check 2·hits/(K+R) = 4 / 7 = 0.5714]
  5. Hit Rate@K = 1 if hits ≥ 1 else 0 = 1

Per-K breakdown

KFoundPrecision@KRecall@KF1@K
111.00000.25000.4000
210.50000.25000.3333
3chosen20.66670.50000.5714
430.75000.75000.7500
530.60000.75000.6667

Computed entirely in your browser, nothing is uploaded. Definitions per Manning et al., IR-book Ch. 8 and scikit-learn; F1 cross-check passed; last verified 2026-07-06.

How it works

Precision@K and Recall@K evaluate the top K results a ranked system returns for a single query, a search engine, a recommender, or the retriever inside a RAG pipeline. Both start from the same count: how many of the top K results are actually relevant. Call that hits@K. These are the standard information-retrieval definitions from Manning, Raghavan & Schütze, Introduction to Information Retrieval (Chapter 8).

Precision@K asks how clean the top K is:Precision@K = hits@K / KOf the K results you showed, what fraction were right? It penalises padding the list with noise. Precision@K tends to fall as K grows, because you are forced to include lower-ranked, less certain results.

Recall@K asks how much of the relevant set you captured:Recall@K = hits@K / Rwhere R is the total number of relevant items that exist for the query. Recall@K rises (never falls) as K grows, because a deeper cutoff can only find more of the relevant set. If R = 0the ratio divides by zero, so recall is undefined and this tool reports N/A instead of a misleading 0.

F1@K combines the two into one number using the harmonic mean:F1@K = 2 · P · R / (P + R)The harmonic mean sits close to the smaller of the two, so a system cannot earn a high F1@K by being precise but incomplete, or thorough but noisy. There is an equivalent count form, F1@K = 2·hits / (K + R), that gives the same answer without ever forming precision or recall. This calculator computes F1@K both ways and cross-checks them, which is what the “Formulas verified” badge means.

Hit Rate@K is the simplest signal:Hit Rate@K = 1 if hits@K ≥ 1 else 0It answers “did we retrieve anycorrect result in the top K?”, the check RAG developers care about most, since one good chunk is often enough for the language model to answer. In ranked-list mode the tool recomputes all three ratio metrics at every cutoff from K = 1 to the list length, so you can watch the precision–recall trade-off and choose the top-K depth that fits your task.

Worked examples

RAG retriever, ranked list, labels [1, 0, 1, 1, 0], R = 4, K = 3

  1. Top-3 labels = [1, 0, 1] → hits@3 = 2
  2. Precision@3 = hits / K = 2 / 3 = 0.6667
  3. Recall@3 = hits / R = 2 / 4 = 0.5000
  4. F1@3 = 2 × (0.6667 × 0.5) / (0.6667 + 0.5) = 0.66667 / 1.16667 = 0.5714
  5. Cross-check: 2 × hits / (K + R) = 2 × 2 / (3 + 4) = 4 / 7 = 0.5714, matches
  6. Hit Rate@3 = 1 (at least one relevant chunk in the top 3)

Retriever, counts only, hits = 3, K = 5, R = 6

  1. Precision@5 = hits / K = 3 / 5 = 0.6000
  2. Recall@5 = hits / R = 3 / 6 = 0.5000
  3. F1@5 = 2 × (0.6 × 0.5) / (0.6 + 0.5) = 0.60 / 1.10 = 0.5455
  4. Cross-check: 2 × 3 / (5 + 6) = 6 / 11 = 0.5455, matches
  5. Hit Rate@5 = 1

Edge case, missed everything (hits = 0, K = 10, R = 4)

  1. Precision@10 = 0 / 10 = 0.0000
  2. Recall@10 = 0 / 4 = 0.0000
  3. Precision + recall = 0 → F1@10 is reported as 0
  4. Hit Rate@10 = 0 (no relevant item anywhere in the top 10)
  5. A zero across the board flags a retriever that is not finding the right documents at all

Frequently asked questions

Sources & references

The definitions on this page were last cross-checked against the IR-book and scikit-learn on 2026-07-06. These are standard mathematical definitions that do not change over time; F1@K is verified by computing it two independent ways and confirming they agree.

Related tools

Comments & feedback

Spotted a bug or want an improvement? Tell us, our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] , most fixes ship within 24 hours.