modify server api

Former-commit-id: 3eff45989dd09bf7b7aae8b2a004f83898708dd6
pull/191/head
groot 2019-04-22 13:56:38 +08:00
parent 41220cb25d
commit e7075c185d
10 changed files with 192 additions and 388 deletions

View File

@ -82,7 +82,7 @@ VecServiceHandler::del_group(const std::string &group_id) {
void
VecServiceHandler::add_vector(VecTensorIdList& _return, const std::string &group_id, const VecTensor &tensor) {
VecServiceHandler::add_vector(const std::string &group_id, const VecTensor &tensor) {
SERVER_LOG_INFO << "add_vector() called";
SERVER_LOG_TRACE << "group_id = " << group_id << ", vector size = " << tensor.tensor.size();
@ -93,7 +93,6 @@ VecServiceHandler::add_vector(VecTensorIdList& _return, const std::string &group
if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
} else {
_return.id_list.swap(vector_ids);
}
SERVER_LOG_INFO << "add_vector() finished";
@ -103,8 +102,7 @@ VecServiceHandler::add_vector(VecTensorIdList& _return, const std::string &group
}
void
VecServiceHandler::add_vector_batch(VecTensorIdList &_return,
const std::string &group_id,
VecServiceHandler::add_vector_batch(const std::string &group_id,
const VecTensorList &tensor_list) {
SERVER_LOG_INFO << "add_vector_batch() called";
SERVER_LOG_TRACE << "group_id = " << group_id << ", vector list size = "
@ -121,7 +119,6 @@ VecServiceHandler::add_vector_batch(VecTensorIdList &_return,
if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
} else {
_return.id_list.swap(vector_ids);
}
SERVER_LOG_INFO << "add_vector_batch() finished";
@ -149,8 +146,10 @@ VecServiceHandler::search_vector(VecSearchResult &_return,
if(!stat.ok()) {
SERVER_LOG_ERROR << "Engine failed: " << stat.ToString();
} else {
if(results.size() > 0) {
_return.id_list.swap(results[0]);
if(!results.empty()) {
for(auto id : results[0]) {
_return.id_list.push_back(std::to_string(id));
}
}
}
@ -184,7 +183,9 @@ VecServiceHandler::search_vector_batch(VecSearchResultList &_return,
} else {
for(engine::QueryResult& res : results){
VecSearchResult v_res;
v_res.id_list.swap(res);
for(auto id : results[0]) {
v_res.id_list.push_back(std::to_string(id));
}
_return.result_list.push_back(v_res);
}
}

View File

@ -49,9 +49,9 @@ public:
* @param group_id
* @param tensor
*/
void add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor);
void add_vector(const std::string& group_id, const VecTensor& tensor);
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list);
void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list);
/**
* search interfaces

View File

@ -25,6 +25,7 @@ struct VecGroup {
}
struct VecTensor {
1: string uid;
2: list<double> tensor;
}
@ -32,12 +33,8 @@ struct VecTensorList {
1: list<VecTensor> tensor_list;
}
struct VecTensorIdList {
1: list<i64> id_list;
}
struct VecSearchResult {
1: list<i64> id_list;
1: list<string> id_list;
}
struct VecSearchResultList {
@ -78,8 +75,8 @@ service VecService {
* vector interfaces
*
*/
VecTensorIdList add_vector(2: string group_id, 3: VecTensor tensor) throws(1: VecException e);
VecTensorIdList add_vector_batch(2: string group_id, 3: VecTensorList tensor_list) throws(1: VecException e);
void add_vector(2: string group_id, 3: VecTensor tensor) throws(1: VecException e);
void add_vector_batch(2: string group_id, 3: VecTensorList tensor_list) throws(1: VecException e);
/**
* search interfaces

View File

@ -710,14 +710,6 @@ uint32_t VecService_add_vector_result::read(::apache::thrift::protocol::TProtoco
}
switch (fid)
{
case 0:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += this->success.read(iprot);
this->__isset.success = true;
} else {
xfer += iprot->skip(ftype);
}
break;
case 1:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += this->e.read(iprot);
@ -744,11 +736,7 @@ uint32_t VecService_add_vector_result::write(::apache::thrift::protocol::TProtoc
xfer += oprot->writeStructBegin("VecService_add_vector_result");
if (this->__isset.success) {
xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_STRUCT, 0);
xfer += this->success.write(oprot);
xfer += oprot->writeFieldEnd();
} else if (this->__isset.e) {
if (this->__isset.e) {
xfer += oprot->writeFieldBegin("e", ::apache::thrift::protocol::T_STRUCT, 1);
xfer += this->e.write(oprot);
xfer += oprot->writeFieldEnd();
@ -784,14 +772,6 @@ uint32_t VecService_add_vector_presult::read(::apache::thrift::protocol::TProtoc
}
switch (fid)
{
case 0:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += (*(this->success)).read(iprot);
this->__isset.success = true;
} else {
xfer += iprot->skip(ftype);
}
break;
case 1:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += this->e.read(iprot);
@ -933,14 +913,6 @@ uint32_t VecService_add_vector_batch_result::read(::apache::thrift::protocol::TP
}
switch (fid)
{
case 0:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += this->success.read(iprot);
this->__isset.success = true;
} else {
xfer += iprot->skip(ftype);
}
break;
case 1:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += this->e.read(iprot);
@ -967,11 +939,7 @@ uint32_t VecService_add_vector_batch_result::write(::apache::thrift::protocol::T
xfer += oprot->writeStructBegin("VecService_add_vector_batch_result");
if (this->__isset.success) {
xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_STRUCT, 0);
xfer += this->success.write(oprot);
xfer += oprot->writeFieldEnd();
} else if (this->__isset.e) {
if (this->__isset.e) {
xfer += oprot->writeFieldBegin("e", ::apache::thrift::protocol::T_STRUCT, 1);
xfer += this->e.write(oprot);
xfer += oprot->writeFieldEnd();
@ -1007,14 +975,6 @@ uint32_t VecService_add_vector_batch_presult::read(::apache::thrift::protocol::T
}
switch (fid)
{
case 0:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += (*(this->success)).read(iprot);
this->__isset.success = true;
} else {
xfer += iprot->skip(ftype);
}
break;
case 1:
if (ftype == ::apache::thrift::protocol::T_STRUCT) {
xfer += this->e.read(iprot);
@ -1718,10 +1678,10 @@ void VecServiceClient::recv_del_group()
return;
}
void VecServiceClient::add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor)
void VecServiceClient::add_vector(const std::string& group_id, const VecTensor& tensor)
{
send_add_vector(group_id, tensor);
recv_add_vector(_return);
recv_add_vector();
}
void VecServiceClient::send_add_vector(const std::string& group_id, const VecTensor& tensor)
@ -1739,7 +1699,7 @@ void VecServiceClient::send_add_vector(const std::string& group_id, const VecTen
oprot_->getTransport()->flush();
}
void VecServiceClient::recv_add_vector(VecTensorIdList& _return)
void VecServiceClient::recv_add_vector()
{
int32_t rseqid = 0;
@ -1765,25 +1725,20 @@ void VecServiceClient::recv_add_vector(VecTensorIdList& _return)
iprot_->getTransport()->readEnd();
}
VecService_add_vector_presult result;
result.success = &_return;
result.read(iprot_);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
if (result.__isset.success) {
// _return pointer has now been filled
return;
}
if (result.__isset.e) {
throw result.e;
}
throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector failed: unknown result");
return;
}
void VecServiceClient::add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list)
void VecServiceClient::add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list)
{
send_add_vector_batch(group_id, tensor_list);
recv_add_vector_batch(_return);
recv_add_vector_batch();
}
void VecServiceClient::send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list)
@ -1801,7 +1756,7 @@ void VecServiceClient::send_add_vector_batch(const std::string& group_id, const
oprot_->getTransport()->flush();
}
void VecServiceClient::recv_add_vector_batch(VecTensorIdList& _return)
void VecServiceClient::recv_add_vector_batch()
{
int32_t rseqid = 0;
@ -1827,19 +1782,14 @@ void VecServiceClient::recv_add_vector_batch(VecTensorIdList& _return)
iprot_->getTransport()->readEnd();
}
VecService_add_vector_batch_presult result;
result.success = &_return;
result.read(iprot_);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
if (result.__isset.success) {
// _return pointer has now been filled
return;
}
if (result.__isset.e) {
throw result.e;
}
throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector_batch failed: unknown result");
return;
}
void VecServiceClient::search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list)
@ -2181,8 +2131,7 @@ void VecServiceProcessor::process_add_vector(int32_t seqid, ::apache::thrift::pr
VecService_add_vector_result result;
try {
iface_->add_vector(result.success, args.group_id, args.tensor);
result.__isset.success = true;
iface_->add_vector(args.group_id, args.tensor);
} catch (VecException &e) {
result.e = e;
result.__isset.e = true;
@ -2238,8 +2187,7 @@ void VecServiceProcessor::process_add_vector_batch(int32_t seqid, ::apache::thri
VecService_add_vector_batch_result result;
try {
iface_->add_vector_batch(result.success, args.group_id, args.tensor_list);
result.__isset.success = true;
iface_->add_vector_batch(args.group_id, args.tensor_list);
} catch (VecException &e) {
result.e = e;
result.__isset.e = true;
@ -2645,10 +2593,10 @@ void VecServiceConcurrentClient::recv_del_group(const int32_t seqid)
} // end while(true)
}
void VecServiceConcurrentClient::add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor)
void VecServiceConcurrentClient::add_vector(const std::string& group_id, const VecTensor& tensor)
{
int32_t seqid = send_add_vector(group_id, tensor);
recv_add_vector(_return, seqid);
recv_add_vector(seqid);
}
int32_t VecServiceConcurrentClient::send_add_vector(const std::string& group_id, const VecTensor& tensor)
@ -2670,7 +2618,7 @@ int32_t VecServiceConcurrentClient::send_add_vector(const std::string& group_id,
return cseqid;
}
void VecServiceConcurrentClient::recv_add_vector(VecTensorIdList& _return, const int32_t seqid)
void VecServiceConcurrentClient::recv_add_vector(const int32_t seqid)
{
int32_t rseqid = 0;
@ -2709,22 +2657,16 @@ void VecServiceConcurrentClient::recv_add_vector(VecTensorIdList& _return, const
throw TProtocolException(TProtocolException::INVALID_DATA);
}
VecService_add_vector_presult result;
result.success = &_return;
result.read(iprot_);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
if (result.__isset.success) {
// _return pointer has now been filled
sentry.commit();
return;
}
if (result.__isset.e) {
sentry.commit();
throw result.e;
}
// in a bad state, don't commit
throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector failed: unknown result");
sentry.commit();
return;
}
// seqid != rseqid
this->sync_.updatePending(fname, mtype, rseqid);
@ -2734,10 +2676,10 @@ void VecServiceConcurrentClient::recv_add_vector(VecTensorIdList& _return, const
} // end while(true)
}
void VecServiceConcurrentClient::add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list)
void VecServiceConcurrentClient::add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list)
{
int32_t seqid = send_add_vector_batch(group_id, tensor_list);
recv_add_vector_batch(_return, seqid);
recv_add_vector_batch(seqid);
}
int32_t VecServiceConcurrentClient::send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list)
@ -2759,7 +2701,7 @@ int32_t VecServiceConcurrentClient::send_add_vector_batch(const std::string& gro
return cseqid;
}
void VecServiceConcurrentClient::recv_add_vector_batch(VecTensorIdList& _return, const int32_t seqid)
void VecServiceConcurrentClient::recv_add_vector_batch(const int32_t seqid)
{
int32_t rseqid = 0;
@ -2798,22 +2740,16 @@ void VecServiceConcurrentClient::recv_add_vector_batch(VecTensorIdList& _return,
throw TProtocolException(TProtocolException::INVALID_DATA);
}
VecService_add_vector_batch_presult result;
result.success = &_return;
result.read(iprot_);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
if (result.__isset.success) {
// _return pointer has now been filled
sentry.commit();
return;
}
if (result.__isset.e) {
sentry.commit();
throw result.e;
}
// in a bad state, don't commit
throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "add_vector_batch failed: unknown result");
sentry.commit();
return;
}
// seqid != rseqid
this->sync_.updatePending(fname, mtype, rseqid);

View File

@ -38,8 +38,8 @@ class VecServiceIf {
* @param group_id
* @param tensor
*/
virtual void add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor) = 0;
virtual void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list) = 0;
virtual void add_vector(const std::string& group_id, const VecTensor& tensor) = 0;
virtual void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) = 0;
/**
* search interfaces
@ -90,10 +90,10 @@ class VecServiceNull : virtual public VecServiceIf {
void del_group(const std::string& /* group_id */) {
return;
}
void add_vector(VecTensorIdList& /* _return */, const std::string& /* group_id */, const VecTensor& /* tensor */) {
void add_vector(const std::string& /* group_id */, const VecTensor& /* tensor */) {
return;
}
void add_vector_batch(VecTensorIdList& /* _return */, const std::string& /* group_id */, const VecTensorList& /* tensor_list */) {
void add_vector_batch(const std::string& /* group_id */, const VecTensorList& /* tensor_list */) {
return;
}
void search_vector(VecSearchResult& /* _return */, const std::string& /* group_id */, const int64_t /* top_k */, const VecTensor& /* tensor */, const VecTimeRangeList& /* time_range_list */) {
@ -481,8 +481,7 @@ class VecService_add_vector_pargs {
};
typedef struct _VecService_add_vector_result__isset {
_VecService_add_vector_result__isset() : success(false), e(false) {}
bool success :1;
_VecService_add_vector_result__isset() : e(false) {}
bool e :1;
} _VecService_add_vector_result__isset;
@ -495,19 +494,14 @@ class VecService_add_vector_result {
}
virtual ~VecService_add_vector_result() throw();
VecTensorIdList success;
VecException e;
_VecService_add_vector_result__isset __isset;
void __set_success(const VecTensorIdList& val);
void __set_e(const VecException& val);
bool operator == (const VecService_add_vector_result & rhs) const
{
if (!(success == rhs.success))
return false;
if (!(e == rhs.e))
return false;
return true;
@ -524,8 +518,7 @@ class VecService_add_vector_result {
};
typedef struct _VecService_add_vector_presult__isset {
_VecService_add_vector_presult__isset() : success(false), e(false) {}
bool success :1;
_VecService_add_vector_presult__isset() : e(false) {}
bool e :1;
} _VecService_add_vector_presult__isset;
@ -534,7 +527,6 @@ class VecService_add_vector_presult {
virtual ~VecService_add_vector_presult() throw();
VecTensorIdList* success;
VecException e;
_VecService_add_vector_presult__isset __isset;
@ -600,8 +592,7 @@ class VecService_add_vector_batch_pargs {
};
typedef struct _VecService_add_vector_batch_result__isset {
_VecService_add_vector_batch_result__isset() : success(false), e(false) {}
bool success :1;
_VecService_add_vector_batch_result__isset() : e(false) {}
bool e :1;
} _VecService_add_vector_batch_result__isset;
@ -614,19 +605,14 @@ class VecService_add_vector_batch_result {
}
virtual ~VecService_add_vector_batch_result() throw();
VecTensorIdList success;
VecException e;
_VecService_add_vector_batch_result__isset __isset;
void __set_success(const VecTensorIdList& val);
void __set_e(const VecException& val);
bool operator == (const VecService_add_vector_batch_result & rhs) const
{
if (!(success == rhs.success))
return false;
if (!(e == rhs.e))
return false;
return true;
@ -643,8 +629,7 @@ class VecService_add_vector_batch_result {
};
typedef struct _VecService_add_vector_batch_presult__isset {
_VecService_add_vector_batch_presult__isset() : success(false), e(false) {}
bool success :1;
_VecService_add_vector_batch_presult__isset() : e(false) {}
bool e :1;
} _VecService_add_vector_batch_presult__isset;
@ -653,7 +638,6 @@ class VecService_add_vector_batch_presult {
virtual ~VecService_add_vector_batch_presult() throw();
VecTensorIdList* success;
VecException e;
_VecService_add_vector_batch_presult__isset __isset;
@ -962,12 +946,12 @@ class VecServiceClient : virtual public VecServiceIf {
void del_group(const std::string& group_id);
void send_del_group(const std::string& group_id);
void recv_del_group();
void add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor);
void add_vector(const std::string& group_id, const VecTensor& tensor);
void send_add_vector(const std::string& group_id, const VecTensor& tensor);
void recv_add_vector(VecTensorIdList& _return);
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list);
void recv_add_vector();
void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list);
void send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list);
void recv_add_vector_batch(VecTensorIdList& _return);
void recv_add_vector_batch();
void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list);
void send_search_vector(const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list);
void recv_search_vector(VecSearchResult& _return);
@ -1062,24 +1046,22 @@ class VecServiceMultiface : virtual public VecServiceIf {
ifaces_[i]->del_group(group_id);
}
void add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor) {
void add_vector(const std::string& group_id, const VecTensor& tensor) {
size_t sz = ifaces_.size();
size_t i = 0;
for (; i < (sz - 1); ++i) {
ifaces_[i]->add_vector(_return, group_id, tensor);
ifaces_[i]->add_vector(group_id, tensor);
}
ifaces_[i]->add_vector(_return, group_id, tensor);
return;
ifaces_[i]->add_vector(group_id, tensor);
}
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list) {
void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) {
size_t sz = ifaces_.size();
size_t i = 0;
for (; i < (sz - 1); ++i) {
ifaces_[i]->add_vector_batch(_return, group_id, tensor_list);
ifaces_[i]->add_vector_batch(group_id, tensor_list);
}
ifaces_[i]->add_vector_batch(_return, group_id, tensor_list);
return;
ifaces_[i]->add_vector_batch(group_id, tensor_list);
}
void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list) {
@ -1141,12 +1123,12 @@ class VecServiceConcurrentClient : virtual public VecServiceIf {
void del_group(const std::string& group_id);
int32_t send_del_group(const std::string& group_id);
void recv_del_group(const int32_t seqid);
void add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor);
void add_vector(const std::string& group_id, const VecTensor& tensor);
int32_t send_add_vector(const std::string& group_id, const VecTensor& tensor);
void recv_add_vector(VecTensorIdList& _return, const int32_t seqid);
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list);
void recv_add_vector(const int32_t seqid);
void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list);
int32_t send_add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list);
void recv_add_vector_batch(VecTensorIdList& _return, const int32_t seqid);
void recv_add_vector_batch(const int32_t seqid);
void search_vector(VecSearchResult& _return, const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list);
int32_t send_search_vector(const std::string& group_id, const int64_t top_k, const VecTensor& tensor, const VecTimeRangeList& time_range_list);
void recv_search_vector(VecSearchResult& _return, const int32_t seqid);

View File

@ -45,12 +45,12 @@ class VecServiceHandler : virtual public VecServiceIf {
* @param group_id
* @param tensor
*/
void add_vector(VecTensorIdList& _return, const std::string& group_id, const VecTensor& tensor) {
void add_vector(const std::string& group_id, const VecTensor& tensor) {
// Your implementation goes here
printf("add_vector\n");
}
void add_vector_batch(VecTensorIdList& _return, const std::string& group_id, const VecTensorList& tensor_list) {
void add_vector_batch(const std::string& group_id, const VecTensorList& tensor_list) {
// Your implementation goes here
printf("add_vector_batch\n");
}

View File

@ -303,6 +303,10 @@ VecTensor::~VecTensor() throw() {
}
void VecTensor::__set_uid(const std::string& val) {
this->uid = val;
}
void VecTensor::__set_tensor(const std::vector<double> & val) {
this->tensor = val;
}
@ -334,6 +338,14 @@ uint32_t VecTensor::read(::apache::thrift::protocol::TProtocol* iprot) {
}
switch (fid)
{
case 1:
if (ftype == ::apache::thrift::protocol::T_STRING) {
xfer += iprot->readString(this->uid);
this->__isset.uid = true;
} else {
xfer += iprot->skip(ftype);
}
break;
case 2:
if (ftype == ::apache::thrift::protocol::T_LIST) {
{
@ -371,6 +383,10 @@ uint32_t VecTensor::write(::apache::thrift::protocol::TProtocol* oprot) const {
::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
xfer += oprot->writeStructBegin("VecTensor");
xfer += oprot->writeFieldBegin("uid", ::apache::thrift::protocol::T_STRING, 1);
xfer += oprot->writeString(this->uid);
xfer += oprot->writeFieldEnd();
xfer += oprot->writeFieldBegin("tensor", ::apache::thrift::protocol::T_LIST, 2);
{
xfer += oprot->writeListBegin(::apache::thrift::protocol::T_DOUBLE, static_cast<uint32_t>(this->tensor.size()));
@ -390,15 +406,18 @@ uint32_t VecTensor::write(::apache::thrift::protocol::TProtocol* oprot) const {
void swap(VecTensor &a, VecTensor &b) {
using ::std::swap;
swap(a.uid, b.uid);
swap(a.tensor, b.tensor);
swap(a.__isset, b.__isset);
}
VecTensor::VecTensor(const VecTensor& other11) {
uid = other11.uid;
tensor = other11.tensor;
__isset = other11.__isset;
}
VecTensor& VecTensor::operator=(const VecTensor& other12) {
uid = other12.uid;
tensor = other12.tensor;
__isset = other12.__isset;
return *this;
@ -406,7 +425,8 @@ VecTensor& VecTensor::operator=(const VecTensor& other12) {
void VecTensor::printTo(std::ostream& out) const {
using ::apache::thrift::to_string;
out << "VecTensor(";
out << "tensor=" << to_string(tensor);
out << "uid=" << to_string(uid);
out << ", " << "tensor=" << to_string(tensor);
out << ")";
}
@ -523,123 +543,11 @@ void VecTensorList::printTo(std::ostream& out) const {
}
VecTensorIdList::~VecTensorIdList() throw() {
}
void VecTensorIdList::__set_id_list(const std::vector<int64_t> & val) {
this->id_list = val;
}
std::ostream& operator<<(std::ostream& out, const VecTensorIdList& obj)
{
obj.printTo(out);
return out;
}
uint32_t VecTensorIdList::read(::apache::thrift::protocol::TProtocol* iprot) {
::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot);
uint32_t xfer = 0;
std::string fname;
::apache::thrift::protocol::TType ftype;
int16_t fid;
xfer += iprot->readStructBegin(fname);
using ::apache::thrift::protocol::TProtocolException;
while (true)
{
xfer += iprot->readFieldBegin(fname, ftype, fid);
if (ftype == ::apache::thrift::protocol::T_STOP) {
break;
}
switch (fid)
{
case 1:
if (ftype == ::apache::thrift::protocol::T_LIST) {
{
this->id_list.clear();
uint32_t _size21;
::apache::thrift::protocol::TType _etype24;
xfer += iprot->readListBegin(_etype24, _size21);
this->id_list.resize(_size21);
uint32_t _i25;
for (_i25 = 0; _i25 < _size21; ++_i25)
{
xfer += iprot->readI64(this->id_list[_i25]);
}
xfer += iprot->readListEnd();
}
this->__isset.id_list = true;
} else {
xfer += iprot->skip(ftype);
}
break;
default:
xfer += iprot->skip(ftype);
break;
}
xfer += iprot->readFieldEnd();
}
xfer += iprot->readStructEnd();
return xfer;
}
uint32_t VecTensorIdList::write(::apache::thrift::protocol::TProtocol* oprot) const {
uint32_t xfer = 0;
::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot);
xfer += oprot->writeStructBegin("VecTensorIdList");
xfer += oprot->writeFieldBegin("id_list", ::apache::thrift::protocol::T_LIST, 1);
{
xfer += oprot->writeListBegin(::apache::thrift::protocol::T_I64, static_cast<uint32_t>(this->id_list.size()));
std::vector<int64_t> ::const_iterator _iter26;
for (_iter26 = this->id_list.begin(); _iter26 != this->id_list.end(); ++_iter26)
{
xfer += oprot->writeI64((*_iter26));
}
xfer += oprot->writeListEnd();
}
xfer += oprot->writeFieldEnd();
xfer += oprot->writeFieldStop();
xfer += oprot->writeStructEnd();
return xfer;
}
void swap(VecTensorIdList &a, VecTensorIdList &b) {
using ::std::swap;
swap(a.id_list, b.id_list);
swap(a.__isset, b.__isset);
}
VecTensorIdList::VecTensorIdList(const VecTensorIdList& other27) {
id_list = other27.id_list;
__isset = other27.__isset;
}
VecTensorIdList& VecTensorIdList::operator=(const VecTensorIdList& other28) {
id_list = other28.id_list;
__isset = other28.__isset;
return *this;
}
void VecTensorIdList::printTo(std::ostream& out) const {
using ::apache::thrift::to_string;
out << "VecTensorIdList(";
out << "id_list=" << to_string(id_list);
out << ")";
}
VecSearchResult::~VecSearchResult() throw() {
}
void VecSearchResult::__set_id_list(const std::vector<int64_t> & val) {
void VecSearchResult::__set_id_list(const std::vector<std::string> & val) {
this->id_list = val;
}
std::ostream& operator<<(std::ostream& out, const VecSearchResult& obj)
@ -674,14 +582,14 @@ uint32_t VecSearchResult::read(::apache::thrift::protocol::TProtocol* iprot) {
if (ftype == ::apache::thrift::protocol::T_LIST) {
{
this->id_list.clear();
uint32_t _size29;
::apache::thrift::protocol::TType _etype32;
xfer += iprot->readListBegin(_etype32, _size29);
this->id_list.resize(_size29);
uint32_t _i33;
for (_i33 = 0; _i33 < _size29; ++_i33)
uint32_t _size21;
::apache::thrift::protocol::TType _etype24;
xfer += iprot->readListBegin(_etype24, _size21);
this->id_list.resize(_size21);
uint32_t _i25;
for (_i25 = 0; _i25 < _size21; ++_i25)
{
xfer += iprot->readI64(this->id_list[_i33]);
xfer += iprot->readString(this->id_list[_i25]);
}
xfer += iprot->readListEnd();
}
@ -709,11 +617,11 @@ uint32_t VecSearchResult::write(::apache::thrift::protocol::TProtocol* oprot) co
xfer += oprot->writeFieldBegin("id_list", ::apache::thrift::protocol::T_LIST, 1);
{
xfer += oprot->writeListBegin(::apache::thrift::protocol::T_I64, static_cast<uint32_t>(this->id_list.size()));
std::vector<int64_t> ::const_iterator _iter34;
for (_iter34 = this->id_list.begin(); _iter34 != this->id_list.end(); ++_iter34)
xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRING, static_cast<uint32_t>(this->id_list.size()));
std::vector<std::string> ::const_iterator _iter26;
for (_iter26 = this->id_list.begin(); _iter26 != this->id_list.end(); ++_iter26)
{
xfer += oprot->writeI64((*_iter34));
xfer += oprot->writeString((*_iter26));
}
xfer += oprot->writeListEnd();
}
@ -730,13 +638,13 @@ void swap(VecSearchResult &a, VecSearchResult &b) {
swap(a.__isset, b.__isset);
}
VecSearchResult::VecSearchResult(const VecSearchResult& other35) {
id_list = other35.id_list;
__isset = other35.__isset;
VecSearchResult::VecSearchResult(const VecSearchResult& other27) {
id_list = other27.id_list;
__isset = other27.__isset;
}
VecSearchResult& VecSearchResult::operator=(const VecSearchResult& other36) {
id_list = other36.id_list;
__isset = other36.__isset;
VecSearchResult& VecSearchResult::operator=(const VecSearchResult& other28) {
id_list = other28.id_list;
__isset = other28.__isset;
return *this;
}
void VecSearchResult::printTo(std::ostream& out) const {
@ -786,14 +694,14 @@ uint32_t VecSearchResultList::read(::apache::thrift::protocol::TProtocol* iprot)
if (ftype == ::apache::thrift::protocol::T_LIST) {
{
this->result_list.clear();
uint32_t _size37;
::apache::thrift::protocol::TType _etype40;
xfer += iprot->readListBegin(_etype40, _size37);
this->result_list.resize(_size37);
uint32_t _i41;
for (_i41 = 0; _i41 < _size37; ++_i41)
uint32_t _size29;
::apache::thrift::protocol::TType _etype32;
xfer += iprot->readListBegin(_etype32, _size29);
this->result_list.resize(_size29);
uint32_t _i33;
for (_i33 = 0; _i33 < _size29; ++_i33)
{
xfer += this->result_list[_i41].read(iprot);
xfer += this->result_list[_i33].read(iprot);
}
xfer += iprot->readListEnd();
}
@ -822,10 +730,10 @@ uint32_t VecSearchResultList::write(::apache::thrift::protocol::TProtocol* oprot
xfer += oprot->writeFieldBegin("result_list", ::apache::thrift::protocol::T_LIST, 1);
{
xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast<uint32_t>(this->result_list.size()));
std::vector<VecSearchResult> ::const_iterator _iter42;
for (_iter42 = this->result_list.begin(); _iter42 != this->result_list.end(); ++_iter42)
std::vector<VecSearchResult> ::const_iterator _iter34;
for (_iter34 = this->result_list.begin(); _iter34 != this->result_list.end(); ++_iter34)
{
xfer += (*_iter42).write(oprot);
xfer += (*_iter34).write(oprot);
}
xfer += oprot->writeListEnd();
}
@ -842,13 +750,13 @@ void swap(VecSearchResultList &a, VecSearchResultList &b) {
swap(a.__isset, b.__isset);
}
VecSearchResultList::VecSearchResultList(const VecSearchResultList& other43) {
result_list = other43.result_list;
__isset = other43.__isset;
VecSearchResultList::VecSearchResultList(const VecSearchResultList& other35) {
result_list = other35.result_list;
__isset = other35.__isset;
}
VecSearchResultList& VecSearchResultList::operator=(const VecSearchResultList& other44) {
result_list = other44.result_list;
__isset = other44.__isset;
VecSearchResultList& VecSearchResultList::operator=(const VecSearchResultList& other36) {
result_list = other36.result_list;
__isset = other36.__isset;
return *this;
}
void VecSearchResultList::printTo(std::ostream& out) const {
@ -1019,23 +927,23 @@ void swap(VecDateTime &a, VecDateTime &b) {
swap(a.__isset, b.__isset);
}
VecDateTime::VecDateTime(const VecDateTime& other45) {
year = other45.year;
month = other45.month;
day = other45.day;
hour = other45.hour;
minute = other45.minute;
second = other45.second;
__isset = other45.__isset;
VecDateTime::VecDateTime(const VecDateTime& other37) {
year = other37.year;
month = other37.month;
day = other37.day;
hour = other37.hour;
minute = other37.minute;
second = other37.second;
__isset = other37.__isset;
}
VecDateTime& VecDateTime::operator=(const VecDateTime& other46) {
year = other46.year;
month = other46.month;
day = other46.day;
hour = other46.hour;
minute = other46.minute;
second = other46.second;
__isset = other46.__isset;
VecDateTime& VecDateTime::operator=(const VecDateTime& other38) {
year = other38.year;
month = other38.month;
day = other38.day;
hour = other38.hour;
minute = other38.minute;
second = other38.second;
__isset = other38.__isset;
return *this;
}
void VecDateTime::printTo(std::ostream& out) const {
@ -1177,19 +1085,19 @@ void swap(VecTimeRange &a, VecTimeRange &b) {
swap(a.__isset, b.__isset);
}
VecTimeRange::VecTimeRange(const VecTimeRange& other47) {
time_begin = other47.time_begin;
begine_closed = other47.begine_closed;
time_end = other47.time_end;
end_closed = other47.end_closed;
__isset = other47.__isset;
VecTimeRange::VecTimeRange(const VecTimeRange& other39) {
time_begin = other39.time_begin;
begine_closed = other39.begine_closed;
time_end = other39.time_end;
end_closed = other39.end_closed;
__isset = other39.__isset;
}
VecTimeRange& VecTimeRange::operator=(const VecTimeRange& other48) {
time_begin = other48.time_begin;
begine_closed = other48.begine_closed;
time_end = other48.time_end;
end_closed = other48.end_closed;
__isset = other48.__isset;
VecTimeRange& VecTimeRange::operator=(const VecTimeRange& other40) {
time_begin = other40.time_begin;
begine_closed = other40.begine_closed;
time_end = other40.time_end;
end_closed = other40.end_closed;
__isset = other40.__isset;
return *this;
}
void VecTimeRange::printTo(std::ostream& out) const {
@ -1242,14 +1150,14 @@ uint32_t VecTimeRangeList::read(::apache::thrift::protocol::TProtocol* iprot) {
if (ftype == ::apache::thrift::protocol::T_LIST) {
{
this->range_list.clear();
uint32_t _size49;
::apache::thrift::protocol::TType _etype52;
xfer += iprot->readListBegin(_etype52, _size49);
this->range_list.resize(_size49);
uint32_t _i53;
for (_i53 = 0; _i53 < _size49; ++_i53)
uint32_t _size41;
::apache::thrift::protocol::TType _etype44;
xfer += iprot->readListBegin(_etype44, _size41);
this->range_list.resize(_size41);
uint32_t _i45;
for (_i45 = 0; _i45 < _size41; ++_i45)
{
xfer += this->range_list[_i53].read(iprot);
xfer += this->range_list[_i45].read(iprot);
}
xfer += iprot->readListEnd();
}
@ -1278,10 +1186,10 @@ uint32_t VecTimeRangeList::write(::apache::thrift::protocol::TProtocol* oprot) c
xfer += oprot->writeFieldBegin("range_list", ::apache::thrift::protocol::T_LIST, 1);
{
xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast<uint32_t>(this->range_list.size()));
std::vector<VecTimeRange> ::const_iterator _iter54;
for (_iter54 = this->range_list.begin(); _iter54 != this->range_list.end(); ++_iter54)
std::vector<VecTimeRange> ::const_iterator _iter46;
for (_iter46 = this->range_list.begin(); _iter46 != this->range_list.end(); ++_iter46)
{
xfer += (*_iter54).write(oprot);
xfer += (*_iter46).write(oprot);
}
xfer += oprot->writeListEnd();
}
@ -1298,13 +1206,13 @@ void swap(VecTimeRangeList &a, VecTimeRangeList &b) {
swap(a.__isset, b.__isset);
}
VecTimeRangeList::VecTimeRangeList(const VecTimeRangeList& other55) {
range_list = other55.range_list;
__isset = other55.__isset;
VecTimeRangeList::VecTimeRangeList(const VecTimeRangeList& other47) {
range_list = other47.range_list;
__isset = other47.__isset;
}
VecTimeRangeList& VecTimeRangeList::operator=(const VecTimeRangeList& other56) {
range_list = other56.range_list;
__isset = other56.__isset;
VecTimeRangeList& VecTimeRangeList::operator=(const VecTimeRangeList& other48) {
range_list = other48.range_list;
__isset = other48.__isset;
return *this;
}
void VecTimeRangeList::printTo(std::ostream& out) const {

View File

@ -43,8 +43,6 @@ class VecTensor;
class VecTensorList;
class VecTensorIdList;
class VecSearchResult;
class VecSearchResultList;
@ -160,7 +158,8 @@ void swap(VecGroup &a, VecGroup &b);
std::ostream& operator<<(std::ostream& out, const VecGroup& obj);
typedef struct _VecTensor__isset {
_VecTensor__isset() : tensor(false) {}
_VecTensor__isset() : uid(false), tensor(false) {}
bool uid :1;
bool tensor :1;
} _VecTensor__isset;
@ -169,18 +168,23 @@ class VecTensor : public virtual ::apache::thrift::TBase {
VecTensor(const VecTensor&);
VecTensor& operator=(const VecTensor&);
VecTensor() {
VecTensor() : uid() {
}
virtual ~VecTensor() throw();
std::string uid;
std::vector<double> tensor;
_VecTensor__isset __isset;
void __set_uid(const std::string& val);
void __set_tensor(const std::vector<double> & val);
bool operator == (const VecTensor & rhs) const
{
if (!(uid == rhs.uid))
return false;
if (!(tensor == rhs.tensor))
return false;
return true;
@ -243,48 +247,6 @@ void swap(VecTensorList &a, VecTensorList &b);
std::ostream& operator<<(std::ostream& out, const VecTensorList& obj);
typedef struct _VecTensorIdList__isset {
_VecTensorIdList__isset() : id_list(false) {}
bool id_list :1;
} _VecTensorIdList__isset;
class VecTensorIdList : public virtual ::apache::thrift::TBase {
public:
VecTensorIdList(const VecTensorIdList&);
VecTensorIdList& operator=(const VecTensorIdList&);
VecTensorIdList() {
}
virtual ~VecTensorIdList() throw();
std::vector<int64_t> id_list;
_VecTensorIdList__isset __isset;
void __set_id_list(const std::vector<int64_t> & val);
bool operator == (const VecTensorIdList & rhs) const
{
if (!(id_list == rhs.id_list))
return false;
return true;
}
bool operator != (const VecTensorIdList &rhs) const {
return !(*this == rhs);
}
bool operator < (const VecTensorIdList & ) const;
uint32_t read(::apache::thrift::protocol::TProtocol* iprot);
uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const;
virtual void printTo(std::ostream& out) const;
};
void swap(VecTensorIdList &a, VecTensorIdList &b);
std::ostream& operator<<(std::ostream& out, const VecTensorIdList& obj);
typedef struct _VecSearchResult__isset {
_VecSearchResult__isset() : id_list(false) {}
bool id_list :1;
@ -299,11 +261,11 @@ class VecSearchResult : public virtual ::apache::thrift::TBase {
}
virtual ~VecSearchResult() throw();
std::vector<int64_t> id_list;
std::vector<std::string> id_list;
_VecSearchResult__isset __isset;
void __set_id_list(const std::vector<int64_t> & val);
void __set_id_list(const std::vector<std::string> & val);
bool operator == (const VecSearchResult & rhs) const
{

View File

@ -29,6 +29,7 @@ void ClientApp::Run(const std::string &config_file) {
try {
ClientSession session(address, port, protocol);
//add group
const int32_t dim = 256;
VecGroup group;
group.id = "test_group";
@ -36,18 +37,36 @@ void ClientApp::Run(const std::string &config_file) {
group.index_type = 0;
session.interface()->add_group(group);
//add vectors
for(int64_t k = 0; k < 10000; k++) {
VecTensor tensor;
for(int32_t i = 0; i < dim; i++) {
tensor.tensor.push_back((double)(i + k));
}
tensor.uid = "vec_" + std::to_string(k);
VecTensorIdList result;
session.interface()->add_vector(result, group.id, tensor);
session.interface()->add_vector(group.id, tensor);
CLIENT_LOG_INFO << "add vector no." << k;
}
//search vector
{
VecTensor tensor;
for (int32_t i = 0; i < dim; i++) {
tensor.tensor.push_back((double) (i + 100));
}
VecSearchResult res;
VecTimeRangeList range;
session.interface()->search_vector(res, group.id, 10, tensor, range);
std::cout << "Search result: " << std::endl;
for(auto id : res.id_list) {
std::cout << id << std::endl;
}
}
} catch (std::exception& ex) {
CLIENT_LOG_ERROR << "request encounter exception: " << ex.what();
}

View File

@ -13,8 +13,7 @@ namespace zilliz {
namespace vecwise {
namespace client {
using VecServiceClientPtr = std::shared_ptr<VecServiceClient>;
using VecServiceClientPtr = std::shared_ptr<VecServiceClient>;
class ClientSession {
public: