def recall_at_k(
        self,
        query: str,
        retrieved_context_chunks: List[str],
        relevance_scores: Optional[List[float]] = None,
        k: Optional[int] = None,
    ) -> float:
        """
        Compute Recall@k for a given query and retrieved context chunks, considering tie handling.

        Args:
            query (str): The input query string.
            retrieved_context_chunks (List[str]): List of retrieved context chunks.
            relevance_scores (Optional[List[float]]): Relevance scores for each retrieved chunk.
            k (Optional[int]): Rank position up to which to compute Recall. If None, compute for all retrieved chunks.

        Returns:
            float: Computed Recall@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
            )

            # Sort retrieved chunks by relevance scores if scores are provided
            if relevance_scores:
                # Get the top-k threshold score (with tie handling)
                sorted_scores = sorted(relevance_scores, reverse=True)
                kth_score = sorted_scores[min(k - 1, len(sorted_scores) - 1)]

                # Include all indices with scores >= kth score
                top_k_indices = [
                    i
                    for i, score in enumerate(relevance_scores)
                    if score >= kth_score
                ]
                retrieved_top_k = [
                    retrieved_context_chunks[i] for i in top_k_indices
                ]
            else:
                # If no relevance scores, use the top-k retrieved chunks as they are
                retrieved_top_k = retrieved_context_chunks[:k]

            # Calculate recall at k with tie handling
            relevant_retrieved = len([
                chunk for chunk in retrieved_top_k if chunk in golden_chunks
            ])
            return (
                relevant_retrieved / len(golden_chunks)
                if len(golden_chunks) > 0
                else 0.0
            )
        else:
            return np.nan

        Compute Recall@k for a given query and retrieved context chunks, considering tie handling.

        Args:
            query (str): The input query string.
            retrieved_context_chunks (List[str]): List of retrieved context chunks.
            relevance_scores (Optional[List[float]]): Relevance scores for each retrieved chunk.
            k (Optional[int]): Rank position up to which to compute Recall. If None, compute for all retrieved chunks.

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