code: from llama_index import ServiceContext
  from llama_index import StorageContext, load_index_from_storage
  from omegaconf import DictConfig, OmegaConf
  import hydra
  from llama_index.evaluation import RetrieverEvaluator
  from llama_index.evaluation import (
      EmbeddingQAFinetuneDataset,
  )
  import pandas as pd
  
  
  @hydra.main(version_base=None, config_path="../../conf", config_name="config")
  def main(cfg: DictConfig):
      index_dir = cfg.retriever.evaluate.index_dir
      test_data_path = cfg.retriever.evaluate.test_data_path
      metrics = cfg.retriever.evaluate.metrics
  
      service_context = ServiceContext.from_defaults()
      # rebuild storage context
      storage_context = StorageContext.from_defaults(persist_dir=index_dir)
      # load index
      index = load_index_from_storage(storage_context, service_context=service_context)
      retriever = index.as_retriever()
      retriever_evaluator = RetrieverEvaluator.from_metric_names(
          metrics, retriever=retriever
      )
      total_metrics = {m: 0.0 for m in metrics}
      qa_data = EmbeddingQAFinetuneDataset.from_json(test_data_path)
      metric_dicts = []
      for qid, query in list(qa_data.queries.items())[:3]:
          relevant_doc_ids = qa_data.relevant_docs[qid]
          result = retriever_evaluator.evaluate(
              query=query, expected_ids=relevant_doc_ids
          )
          metric_dicts.append(result.metric_vals_dict)
      full_df = pd.DataFrame(metric_dicts)
      for metric in metrics:
          metric_ave_val = full_df[metric].mean()
          print(f"{metric}: {metric_ave_val}")
  
  
  if __name__ == "__main__":
      main()
  
apis: llama_index.evaluation.EmbeddingQAFinetuneDataset.from_json llama_index.ServiceContext.from_defaults llama_index.StorageContext.from_defaults llama_index.load_index_from_storage llama_index.evaluation.RetrieverEvaluator.from_metric_names
extract_api: [((308, 385), 'hydra.main', 'hydra.main', ([], {'version_base': 'None', 'config_path': '"""../../conf"""', 'config_name': '"""config"""'}), "(version_base=None, config_path='../../conf', config_name='config')\n", (318, 385), False, 'import hydra\n'), ((589, 619), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {}), '()\n', (617, 619), False, 'from llama_index import ServiceContext\n'), ((672, 723), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': 'index_dir'}), '(persist_dir=index_dir)\n', (700, 723), False, 'from llama_index import StorageContext, load_index_from_storage\n'), ((753, 826), 'llama_index.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {'service_context': 'service_context'}), '(storage_context, service_context=service_context)\n', (776, 826), False, 'from llama_index import StorageContext, load_index_from_storage\n'), ((890, 956), 'llama_index.evaluation.RetrieverEvaluator.from_metric_names', 'RetrieverEvaluator.from_metric_names', (['metrics'], {'retriever': 'retriever'}), '(metrics, retriever=retriever)\n', (926, 956), False, 'from llama_index.evaluation import RetrieverEvaluator\n'), ((1031, 1083), 'llama_index.evaluation.EmbeddingQAFinetuneDataset.from_json', 'EmbeddingQAFinetuneDataset.from_json', (['test_data_path'], {}), '(test_data_path)\n', (1067, 1083), False, 'from llama_index.evaluation import EmbeddingQAFinetuneDataset\n'), ((1396, 1422), 'pandas.DataFrame', 'pd.DataFrame', (['metric_dicts'], {}), '(metric_dicts)\n', (1408, 1422), True, 'import pandas as pd\n')]