code: def dcg(
      relevances: np.ndarray, k: Optional[int] = None
  ) -> np.ndarray:
      """Calculate DCG (Discounted Cumulative Gain) up to position k.
  
      :param relevances: List of true relevance scores (in the order as they are ranked)
      :type relevances: list
      :param k: Position up to which DCG is computed
      :type k: int
      :return: The DCG score at position k
      :rtype: float
      """
      if k:
          relevances = np.asarray(relevances)[:k]
  
      n_relevances = len(relevances)
      if n_relevances == 0:
          return 0.0
  
      discounts = np.log2(np.arange(n_relevances) + 2)
      return np.sum(relevances / discounts)
  
imports: from __future__ import annotations
  from time import time_ns
  from typing import Tuple, Any, Callable, Union, Optional, List
  from dataclasses import dataclass, asdict
  from collections import defaultdict
  from math import ceil
  import numpy
  from usearch.io import load_matrix
  from usearch.index import Index, Matches, BatchMatches, MetricKind, MetricKindBitwise, Key
label_desc: Use image node_id 4 for calling a global function with example usage: dcg(relevances, k) and returns: np, int