def ir_hit_rate(
        self,
        query: str,
        retrieved_context_chunks: List[str],
        k: Optional[int] = None,
    ) -> float:
        """
        Compute IR Hit Rate (Hit Rate@k) for a given query and retrieved context chunks.

        Args:
            query (str): The input query string.
            retrieved_context_chunks (List[str]): List of retrieved context chunks.
            k (Optional[int]): Rank position up to which to compute Hit Rate. If None, compute for all retrieved chunks.

        Returns:
            float: Computed Hit Rate@k score.
        """
        ground_truth_context_chunks = (
            self._find_golden_context_chunks_and_scores(query)
        )
        if ground_truth_context_chunks:
            k = k or len(retrieved_context_chunks)

            # Extract ground truth chunks
            golden_chunks = set(
                chunk[0] for chunk in ground_truth_context_chunks
            )

            # Calculate hit rate at k (1 if at least one relevant item is retrieved, 0 otherwise)
            return (
                1.0
                if any(
                    chunk in golden_chunks
                    for chunk in retrieved_context_chunks[:k]
                )
                else 0.0
            )
        else:
            return np.nan

        Compute IR Hit Rate (Hit Rate@k) for a given query and retrieved context chunks.

        Args:
            query (str): The input query string.
            retrieved_context_chunks (List[str]): List of retrieved context chunks.
            k (Optional[int]): Rank position up to which to compute Hit Rate. If None, compute for all retrieved chunks.

        Returns:
            float: Computed Hit Rate@k score.
        
src/feedback/trulens/feedback/groundtruth.py