def postprocess_candidates(candidates, query):
  """Perform additional processing on the candidates retrieved for a query.

  Args:
    candidates (list[Document]): a list of retrieved documents.
    query (Query): the query used to retrieve the documents.

  Returns:
    new_candidates (list[Document]): a list of the same size as candidates.
  """
  # If the query's originating document appears among candidates, remove it.
  candidates = [c for c in candidates if c.uid != query.orig_doc_uid]

  # We shouldn't have lost more than 1 candidate.
  assert len(candidates) >= FLAGS.num_candidates - 1

  # Prepend a null candidate.
  candidates.insert(0, NULL_DOCUMENT)
  candidates = candidates[:FLAGS.num_candidates]
  return candidates
Perform additional processing on the candidates retrieved for a query.

  Args:
    candidates (list[Document]): a list of retrieved documents.
    query (Query): the query used to retrieve the documents.

  Returns:
    new_candidates (list[Document]): a list of the same size as candidates.
  
language/realm/example_generator.py