File size: 5,832 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env bash
# This test checks that Qdrant answers to all API mentioned in README.md as expected

set -ex

# Ensure current path is project root
cd "$(dirname "$0")/../"

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

docker_grpcurl=("docker" "run" "--rm" "--network=host" "-v" "${PWD}/lib/api/src/grpc/proto:/proto" "fullstorydev/grpcurl" "-plaintext" "-import-path" "/proto" "-proto" "qdrant.proto")

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

"${docker_grpcurl[@]}" -d '{
   "collection_name": "test_sparse_collection"
}' $QDRANT_HOST qdrant.Collections/Delete

"${docker_grpcurl[@]}" -d '{
   "collection_name": "test_sparse_collection",
   "sparse_vectors_config": {
      "map": {
        "test": { }
      }
   }
}' $QDRANT_HOST qdrant.Collections/Create

"${docker_grpcurl[@]}" -d '{}' $QDRANT_HOST qdrant.Collections/List

"${docker_grpcurl[@]}" -d '{
  "collection_name": "test_sparse_collection",
  "wait": true,
  "ordering": null,
  "points": [
    {
      "id": { "num": 1 },
      "vectors": {
        "vectors": {
          "vectors": {
            "test": { "data": [0.05, 0.61, 0.76, 0.74], "indices": { "data": [0,1,2,3] }}
          }
        }
      },
      "payload": {
        "city": { "string_value": "Berlin" },
        "country":  { "string_value": "Germany" },
        "population": { "integer_value":  1000000 },
        "square": { "double_value": 12.5 },
        "coords": { "struct_value": { "fields": { "lat": { "double_value": 1.0 }, "lon": { "double_value": 2.0 } } } }
      }
    },
    {
      "id": { "num": 2 },
      "vectors": {
        "vectors": {
          "vectors": {
            "test": { "data": [0.19, 0.81, 0.75, 0.11], "indices": { "data": [0,1,2,3] }}
          }
        }
      },
      "payload": {"city": {"list_value": {"values": [{ "string_value": "Berlin" }, { "string_value": "London" }]}}}
    },
    {
      "id": { "num": 3 },
      "vectors": {
        "vectors": {
          "vectors": {
            "test": { "data": [0.36, 0.55, 0.47, 0.94], "indices": { "data": [0,1,2,3] }}
          }
        }
      },
      "payload": {"city": {"list_value": {"values": [{ "string_value": "Berlin" }, { "string_value": "Moscow" }]}}}
    },
    {
      "id": { "num": 4 },
      "vectors": {
        "vectors": {
          "vectors": {
            "test": {"data": [0.18, 0.01, 0.85, 0.80], "indices": { "data": [0,1,2,3] }}
          }
        }
      },
      "payload": {"city": {"list_value": {"values": [{ "string_value": "London" }, { "string_value": "Moscow" }]}}}
    },
    {
      "id": { "uuid": "98a9a4b1-4ef2-46fb-8315-a97d874fe1d7" },
      "vectors": {
        "vectors": {
          "vectors": {
            "test": {"data": [0.24, 0.18, 0.22, 0.44], "indices": { "data": [0,1,2,3] }}
          }
        }
      },
      "payload": {"count":{"list_value": {"values": [{ "integer_value": 0 }]}}}
    },
    {
      "id": { "uuid": "f0e09527-b096-42a8-94e9-ea94d342b925" },
      "vectors": {
        "vectors": {
          "vectors": {
            "test": {"data": [0.35, 0.08, 0.11, 0.44], "indices": { "data": [0,1,2,3] }}
          }
        }
      }
    }
  ]
}' $QDRANT_HOST qdrant.Points/Upsert

"${docker_grpcurl[@]}" -d '{ "collection_name": "test_sparse_collection" }' $QDRANT_HOST qdrant.Collections/Get

"${docker_grpcurl[@]}" -d '{
  "collection_name": "test_sparse_collection",
  "vector": [0.2,0.1,0.9,0.7],
  "sparse_indices": { "data": [0,1,2,3] },
  "vector_name": "test",
  "limit": 3
}' $QDRANT_HOST qdrant.Points/Search

"${docker_grpcurl[@]}" -d '{
  "collection_name": "test_sparse_collection",
  "filter": {
    "should": [
      {
        "field": {
          "key": "city",
          "match": {
            "keyword": "London"
          }
        }
      }
    ]
  },
  "vector": [0.2,0.1,0.9,0.7],
  "sparse_indices": { "data": [0,1,2,3] },
  "vector_name": "test",
  "limit": 3
}' $QDRANT_HOST qdrant.Points/Search

"${docker_grpcurl[@]}" -d '{
  "collection_name": "test_sparse_collection",
  "limit": 2,
  "with_vectors": {"enable": true},
  "filter": {
    "should": [
      {
        "field": {
          "key": "city",
          "match": {
            "keyword": "London"
          }
        }
      }
    ]
  }
}' $QDRANT_HOST qdrant.Points/Scroll

"${docker_grpcurl[@]}" -d '{
  "collection_name": "test_sparse_collection",
  "with_vectors": {"enable": true},
  "ids": [{ "num": 2 }, { "num": 3 }, { "num": 4 }]
}' $QDRANT_HOST qdrant.Points/Get

# validate search request when vector and indices have different sizes
set +e
response=$(
  "${docker_grpcurl[@]}" -d '{
    "collection_name": "test_sparse_collection",
    "vector": [0.2,0.1],
    "sparse_indices": { "data": [0,1,2,3] },
    "vector_name": "test",
    "limit": 3
  }' $QDRANT_HOST qdrant.Points/Search 2>&1
)
if [[ $response != *"Sparse indices does not match sparse vector conditions"* ]]; then
    echo Unexpected response, expected validation error: $response
    exit 1
fi

response=$(
  "${docker_grpcurl[@]}" -d '{
    "collection_name": "test_sparse_collection",
    "wait": true,
    "ordering": null,
    "points": [
      {
        "id": { "uuid": "f0e09527-b096-42a8-94e9-ea94d342b885" },
        "vectors": {
          "vectors": {
            "vectors": {
              "test": {"data": [0.35, 0.08], "indices": { "data": [0,1,2,3] }}
            }
          }
        }
      }
    ]
  }' $QDRANT_HOST qdrant.Points/Upsert 2>&1
)
if [[ $response != *"Validation error in body: [points[0].vectors.vectors_options.vectors.[].values: Validation error: must be the same length as indices [{}]]"* ]]; then
    echo Unexpected response, expected validation error: $response
    exit 1
fi
set -e