| 162 | } |
| 163 | |
| 164 | func queryVectorUsingUid(t *testing.T, uid, pred string) ([]float32, error) { |
| 165 | vectorQuery := fmt.Sprintf(` |
| 166 | { |
| 167 | vector(func: uid(%v)) { |
| 168 | %v |
| 169 | } |
| 170 | }`, uid, pred) |
| 171 | |
| 172 | resp, err := client.Query(vectorQuery) |
| 173 | require.NoError(t, err) |
| 174 | |
| 175 | type VectorData struct { |
| 176 | VTest []float32 `json:"vtest"` |
| 177 | } |
| 178 | |
| 179 | type Data struct { |
| 180 | Vector []VectorData `json:"vector"` |
| 181 | } |
| 182 | |
| 183 | var data Data |
| 184 | |
| 185 | err = json.Unmarshal([]byte(resp.Json), &data) |
| 186 | if err != nil { |
| 187 | return []float32{}, err |
| 188 | } |
| 189 | |
| 190 | return data.Vector[0].VTest, nil |
| 191 | |
| 192 | } |
| 193 | |
| 194 | func queryMultipleVectorsUsingSimilarTo(t *testing.T, vector []float32, pred string, topK int) ([][]float32, error) { |
| 195 | vectorQuery := fmt.Sprintf(` |