test_function.py 1.3 KB
Newer Older
X
xj.lin 已提交
1 2
import numpy as np
import requests
X
xj.lin 已提交
3
import pytest
X
xj.lin 已提交
4 5 6 7 8 9 10
import logging
import json

url = "http://127.0.0.1:5000"


# TODO: LOG and Assert
X
xj.lin 已提交
11
class TestEngineFunction():
X
xj.lin 已提交
12 13
    def test_1m_add(self):
        d = 4
X
xj.lin 已提交
14
        nb = 100
X
xj.lin 已提交
15 16 17 18
        nq = 1
        k = 10
        _, xb, xq = get_dataset(d, nb, 1, nq)

X
xj.lin 已提交
19
        groupid = "test_search_3"
X
xj.lin 已提交
20

X
xj.lin 已提交
21 22 23 24 25 26 27 28 29 30 31
        route_group = url + "/vector/group/" + groupid
        r = requests.post(route_group, json={"dimension": d})

        # import dataset
        vector_add_route = url + "/vector/add/" + groupid
        for i in xb:
            data = dict()
            data['vector'] = i.tolist()
            # print(data)
            r = requests.post(vector_add_route, json=data)
            print(r.json())
X
xj.lin 已提交
32 33 34 35

        # search dataset
        vector_search_route = url + "/vector/search/" + groupid
        data = dict()
X
xj.lin 已提交
36 37 38 39 40 41
        for i in xq:
            data['vector'] = i.tolist()
            data['limit'] = k
            # print(data)
            r = requests.get(vector_search_route, json=data)
            print(r.json())
X
xj.lin 已提交
42 43 44 45 46 47 48 49 50 51 52 53


def get_dataset(d, nb, nt, nq):
    d1 = 10  # intrinsic dimension (more or less)
    n = nb + nt + nq
    rs = np.random.RandomState(1338)
    x = rs.normal(size=(n, d1))
    x = np.dot(x, rs.rand(d1, d))
    x = x * (rs.rand(d) * 4 + 0.1)
    x = np.sin(x)
    x = x.astype('float32')
    return x[:nt], x[nt:-nq], x[-nq:]