def total(host): print("host: %s" % host) channel = grpc.insecure_channel(host) stub = pb2_grpc.ServerStub(channel) response = stub.Total(pb2.EmptyRequest()) print("total: %d" % response.count)
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) id = 2 response = stub.Search(pb2.SearchRequest(id=id, count=5)) print("response: %s, %s" % (response.ids, response.scores)) embedding = list(np.random.random((dim)).astype('float32')) 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 = 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)
def import_(host, embs_path, ids_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)) print("response: %s" % response.message) response = stub.Total(pb2.EmptyRequest()) print("total: %d" % response.count)
def _search_by_key(host, key, count, timeout, channel): stub = pb2_grpc.ServerStub(channel) return stub.Search(pb2.SearchRequest(key=key, count=count))
def search(host, id, count, timeout): with grpc.insecure_channel(host) as channel: stub = pb2_grpc.ServerStub(channel) response = stub.Search(pb2.SearchRequest(id=id, count=count), timeout=timeout) print("response: %s, %s" % (response.ids, response.scores))