使用Weaviate地理定位搜索遇报错,求最小可用运行示例
问题分析与解决方案
1. 核心问题
你使用的Weaviate 1.18.0版本在单机(Standalone)模式下不支持geoCoordinates类型的过滤查询,同时你的查询语句存在属性名拼写错误。
2. 最小可用运行示例
步骤1:调整Docker Compose配置(启用单节点集群模式)
修改docker-compose.yml,切换为集群模式运行Weaviate,以此解锁地理坐标过滤功能:
version: '3.4' services: weaviate: image: semitechnologies/weaviate:1.18.0 ports: - "8080:8080" environment: QUERY_DEFAULTS_LIMIT: 20 AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true' PERSISTENCE_DATA_PATH: "./data" ENABLE_MODULES: text2vec-transformers TRANSFORMERS_INFERENCE_API: http://t2v-transformers:8080 CLUSTER_HOSTNAME: 'node1' t2v-transformers: image: semitechnologies/transformers-inference:sentence-transformers-all-MiniLM-L6-v2 environment: ENABLE_CUDA: '0' # 有GPU的话改为1
步骤2:Schema保持不变(确认属性名)
你的Schema定义正确,属性名为coordinates,注意不要拼写错误:
{ "class": "RealEstate", "description": "Real estates up for rental or purchase.", "moduleConfig": { "text2vec-transformers": { "vectorizeClassName": false } }, "properties": [ { "dataType": ["text"], "description": "A description of the property e.g. number of bathrooms, type of heating etc.", "name": "description" }, { "dataType": ["geoCoordinates"], "description": "The geocoordinate corresponding to the address", "name": "coordinates" } ], "invertedIndexConfig": { "stopwords": { "preset": "en" }, "indexTimestamps": false, "indexNullState": false, "indexPropertyLength": false }, "vectorizer": "text2vec-transformers" }
步骤3:修正查询语句(修复拼写错误)
将查询中的coordinate改为coordinates,确保与Schema属性名一致:
import weaviate # 初始化客户端 client = weaviate.Client("http://localhost:8080") # 导入测试数据 dummy_realestate = { "description": "Dummy house", "coordinates": {"latitude": 52.366667, "longitude": 4.9}, } client.data_object.create(dummy_realestate, class_name="RealEstate") # 修正后的地理坐标过滤查询 query = """ { Get { RealEstate(where: { path: ["coordinates"] operator: WithinGeoRange valueGeoRange: { geoCoordinates: { latitude: 52.5200 longitude: 13.4050 } distance: { max: 200 } } }) { description coordinates { latitude longitude } } } } """ query_result = client.query.raw(query) print(query_result)
步骤4:运行验证
- 启动服务:执行
docker-compose up -d,等待1-2分钟确保所有容器就绪 - 运行上述Python代码,即可执行地理坐标范围查询
3. 额外说明
- Weaviate 1.18.0的单机模式确实不支持地理坐标过滤,必须使用集群模式(单节点集群即可)
- 距离参数
max的默认单位是千米,若需其他单位需额外配置 - 确保transformers推理容器正常运行,否则无法生成数据向量
内容的提问来源于stack exchange,提问作者Anon1284712
相关产品推荐
相关产品推荐

