Inferensys

Glossary

Hits@K

Hits@K is a standard evaluation metric for knowledge graph completion that measures the proportion of test triples where the correct entity is ranked among the top K predictions by the model.
Moody home-office setup in a converted highrise loft, analyst working late with multiple screens showing knowledge graph visualizations, city lights through large windows behind.
EVALUATION METRIC

What is Hits@K?

Hits@K is a standard evaluation metric for Knowledge Graph Completion (KGC) that measures the proportion of test triples where the correct entity is ranked among the top K predictions by the model.

Hits@K is a binary, rank-based metric used to evaluate the performance of link prediction models in knowledge graph completion. For a given test query (e.g., predicting the tail entity for (Paris, capitalOf, ?)), the model generates a ranked list of candidate entities. If the correct entity appears within the top K positions of this list, it scores a 'hit' (1); otherwise, it scores 0. The final metric is the average hit rate across all test queries, expressed as a percentage or decimal. Common values for K are 1, 3, or 10, with Hits@1 being the strictest measure of precision.

This metric is favored for its intuitive interpretation and direct relevance to real-world applications where only the top few model suggestions are considered. It is often reported alongside Mean Reciprocal Rank (MRR) to provide a more complete performance picture. A key nuance is that Hits@K treats all ranks within the top K equally, unlike MRR which rewards higher ranks. The choice of K depends on the use case: Hits@1 assesses exact-match accuracy, while Hits@10 evaluates the model's ability to include the correct answer in a broader candidate set for downstream filtering.

EVALUATION METRIC

Key Characteristics of Hits@K

Hits@K is a standard evaluation metric for Knowledge Graph Completion (KGC) that measures the proportion of test triples where the correct entity is ranked among the top K predictions by the model.

01

Definition and Core Purpose

Hits@K is a ranking-based metric that quantifies the success of a Knowledge Graph Completion (KGC) model by checking if the correct entity appears within the top K positions of a ranked list of candidate predictions. Its primary purpose is to evaluate the model's practical utility—in many applications, a user or downstream system only reviews the top few suggestions. A higher Hits@K score indicates a model better at surfacing correct answers early in the results.

  • Core Formula: Hits@K = (Number of queries where correct entity rank ≤ K) / (Total number of queries).
  • Result: A value between 0 and 1, often reported as a percentage (e.g., Hits@10 = 0.45 or 45%).
02

The Evaluation Protocol

Calculating Hits@K requires a standardized evaluation protocol to ensure fair comparison between models. For each missing triple in the test set (e.g., (Paris, capitalOf, ?)), the model scores all possible entities that could fill the missing position (the 'tail'). The scores are sorted to create a ranked list. The protocol must carefully handle corrupted triples to avoid false positives.

Key steps include:

  • Filtered Setting (Standard): During ranking, all other known true triples present in the training, validation, and test sets are removed from the candidate list. This prevents the model from being penalized for ranking other true facts above the target.
  • Raw Setting (Less Common): All entities are ranked, including those that form other known true triples. This typically yields lower, less informative scores.
03

Interpretation and Common K Values

The choice of K directly shapes the metric's interpretation and strictness. It acts as a utility threshold, reflecting how many predictions a user is willing to consider.

  • Hits@1: The strictest measure. It asks: "Is the model's single best guess correct?" This indicates high precision and confidence.
  • Hits@3 / Hits@5: Common pragmatic values. They answer: "Is the correct answer in a shortlist I might review?" Balances model confidence with practical recall.
  • Hits@10: A broader, recall-oriented measure. Frequently used in academic benchmarks (e.g., FB15k-237, WN18RR). It assesses if the model can place the answer within a reasonably sized candidate pool.

A model excelling at Hits@1 demonstrates high ranking accuracy, while one with strong Hits@10 but weak Hits@1 may have good recall but lack precision in its top prediction.

04

Comparison with MRR

Hits@K and Mean Reciprocal Rank (MRR) are the two primary metrics for KGC, offering complementary views. Hits@K is a threshold metric, while MRR is a score metric sensitive to the exact rank position.

  • Hits@K: Provides a binary, thresholded view. It does not distinguish between a correct answer ranked 1st vs. ranked Kth. It answers: "Was the answer found in the top K?"
  • Mean Reciprocal Rank (MRR): Averages the reciprocal of the rank of the first correct answer (e.g., rank 1 gives 1/1=1, rank 3 gives 1/3≈0.33). It is more granular, rewarding models that place the correct answer higher.

Use Case: Hits@K is often preferred for user-facing applications where a shortlist is presented. MRR is favored for benchmarking model quality as it differentiates fine-grained ranking performance.

05

Advantages and Limitations

Advantages:

  • Intuitive Interpretation: Easy to understand and communicate (e.g., "The model gets it right in the top 10 guesses 90% of the time").
  • Application-Aligned: Directly reflects the utility in systems where users inspect only top results.
  • Simple Computation: Straightforward to calculate once ranks are determined.

Limitations:

  • Threshold Dependency: The score is entirely dependent on the chosen K. A model can have a high Hits@10 but a low Hits@1.
  • Lack of Granularity: Does not capture the difference between a rank of 1 and a rank of K. Two models with identical Hits@K can have different MRR.
  • Assumes Single Correct Answer: In some KGC tasks, multiple entities could be valid for a single query (e.g., (person, hasChild, ?)). Standard Hits@K typically considers only one ground truth.
06

Practical Considerations in Model Development

When optimizing for Hits@K during model development, engineers must consider several factors:

  • Loss Function Alignment: Ranking loss functions (e.g., pairwise margin-based loss) are often more directly aligned with improving Hits@K than pointwise losses.
  • Negative Sampling Strategy: The quality and difficulty of negative samples used during training critically impact the model's ability to learn discriminative rankings for evaluation.
  • K Selection for Reporting: It is standard to report multiple K values (e.g., Hits@1, Hits@3, Hits@10) to give a full picture of model performance across different utility thresholds.
  • Domain-Specific K: The optimal K is use-case dependent. For a high-stakes fact-checking system, Hits@1 may be critical. For a knowledge graph search assistant, Hits@5 or Hits@10 is more relevant.
EVALUATION METRICS

Hits@K vs. Other KGC Metrics

A comparison of Hits@K against other primary metrics used to evaluate Knowledge Graph Completion (KGC) models, highlighting their distinct measurement focuses and use cases.

MetricHits@KMean Reciprocal Rank (MRR)Mean Rank (MR)

Primary Measurement

Proportion of correct answers in top K

Average of reciprocal ranks of first correct answer

Average rank of the first correct answer

Output Type

Binary (hit/miss)

Continuous score (0 to 1)

Continuous score (≥1)

Interpretation

Higher is better. Measures recall at K.

Higher is better. Balances rank position.

Lower is better. Direct rank penalty.

Sensitivity to Rank

Low (only cares about top K)

High (penalizes lower ranks sharply)

High (linear penalty with rank)

Common Use Case

Production thresholding (e.g., top 10 recommendations)

Overall model ranking quality

Diagnosing model performance issues

Handling of Ties

Ambiguous; depends on tie-breaking strategy.

Sensitive; requires consistent tie-breaking.

Sensitive; average rank can be skewed.

Typical K Values

1, 3, 5, 10

N/A (uses full ranking)

N/A (uses full ranking)

Robustness to Outliers

High (ignores very low ranks)

Moderate (reciprocal dampens effect)

Low (highly skewed by a few bad ranks)

HITS@K

Frequently Asked Questions

Hits@K is a standard evaluation metric for Knowledge Graph Completion (KGC) that measures the proportion of test triples where the correct entity is ranked among the top K predictions by the model.

Hits@K is an evaluation metric for Knowledge Graph Completion (KGC) models that measures the proportion of test queries for which the correct entity is ranked within the top K predictions by the model. It is a standard metric used to assess the quality of link prediction models, where a higher score indicates better model performance at placing correct answers near the top of a ranked list.

For example, in a link prediction task where the model must predict the tail entity for a query (head, relation, ?), the model generates a ranked list of all possible entities. If the correct tail entity is ranked 3rd and K=10, this query contributes a 'hit' to the Hits@10 score. The final metric is the average of these binary hit/miss outcomes across all test queries.

Common values for K are 1, 3, 5, and 10. Hits@1 is the strictest, measuring the model's precision for the top prediction, while Hits@10 is more lenient, indicating the model's ability to include the correct answer in a broader candidate set.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.