def get_documents(
    query_for_reader: str,
    query_for_retriever: str,
    stub: environment_pb2_grpc.EnvironmentServiceStub,
    retrieval_type: environment_pb2.RetrievalRequestType = environment_pb2
    .LUCENE,
    reader_type: environment_pb2.ReaderRequestType = environment_pb2.DPR_READER,
    num_results: int = 5,
    num_retries: int = 3) -> List[environment_pb2.Document]:
  """Fetch documents and return them sorted by reader scores.

  Args:
    query_for_reader:  Query assumed by the machine reader.  This should be the
      "base" query, i.e. the original query (q0) for which an answer is
      requested and which does not contain operators.
    query_for_retriever:  A potentially modified version of the base query; in
      particular, this query can contain search operators such as + or - and
      field syntax.
    stub:  An EnvironmentServiceStub used for making requests.
    retrieval_type:  What kind fo retrieval is to be used.  Note that only
      LUCENE explicitly supports the use of search operators.
    reader_type:  Which machine reader is used for extracting short answers. The
      extracted answers - one per result - are used both for sorting the
      documents and for determining the "context" available for picking
      refinement terms.
    num_results:  How many documents are to be returned.
    num_retries:  Try at most that many times to obtain results.  If the RPC
      fails more than num_retries time, get_documents will (re)raise the
      RPCException.

  Returns:
    A list of document results for `query_for_retriever`, sorted by the answer
    scores for the answers extracted from the documents assuming
    `query_for_reader`.
  """

  request = environment_pb2.GetDocumentsRequest(
      request_type=retrieval_type,
      reader_request_type=reader_type,
      query=environment_pb2.Query(
          query=query_for_reader, query_with_operations=query_for_retriever),
      max_num_results=num_results)

  attempts = 0
  while True:
    try:
      response = stub.GetDocuments(request)
      break
    except grpc.RpcError as e:
      attempts += 1
      if attempts <= num_retries:
        continue
      raise e

  return sorted(
      response.documents, key=lambda x: x.answer.mr_score, reverse=True)
Fetch documents and return them sorted by reader scores.

  Args:
    query_for_reader:  Query assumed by the machine reader.  This should be the
      "base" query, i.e. the original query (q0) for which an answer is
      requested and which does not contain operators.
    query_for_retriever:  A potentially modified version of the base query; in
      particular, this query can contain search operators such as + or - and
      field syntax.
    stub:  An EnvironmentServiceStub used for making requests.
    retrieval_type:  What kind fo retrieval is to be used.  Note that only
      LUCENE explicitly supports the use of search operators.
    reader_type:  Which machine reader is used for extracting short answers. The
      extracted answers - one per result - are used both for sorting the
      documents and for determining the "context" available for picking
      refinement terms.
    num_results:  How many documents are to be returned.
    num_retries:  Try at most that many times to obtain results.  If the RPC
      fails more than num_retries time, get_documents will (re)raise the
      RPCException.

  Returns:
    A list of document results for `query_for_retriever`, sorted by the answer
    scores for the answers extracted from the documents assuming
    `query_for_reader`.
  
language/search_agents/t5/run_inference_beam.py