Ejemplo n.º 1
0
def test(host, port, dim):
    print("host: %s:%d" % (host, port))

    channel = grpc.insecure_channel("%s:%d" % (host, port))
    stub = pb2_grpc.ServerStub(channel)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)

    embedding = list(np.random.random(dim).astype('float32'))
    print(embedding)
    id = 1
    response = stub.Add(pb2.AddRequest(id=id, embedding=embedding))
    print("response: %s" % response.message)

    embedding = list(np.random.random(dim).astype('float32'))
    print(embedding)
    id = 1
    response = stub.Add(pb2.AddRequest(id=id, embedding=embedding))
    print("response: %s" % response.message)

    embedding = list(np.random.random(dim).astype('float32'))
    id = 2
    response = stub.Add(pb2.AddRequest(id=id, embedding=embedding))
    print("response: %s" % response.message)

    embedding = list(np.random.random(dim).astype('float32'))
    id = 3
    response = stub.Add(pb2.AddRequest(id=id, embedding=embedding))
    print("response: %s" % response.message)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)

    id = 2
    response = stub.Search(pb2.SearchRequest(id=id, count=5))
    print("response: %s, %s" % (response.ids, response.scores))

    response = stub.Remove(pb2.IdRequest(id=2))
    print("response: %s" % response.message)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)

    id = 2
    response = stub.Search(pb2.SearchRequest(id=id, count=5))
    print("response: %s, %s" % (response.ids, response.scores))

    # response = stub.Remove(pb2.IdRequest(id=1))
    # response = stub.Remove(pb2.IdRequest(id=3))

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)
Ejemplo n.º 2
0
def imports(host, embs_path, ids_path, keys_path):
    print("host: %s" % host)
    channel = grpc.insecure_channel(host)
    stub = pb2_grpc.ServerStub(channel)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)

    response = stub.Import(
        pb2.ImportRequest(embs_path=embs_path,
                          ids_path=ids_path,
                          keys_path=keys_path))
    print("response: %s" % response.message)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)
Ejemplo n.º 3
0
def test_key(host, port, dim):
    print("host: %s:%d" % (host, port))

    channel = grpc.insecure_channel("%s:%d" % (host, port))
    stub = pb2_grpc.ServerStub(channel)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)

    embedding = list(np.random.random(dim).astype('float32'))
    print(embedding)
    key = "k1"
    response = stub.Add(pb2.AddRequest(key=key, embedding=embedding))
    print("response: %s" % response.message)

    embedding = list(np.random.random(dim).astype('float32'))
    key = "k1"
    response = stub.Add(pb2.AddRequest(key=key, embedding=embedding))
    print("response: %s" % response.message)

    embedding = list(np.random.random(dim).astype('float32'))
    key = "k2"
    response = stub.Add(pb2.AddRequest(key=key, embedding=embedding))
    print("response: %s" % response.message)

    embedding = list(np.random.random(dim).astype('float32'))
    key = "k3"
    response = stub.Add(pb2.AddRequest(key=key, embedding=embedding))
    print("response: %s" % response.message)

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)

    key = "k1"
    response = stub.Search(pb2.SearchRequest(key=key, count=5))
    print("response: %s, %s" % (response.ids, response.scores))

    key = "k2"
    response = stub.Search(pb2.SearchRequest(key=key, count=5))
    print("response: %s, %s" % (response.ids, response.scores))

    response = stub.Total(pb2.EmptyRequest())
    print("total: %d" % response.count)