File size: 4,552 Bytes
3932407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
# This test checks that Qdrant answers to all API mentioned in README.md as expected

set -ex

QDRANT_HOST=${QDRANT_HOST:-'localhost:6333'}

qdrant_host_headers=()

if [ -n "${QDRANT_HOST_HEADERS}" ]; then
  while read h; do
    qdrant_host_headers+=("-H" "$h")
  done <<<  $(echo "${QDRANT_HOST_HEADERS}" | jq -r 'to_entries|map("\(.key): \(.value)")[]')
fi

# cleanup collection if it exists
curl -X DELETE "http://$QDRANT_HOST/collections/test_collection" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s | jq

# create collection
curl -X PUT "http://$QDRANT_HOST/collections/test_collection" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
      "vectors": {
        "size": 4,
        "distance": "Dot"
      },
      "optimizers_config": {
        "default_segment_number": 2
      },
      "replication_factor": 2
    }' | jq

curl -L -X PUT  "http://$QDRANT_HOST/collections/test_collection/index" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
      "field_name": "city",
      "field_schema": "keyword"
    }' | jq

curl -L -X PUT  "http://$QDRANT_HOST/collections/test_collection/index" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
      "field_name": "count",
      "field_schema": "integer"
    }' | jq

curl -L -X PUT  "http://$QDRANT_HOST/collections/test_collection/index" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
      "field_name": "coords",
      "field_schema": "geo"
    }' | jq

curl --fail -s "http://$QDRANT_HOST/collections/test_collection" "${qdrant_host_headers[@]-}" | jq

# insert points
curl -L -X PUT "http://$QDRANT_HOST/collections/test_collection/points?wait=true" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
      "points": [
        {
          "id": 1,
          "vector": [0.05, 0.61, 0.76, 0.74],
          "payload": {
            "city": "Berlin",
            "country": "Germany" ,
            "count": 1000000,
            "square": 12.5,
            "coords": { "lat": 1.0, "lon": 2.0 }
          }
        },
        {"id": 2, "vector": [0.19, 0.81, 0.75, 0.11], "payload": {"city": ["Berlin", "London"]}},
        {"id": 3, "vector": [0.36, 0.55, 0.47, 0.94], "payload": {"city": ["Berlin", "Moscow"]}},
        {"id": 4, "vector": [0.18, 0.01, 0.85, 0.80], "payload": {"city": ["London", "Moscow"]}},
        {"id": "98a9a4b1-4ef2-46fb-8315-a97d874fe1d7", "vector": [0.24, 0.18, 0.22, 0.44], "payload": {"count": [0]}},
        {"id": "f0e09527-b096-42a8-94e9-ea94d342b925", "vector": [0.35, 0.08, 0.11, 0.44]}
      ]
    }' | jq

# retrieve point
curl -L -X GET "http://$QDRANT_HOST/collections/test_collection/points/2" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s | jq

# retrieve points
curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
      "ids": [1, 2]
    }' | jq

SAVED_POINTS_COUNT=$(curl --fail -s "http://$QDRANT_HOST/collections/test_collection" "${qdrant_host_headers[@]}" | jq '.result.points_count')
[[ "$SAVED_POINTS_COUNT" == "6" ]] || {
  echo 'check failed - 6 points expected'
  exit 1
}

# search points
curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
        "vector": [0.2,0.1,0.9,0.7],
        "top": 3
    }' | jq

# search points batch
curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search/batch" \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --fail -s \
  --data-raw '{
    "searches": [
      {
        "vector": [0.2,0.1,0.9,0.7],
        "top": 3
      },
      {
        "vector": [0.2,0.1,0.9,0.7],
        "top": 3
      }
    ]
  }' | jq

curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search" \
  --fail -s \
  -H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
  --data-raw '{
      "filter": {
          "should": [
              {
                  "key": "city",
                  "match": {
                      "value": "London"
                  }
              }
          ]
      },
      "vector": [0.2, 0.1, 0.9, 0.7],
      "top": 3
  }' | jq