<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query_relations(self, environment_id, collection_id, entities=None, context=None, sort=None, filter=None, count=None, evidence_count=None, **kwargs):
 """ Knowledge Graph relationship query. See the [Knowledge Graph documentation](https://cloud.ibm.com/docs/services/discovery?topic=discovery-kg#kg) for more details. :param str environment_id: The ID of the environment. :param str collection_id: The ID of the collection. :param list[QueryRelationsEntity] entities: An array of entities to find relationships for. :param QueryEntitiesContext context: Entity text to provide context for the queried entity and rank based on that association. For example, if you wanted to query the city of London in England your query would look for `London` with the context of `England`. :param str sort: The sorting method for the relationships, can be `score` or `frequency`. `frequency` is the number of unique times each entity is identified. The default is `score`. This parameter cannot be used in the same query as the **bias** parameter. :param QueryRelationsFilter filter: :param int count: The number of results to return. The default is `10`. The maximum is `1000`. :param int evidence_count: The number of evidence items to return for each result. The default is `0`. The maximum number of evidence items per query is 10,000. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse """


        if environment_id is None:
            raise ValueError('environment_id must be provided')
        if collection_id is None:
            raise ValueError('collection_id must be provided')
        if entities is not None:
            entities = [
                self._convert_model(x, QueryRelationsEntity) for x in entities
            ]
        if context is not None:
            context = self._convert_model(context, QueryEntitiesContext)
        if filter is not None:
            filter = self._convert_model(filter, QueryRelationsFilter)

        headers = {}
        if 'headers' in kwargs:
            headers.update(kwargs.get('headers'))
        sdk_headers = get_sdk_headers('discovery', 'V1', 'query_relations')
        headers.update(sdk_headers)

        params = {'version': self.version}

        data = {
            'entities': entities,
            'context': context,
            'sort': sort,
            'filter': filter,
            'count': count,
            'evidence_count': evidence_count
        }

        url = '/v1/environments/{0}/collections/{1}/query_relations'.format(
            *self._encode_path_vars(environment_id, collection_id))
        response = self.request(
            method='POST',
            url=url,
            headers=headers,
            params=params,
            json=data,
            accept_json=True)
        return response