GeoCoordinate filtering with python client library

I’m trying to filter places by geoCoordinates but this code is getting an error

where_filter = {
  'operator': 'WithinGeoRange',
  'valueGeoRange': {
    'geoCoordinates': {
      'latitude': 10.8064,
      'longitude': 106.7323,
    },
    'distance': { 'max': 2000 }
  },
  'path': ['geoLocation']
}
response = (
  client.query
  .get("Place", ["postgresId", "address"])
  .with_additional('id')
  .with_where(where_filter)
  .do()
)
response

The error is as follows:

{'errors': [{'locations': [{'column': 83, 'line': 1}],
   'message': 'Syntax Error GraphQL request (1:83) Expected Name, found String "geoCoordinates"\n\n1: {Get{Place(where: {path: ["geoLocation"] operator: WithinGeoRange valueGeoRange: {"geoCoordinates": {"latitude": 10.8064, "longitude": 106.7323}, "distance": {"max": 2000}}} ){postgresId address _additional {id }}}}\n                                                                                     ^\n',
   'path': None}]}

I’m not sure if I’m missing anything, or does Weaviate python client not support geoLocation filtering? In the documentation that I saw, the python code uses raw query instead (GraphQL - Conditional filters | Weaviate - vector database)

Hi @khoa-cdp ! Welcome to our community :hugs:

Indeed, there seems to have something going on here. This looks like a weaviate-python-client issue. We might need to dig deep into this.

Seems like the queryBuilder is not producing the expected graphql and messing the double quotes.

The workaround, for now, is to call the raw method and query it directly, like so:

get_articles_where = '''
  {
    Get {
      Place(where: {
        operator: WithinGeoRange,
        valueGeoRange: {
          geoCoordinates: {
            latitude: 17.8608,    # latitude
            longitude: 41.5090    # longitude
          },
          distance: {
            max: 200000        # distance in meters
          }
        },
        path: ["geoLocation"] # property needs to be of geoLocation type.
      }) {
        postgresId
        address
        geoLocation {
          latitude
          longitude
        }
      }
    }
  }
'''
query_result = client.query.raw(get_articles_where)
print(query_result)

I have noticed that when using with_where it’s not scaping the fields correclty. We can see that happening when we build the query, instead of doing it

where_filter = {
  'operator': 'WithinGeoRange',
  'valueGeoRange': {
    'geoCoordinates': {
      'latitude': 10.8064,
      'longitude': 106.7323,
    },
    'distance': { 'max': 2000 }
  },
  'path': ['geoLocation']
}
response = (
  client.query
  .get("Place", ["postgresId", "address"])
  .with_additional('id')
  .with_where(where_filter)
  .build() # replaced here from do() to build()
)
response

‘{Get{Place(where: {path: [“geoLocation”] operator: WithinGeoRange valueGeoRange: {“geoCoordinates”: {“latitude”: 10.8064, “longitude”: 106.7323}, “distance”: {“max”: 2000}}} ){postgresId address _additional {id }}}}’

I will ping our team regarding this and update here with more information.

Thanks for reporting :slight_smile:

1 Like

Update! A new PR was produced to fix this issue:

This PR should land on upcoming versions :slight_smile: