chatGPT本地知识库-私有数据知识库-列出qdrant集合中的所有points
演示网站:gofly.v1kf.com我的微信:llike620
想要列出某一个集合里的所有向量数据points,可以根据文档使用下面这个接口
POST /collections/{collection_name}/points/scroll
{
“filter”: {
“must”: [
{
“key”: “color”,
“match”: {
“value”: “red”
}
}
]
},
“limit”: 1,
“with_payload”: true,
“with_vector”: false
}
滚动API将以逐页的方式返回与过滤器匹配的所有点。
所有结果点都按ID排序。要查询下一页,需要在偏移字段中指定最大的已看到的ID。为了方便起见,该ID也在next_page_offset字段中返回。如果next_page_offset字段的值为null,则达到了最后一页。
{
“result”: {
“next_page_offset”: 1,
“points”: [
{
“id”: 0,
“payload”: {
“color”: “red”
}
}
]
},
“status”: “ok”,
“time”: 0.0001}注意,这个offset偏移字段,只允许无符号整型,或者uuid,其他形式会报错
//查询数据列表
func GetPoints(collectionName string, limit uint, offset interface{}) ([]byte, error) {
// 构造请求体
requestBody := map[string]interface{}{
“limit”: limit,
“offset”: offset,
“with_payload”: true,
“with_vector”: false,
}
requestBodyBytes, err := json.Marshal(requestBody)
if err != nil {
return nil, err
}
// 构造请求
url := fmt.Sprintf(“http://%s:%s/collections/%s/points/scroll”, QdrantBase, QdrantPort, collectionName)
request, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(requestBodyBytes))
if err != nil {
return nil, err
}
request.Header.Set(“Content-Type”, “application/json”)
// 发送请求
client := http.DefaultClient
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
// 处理响应
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
return responseBody, nil
}
测试用例:
func TestGetPoints(t *testing.T) {
collectionName := “data_collection”
limit := 1
offset := “16c802db-b52f-434a-b038-7777edd0b5c9”
points, err := GetPoints(collectionName, uint(limit), offset)
if err != nil {
t.Errorf(“Error searching points: %v”, err)
}
log.Println(string(points))
}