def put(collection_name: str, vectors: List[List[float]], payloads, ids=None): ids = [uuid.uuid4().hex for _ in vectors] response = client.upsert(collection_name=collection_name, points=models.Batch.construct( ids=ids, vectors=vectors, payloads=payloads), ) if name == 'main': a,b=search() put('WhaleChat',b,a) qdrant_client.http.exceptions.UnexpectedResponse: Unexpected Response: 400 (Bad Request) Raw response content: b'{"status":{"error":"Format error in JSON body: data did not match any variant of untagged enum BatchVectorStruct at line 1 column 8451277"},"time":0.0}' 哪里用到了json格式的参数 需要怎么改正json的格式
时间: 2024-04-13 14:29:23 浏览: 177
在这段代码中,`json`格式的参数被用在了`client.upsert`方法的`points`参数中。具体来说,`models.Batch.construct`方法构建了一个包含`ids`、`vectors`和`payloads`的字典,并将其作为`points`参数传递给了`client.upsert`方法。
根据错误信息,看起来是在构建`BatchVectorStruct`这个数据结构时出现了问题。可以尝试按照正确的格式重新构建这个数据结构。具体来说,可以使用`models.BatchVectorStruct`类来创建对象,并将其作为`points`参数传递给`client.upsert`方法。
以下是修改后的代码示例:
```python
from qdrant_client.models import BatchVectorStruct
def put(collection_name: str, vectors: List[List[float]], payloads, ids=None):
ids = [uuid.uuid4().hex for _ in vectors]
batch_vectors = BatchVectorStruct(ids=ids, vectors=vectors, payloads=payloads)
response = client.upsert(collection_name=collection_name, points=batch_vectors)
if __name__ == '__main__':
a, b = search()
put('WhaleChat', b, a)
```
这样修改后,应该能够正确构建并发送json格式的请求体数据。请确保`BatchVectorStruct`类的定义与服务器端的要求相匹配,以避免格式错误。
阅读全文