Precision@k, also written precision at k, is a ranking metric that measures the fraction of the top k retrieved items that are relevant to a query. Retrieval & knowledge systems in artificial intelligence, from classic search engines to retrieval-augmented generation (RAG), use it to answer a simple question: of the results a user or a language model actually sees, how many are useful?
The metric is computed per query and then averaged across a test set. It is easy to explain, cheap to calculate and closely tied to user experience, but it ignores the order of results inside the cutoff and the number of relevant documents that were missed, so it is rarely reported alone.
How precision@k is calculated
Precision@k is calculated by counting relevant items in the first k positions and dividing by k. Formally, P@k = (number of relevant results in the top k) / k, and the value always lies between 0 and 1. Relevance comes from human judgments, labeled datasets or, increasingly, an LLM acting as a judge.
The calculation uses binary relevance: a result either counts or it does not. Graded labels such as highly relevant and partially relevant must first be converted with a relevance threshold, which is a design decision that changes the score.
The table below works through one query whose top five results contain three relevant documents, at positions 1, 3 and 4.
| Cutoff k | Relevant in top k | Precision@k |
|---|---|---|
| k = 1 | 1 | 1.00 |
| k = 2 | 1 | 0.50 |
| k = 3 | 2 | 0.67 |
| k = 4 | 3 | 0.75 |
| k = 5 | 3 | 0.60 |
The example shows that precision@k is not monotonic in k. A score can rise or fall as the cutoff grows, which is why teams fix k in advance and report it explicitly, for example P@5 or P@10.
Across a test set, the per-query values are combined by macro averaging, giving every query equal weight regardless of how many relevant documents it has. Micro averaging, which pools all hits and all slots, is uncommon for ranking because it lets queries with long result lists dominate. Reports should also state the number of queries and the judging method, since a score of 0.6 from 50 queries labeled by a model is not comparable with 0.6 from 500 queries labeled by trained assessors.
Choosing the cutoff k
The cutoff should match how many results are actually consumed. In web search, users scan roughly the first page, so P@10 became a long-standing standard in TREC evaluations. In RAG, k should equal the number of chunks passed to the model, because those are the only passages that can influence the answer.
| Application | Typical k | Reason |
|---|---|---|
| Web or site search | 5 to 10 | Users rarely look past the first page |
| RAG context window | 3 to 20 | Equals the number of chunks given to the model |
| Recommendation carousel | 5 to 12 | Matches visible slots on screen |
| Legal or patent review | 50 to 100 | Analysts read long result lists |
| Reranker stage | Final top n | Only reranked items reach the user |
A common mistake is to choose k larger than the number of relevant documents. If a query has only two relevant documents, P@10 cannot exceed 0.2, even for a perfect ranking. R-precision, which sets k equal to the number of relevant documents, avoids this ceiling.
Precision@k compared with related metrics
Precision@k answers a narrow question, and complementary metrics cover what it leaves out. Recall@k measures coverage, while rank-aware metrics reward placing relevant items higher. The table below compares the metrics most often reported next to it.
| Metric | What it measures | Rank-aware | Graded relevance |
|---|---|---|---|
| Precision@k | Share of top k that is relevant | No | No |
| Recall@k | Share of all relevant items found in top k | No | No |
| Mean reciprocal rank | Position of the first relevant item | Yes | No |
| Mean average precision | Precision averaged at each relevant position | Yes | No |
| nDCG@k | Discounted gain against an ideal ranking | Yes | Yes |
Precision and recall pull in opposite directions. Increasing k usually raises recall and lowers precision, and the F1@k score combines both into one number when a balance is needed.
Precision@k in RAG and agent pipelines
In retrieval-augmented generation, precision@k is a direct proxy for context quality. Irrelevant chunks in the prompt waste tokens, distract the model and increase the risk of ungrounded or contradictory answers, so many RAG evaluation frameworks report a context precision score derived from the same idea.
- Rerankers such as cross-encoders are usually judged by how much they raise P@k at a small cutoff.
- Hybrid search combining BM25 and dense retrieval often improves precision on keyword-heavy queries.
- Metadata filtering removes off-topic candidates before ranking and can raise precision sharply.
- Chunk size matters: very large chunks may be judged relevant while containing mostly noise.
Limitations and common pitfalls
Precision@k is insensitive to order within the cutoff, so a system that places the only relevant item at position 10 scores the same as one that places it first. It also says nothing about missed documents, which matters in tasks where completeness is essential.
| Pitfall | Consequence | Mitigation |
|---|---|---|
| Unjudged documents | Unknown items counted as irrelevant | Judge pooled results or report judged-only precision |
| Too few test queries | High variance between runs | Use hundreds of queries and confidence intervals |
| Duplicates in results | Inflated scores from near-identical hits | Deduplicate before scoring |
| Fewer than k results | Inconsistent denominators | State whether missing slots count as zero |
Averaging also hides differences between query types. Reporting precision@k per query segment, for example navigational versus exploratory questions, usually reveals more than a single global mean.
Finally, a high precision@k can be achieved by a system that returns very few results or plays safe with obvious matches. Pairing it with recall@k and tracking the share of queries with zero relevant results guards against optimizing a number that users do not experience as better search.
The short version
Imagine asking a librarian for books on a topic. The librarian hands you five. If three of them are useful, the precision at five is three out of five, or 60 percent.
That is all precision@k does. It checks how clean the top of the list is. It does not care about good books left on the shelf, and it does not care whether the best book came first or last in your stack.
Where it makes a difference
An internal support assistant at a software company answers employee questions with RAG over 40,000 help articles. The team sends the top 8 chunks to the language model and builds a test set of 300 real questions with human relevance labels. The baseline dense retriever reaches a mean P@8 of 0.41, so more than half of every prompt is noise.
After adding a cross-encoder reranker and a filter on product version, mean P@8 rises to about 0.68. The engineers then reduce k to 5, since most answers need only two or three passages. Shorter, cleaner prompts cut token cost per query by roughly a third, and reviewers report fewer answers that mix instructions from different product versions.