jina.serve.runtimes.request_handlers.data_request_handler module

class jina.serve.runtimes.request_handlers.data_request_handler.DataRequestHandler(args, logger, \*kwargs*)[source]

Bases: object

Object to encapsulate the code related to handle the data requests passing to executor and its returned values

Initialize private parameters and execute private loading functions.

  • Parameters

    • args (argparse.Namespace) – args from CLI

    • logger (JinaLogger) – the logger provided by the user

    • kwargs – extra keyword arguments

  • async handle(requests)[source]

    Initialize private parameters and execute private loading functions.

    • Parameters

      requests (List[DataRequest]) – The messages to handle containing a DataRequest

      Return type

      DataRequest

      Returns

      the processed message

  • static replace_docs(request, docs)[source]

    Replaces the docs in a message with new Documents.

    • Parameters

      Return type

      None

  • static replace_parameters(request, parameters)[source]

    Replaces the parameters in a message with new Documents.

    • Parameters

      • request (List[DataRequest]) – The request object

      • parameters (Dict) – the new parameters to be used

      Return type

      None

  • static merge_routes(requests)[source]

    Merges all routes found in requests into the first message

    • Parameters

      requests (List[DataRequest]) – The messages containing the requests with the routes to merge

      Return type

      None

  • close()[source]

    Close the data request handler, by closing the executor

  • static get_docs_matrix_from_request(requests, field)[source]

    Returns a docs matrix from a list of DataRequest objects. :type requests: List[DataRequest] :param requests: List of DataRequest objects :type field: str :param field: field to be retrieved :rtype: List[DocumentArray] :return: docs matrix: list of DocumentArray objects

  • static get_parameters_dict_from_request(requests)[source]

    Returns a parameters dict from a list of DataRequest objects. :type requests: List[DataRequest] :param requests: List of DataRequest objects :rtype: Dict :return: parameters matrix: list of parameters (Dict) objects

  • static get_docs_from_request(requests, field)[source]

    Gets a field from the message

    • Parameters

      • requests (List[DataRequest]) – requests to get the field from

      • field (str) – field name to access

      Return type

      DocumentArray

      Returns

      DocumentArray extraced from the field from all messages

  • static reduce(docs_matrix)[source]

    Reduces a list of DocumentArrays into one DocumentArray. Changes are applied to the first DocumentArray in-place.

    Reduction consists in reducing every DocumentArray in docs_matrix sequentially using DocumentArray.:method:reduce. The resulting DocumentArray contains Documents of all DocumentArrays. If a Document exists in many DocumentArrays, data properties are merged with priority to the left-most DocumentArrays (that is, if a data attribute is set in a Document belonging to many DocumentArrays, the attribute value of the left-most DocumentArray is kept). Matches and chunks of a Document belonging to many DocumentArrays are also reduced in the same way. Other non-data properties are ignored.

    Note

    • Matches are not kept in a sorted order when they are reduced. You might want to re-sort them in a later

      step.

    • The final result depends on the order of DocumentArrays when applying reduction.

    • Parameters

      docs_matrix (List[DocumentArray]) – List of DocumentArrays to be reduced

      Return type

      Optional[DocumentArray]

      Returns

      the resulting DocumentArray

  • static reduce_requests(requests)[source]

    Reduces a list of requests containing DocumentArrays inton one request object. Changes are applied to the first request object in-place.

    Reduction consists in reducing every DocumentArray in requests sequentially using DocumentArray.:method:reduce. The resulting DataRequest object contains Documents of all DocumentArrays inside requests.

    • Parameters

      requests (List[DataRequest]) – List of DataRequest objects

      Return type

      DataRequest

      Returns

      the resulting DataRequest