refine c++sdk

Signed-off-by: groot <yihua.mo@zilliz.com>
This commit is contained in:
groot 2020-03-08 12:13:06 +08:00
parent ab8339ced4
commit fcb5656819
5 changed files with 193 additions and 229 deletions

View File

@ -415,21 +415,6 @@ ClientProxy::ServerStatus() const {
}
}
std::string
ClientProxy::DumpTaskTables() const {
if (channel_ == nullptr) {
return "not connected to server";
}
try {
std::string dummy;
Status status = client_ptr_->Cmd("tasktable", dummy);
return dummy;
} catch (std::exception& ex) {
return "connection lost";
}
}
Status
ClientProxy::DeleteByID(const std::string& table_name, const std::vector<int64_t>& id_array) {
try {

View File

@ -84,9 +84,6 @@ class ClientProxy : public Connection {
std::string
ServerStatus() const override;
std::string
DumpTaskTables() const override;
Status
DeleteByID(const std::string& table_name, const std::vector<int64_t>& id_array) override;

View File

@ -54,20 +54,19 @@ struct ConnectParam {
};
/**
* @brief Table Schema
* @brief Collection parameters
*/
struct TableSchema {
std::string table_name; ///< Table name
struct CollectionParam {
std::string collection_name; ///< Collection_name name
int64_t dimension = 0; ///< Vector dimension, must be a positive value
int64_t index_file_size = 1024; ///< Index file size, must be a positive value, unit: MB
MetricType metric_type = MetricType::L2; ///< Index metric type
};
/**
* @brief Record inserted
* @brief Entity inserted, currently each entity represent a vector
*/
struct RowRecord {
struct Entity {
std::vector<float> float_data; ///< Vector raw float data
std::vector<uint8_t> binary_data; ///< Vector raw binary data
};
@ -76,7 +75,7 @@ struct RowRecord {
* @brief TopK query result
*/
struct QueryResult {
std::vector<int64_t> ids; ///< Query ids result
std::vector<int64_t> ids; ///< Query entity ids result
std::vector<float> distances; ///< Query distances result
};
using TopKQueryResult = std::vector<QueryResult>; ///< Topk query result
@ -85,13 +84,14 @@ using TopKQueryResult = std::vector<QueryResult>; ///< Topk query result
* @brief Index parameters
* Note: extra_params is extra parameters list, it must be json format
* For different index type, parameter list is different accordingly, for example:
* FLAT/IVFLAT/SQ8: "{nlist: '16384'}"
* IVFPQ: "{nlist: '16384', nbits: "16"}"
* NSG: "{search_length: '100', out_degree:'40', pool_size:'66'}"
* HNSW "{M: '16', ef_construct:'500'}"
* FLAT/IVFLAT/SQ8: "{nlist: '16384'}" nlist range:[1, 999999]
* IVFPQ: "{nlist: '16384', m: "12"}" nlist range:[1, 999999] m is decided by dim and have a couple of results.
* NSG: "{search_length: '45', out_degree:'50', candidate_pool_size:'300', "knng":'100'}"
* search_length range:[10, 300] out_degree range:[5, 300] candidate_pool_size range:[50, 1000] knng range:[5, 300]
* HNSW "{M: '16', efConstruction:'500'}" M range:[5, 48] efConstruction range:[topk, 4096]
*/
struct IndexParam {
std::string table_name; ///< Table name for create index
std::string collection_name; ///< Collection name for create index
IndexType index_type; ///< Index type
std::string extra_params; ///< Extra parameters according to different index type, must be json format
};
@ -100,7 +100,7 @@ struct IndexParam {
* @brief partition parameters
*/
struct PartitionParam {
std::string table_name;
std::string collection_name;
std::string partition_tag;
};
@ -126,11 +126,11 @@ struct PartitionStat {
};
/**
* @brief table info
* @brief collection info
*/
struct TableInfo {
int64_t total_row_count; ///< Table total row count
std::vector<PartitionStat> partitions_stat; ///< Table's partitions statistics
struct CollectionInfo {
int64_t total_row_count; ///< Collection total entity count
std::vector<PartitionStat> partitions_stat; ///< Collection's partitions statistics
};
/**
@ -209,182 +209,6 @@ class Connection {
virtual Status
Disconnect() = 0;
/**
* @brief Create table method
*
* This method is used to create table.
*
* @param param, use to provide table information to be created.
*
* @return Indicate if table is created successfully
*/
virtual Status
CreateTable(const TableSchema& param) = 0;
/**
* @brief Test table existence method
*
* This method is used to create table.
*
* @param table_name, target table's name.
*
* @return Indicate if table is cexist
*/
virtual bool
HasTable(const std::string& table_name) = 0;
/**
* @brief Drop table method
*
* This method is used to drop table(and its partitions).
*
* @param table_name, target table's name.
*
* @return Indicate if table is drop successfully.
*/
virtual Status
DropTable(const std::string& table_name) = 0;
/**
* @brief Create index method
*
* This method is used to create index for whole table(and its partitions).
*
* @param IndexParam
* table_name, table name is going to be create index.
* index type,
* nlist,
* index file size
*
* @return Indicate if build index successfully.
*/
virtual Status
CreateIndex(const IndexParam& index_param) = 0;
/**
* @brief Insert vector to table
*
* This method is used to insert vector array to table.
*
* @param table_name, target table's name.
* @param partition_tag, target partition's tag, keep empty if no partition specified.
* @param record_array, vector array is inserted.
* @param id_array,
* specify id for each vector,
* if this array is empty, milvus will generate unique id for each vector,
* and return all ids by this parameter.
*
* @return Indicate if vector array are inserted successfully
*/
virtual Status
Insert(const std::string& table_name, const std::string& partition_tag, const std::vector<RowRecord>& record_array,
std::vector<int64_t>& id_array) = 0;
/**
* @brief Get vector data by id
*
* This method is used to get vector data by id from a table.
* Return the first found vector if there are vectors with duplicated id
*
* @param table_name, target table's name.
* @param vector_id, target vector id.
* @param vector_data, returned vector data.
*
* @return Indicate if the operation is succeed.
*/
virtual Status
GetVectorByID(const std::string& table_name, int64_t vector_id, RowRecord& vector_data) = 0;
/**
* @brief Get vector ids from a segment
*
* This method is used to get vector ids from a segment
* Return all vector(not deleted) ids
*
* @param table_name, target table's name.
* @param segment_name, target segment name.
* @param id_array, returned vector id array.
*
* @return Indicate if the operation is succeed.
*/
virtual Status
GetIDsInSegment(const std::string& table_name, const std::string& segment_name, std::vector<int64_t>& id_array) = 0;
/**
* @brief Search vector
*
* This method is used to query vector in table.
*
* @param table_name, target table's name.
* @param partition_tag_array, target partitions, keep empty if no partition specified.
* @param query_record_array, vectors to be queried.
* @param topk, how many similarity vectors will be returned.
* @param extra_params, extra search parameters according to different index type, must be json format.
* Note: extra_params is extra parameters list, it must be json format, for example:
* For different index type, parameter list is different accordingly
* FLAT/IVFLAT/SQ8/IVFPQ: "{nprobe: '32'}"
* NSG: "{search_length:'100'}
* HNSW "{ef: '64'}
* @param topk_query_result, result array.
*
* @return Indicate if query is successful.
*/
virtual Status
Search(const std::string& table_name, const PartitionTagList& partition_tag_array,
const std::vector<RowRecord>& query_record_array, int64_t topk,
const std::string& extra_params, TopKQueryResult& topk_query_result) = 0;
/**
* @brief Show table description
*
* This method is used to show table information.
*
* @param table_name, target table's name.
* @param table_schema, table_schema is given when operation is successful.
*
* @return Indicate if this operation is successful.
*/
virtual Status
DescribeTable(const std::string& table_name, TableSchema& table_schema) = 0;
/**
* @brief Get table row count
*
* This method is used to get table row count.
*
* @param table_name, target table's name.
* @param row_count, table total row count(including partitions).
*
* @return Indicate if this operation is successful.
*/
virtual Status
CountTable(const std::string& table_name, int64_t& row_count) = 0;
/**
* @brief Show all tables in database
*
* This method is used to list all tables.
*
* @param table_array, all tables in database.
*
* @return Indicate if this operation is successful.
*/
virtual Status
ShowTables(std::vector<std::string>& table_array) = 0;
/**
* @brief Show table information
*
* This method is used to get detail information of a table.
*
* @param table_name, target table's name.
* @param table_info, target table's information
*
* @return Indicate if this operation is successful.
*/
virtual Status
ShowTableInfo(const std::string& table_name, TableInfo& table_info) = 0;
/**
* @brief Give the client version
*
@ -405,6 +229,182 @@ class Connection {
virtual std::string
ServerVersion() const = 0;
/**
* @brief Create collection method
*
* This method is used to create collection.
*
* @param param, use to provide collection information to be created.
*
* @return Indicate if collection is created successfully
*/
virtual Status
CreateCollection(const CollectionParam& param) = 0;
/**
* @brief Test collection existence method
*
* This method is used to test collection existence.
*
* @param collection_name, target collection's name.
*
* @return Indicate if collection is cexist
*/
virtual bool
HasCollection(const std::string& collection_name) = 0;
/**
* @brief Drop collection method
*
* This method is used to drop collection(and its partitions).
*
* @param collection_name, target collection's name.
*
* @return Indicate if collection is drop successfully.
*/
virtual Status
DropCollection(const std::string& collection_name) = 0;
/**
* @brief Create index method
*
* This method is used to create index for whole collection(and its partitions).
*
* @param index_param, use to provide index information to be created.
*
* @return Indicate if create index successfully.
*/
virtual Status
CreateIndex(const IndexParam& index_param) = 0;
/**
* @brief Insert entity to table
*
* This method is used to insert vector array to table.
*
* @param collection_name, target collection's name.
* @param partition_tag, target partition's tag, keep empty if no partition specified.
* @param entity_array, entity array is inserted, each entitu represent a vector.
* @param id_array,
* specify id for each entity,
* if this array is empty, milvus will generate unique id for each entity,
* and return all ids by this parameter.
*
* @return Indicate if entity array are inserted successfully
*/
virtual Status
Insert(const std::string& collection_name,
const std::string& partition_tag,
const std::vector<Entity>& entity_array,
std::vector<int64_t>& id_array) = 0;
/**
* @brief Get entity data by id
*
* This method is used to get entity data by id from a collection.
* Return the first found entity if there are entities with duplicated id
*
* @param collection_name, target collection's name.
* @param entity_id, target entity id.
* @param entity_data, returned entity data.
*
* @return Indicate if the operation is succeed.
*/
virtual Status
GetEntityByID(const std::string& collection_name, int64_t entity_id, Entity& entity_data) = 0;
/**
* @brief Get entity ids from a segment
*
* This method is used to get entity ids from a segment
* Return all entity(not deleted) ids
*
* @param collection_name, target collection's name.
* @param segment_name, target segment name.
* @param id_array, returned entity id array.
*
* @return Indicate if the operation is succeed.
*/
virtual Status
GetIDsInSegment(const std::string& collection_name,
const std::string& segment_name,
std::vector<int64_t>& id_array) = 0;
/**
* @brief Search entities in a collection
*
* This method is used to query entity in collection.
*
* @param collection_name, target collection's name.
* @param partition_tag_array, target partitions, keep empty if no partition specified.
* @param query_record_array, vectors to be queried.
* @param topk, how many similarity vectors will be returned.
* @param extra_params, extra search parameters according to different index type, must be json format.
* Note: extra_params is extra parameters list, it must be json format, for example:
* For different index type, parameter list is different accordingly
* FLAT/IVFLAT/SQ8/IVFPQ: "{nprobe: '32'}"
* NSG: "{search_length:'100'}
* HNSW "{ef: '64'}
* @param topk_query_result, result array.
*
* @return Indicate if query is successful.
*/
virtual Status
Search(const std::string& table_name, const PartitionTagList& partition_tag_array,
const std::vector<Entity>& query_record_array, int64_t topk,
const std::string& extra_params, TopKQueryResult& topk_query_result) = 0;
/**
* @brief Show collection description
*
* This method is used to show collection information.
*
* @param collection_name, target collection's name.
* @param collection_schema, collection_schema is given when operation is successful.
*
* @return Indicate if this operation is successful.
*/
virtual Status
DescribeCollection(const std::string& collection_name, TableSchema& collection_schema) = 0;
/**
* @brief Get collection row count
*
* This method is used to get collection row count.
*
* @param collection_name, target collection's name.
* @param entity_count, collection total entity count(including partitions).
*
* @return Indicate if this operation is successful.
*/
virtual Status
CountCollection(const std::string& collection_name, int64_t& entity_count) = 0;
/**
* @brief Show all collections in database
*
* This method is used to list all collections.
*
* @param collection_array, all collections in database.
*
* @return Indicate if this operation is successful.
*/
virtual Status
ShowCollections(std::vector<std::string>& collection_array) = 0;
/**
* @brief Show collections information
*
* This method is used to get detail information of a collections.
*
* @param collections_name, target collections's name.
* @param collections_info, target collections's information
*
* @return Indicate if this operation is successful.
*/
virtual Status
ShowCollectionInfo(const std::string& collections_name, TableInfo& collections_info) = 0;
/**
* @brief Give the server status
*
@ -415,16 +415,6 @@ class Connection {
virtual std::string
ServerStatus() const = 0;
/**
* @brief dump server tasks information
*
* This method is internal used.
*
* @return Task information in tasktables.
*/
virtual std::string
DumpTaskTables() const = 0;
/**
* [deprecated]
* @brief delete tables by vector id

View File

@ -130,11 +130,6 @@ ConnectionImpl::ServerStatus() const {
return client_proxy_->ServerStatus();
}
std::string
ConnectionImpl::DumpTaskTables() const {
return client_proxy_->DumpTaskTables();
}
Status
ConnectionImpl::DeleteByID(const std::string& table_name, const std::vector<int64_t>& id_array) {
return client_proxy_->DeleteByID(table_name, id_array);

View File

@ -86,9 +86,6 @@ class ConnectionImpl : public Connection {
std::string
ServerStatus() const override;
std::string
DumpTaskTables() const override;
Status
DeleteByID(const std::string& table_name, const std::vector<int64_t>& id_array) override;