Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
5386d5e7
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5386d5e7
编写于
5月 29, 2019
作者:
G
groot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine sample code
Former-commit-id: 18bda8e3585dfd0bcfc699c6788a9af0eb53fc5f
上级
360d56fd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
70 addition
and
63 deletion
+70
-63
cpp/src/sdk/examples/simple/CMakeLists.txt
cpp/src/sdk/examples/simple/CMakeLists.txt
+0
-2
cpp/src/sdk/examples/simple/main.cpp
cpp/src/sdk/examples/simple/main.cpp
+11
-7
cpp/src/sdk/examples/simple/src/ClientTest.cpp
cpp/src/sdk/examples/simple/src/ClientTest.cpp
+28
-24
cpp/src/server/RocksIdMapper.cpp
cpp/src/server/RocksIdMapper.cpp
+1
-0
cpp/src/server/RocksIdMapper.h
cpp/src/server/RocksIdMapper.h
+5
-2
cpp/src/server/VecIdMapper.cpp
cpp/src/server/VecIdMapper.cpp
+25
-0
cpp/src/server/VecIdMapper.h
cpp/src/server/VecIdMapper.h
+0
-28
未找到文件。
cpp/src/sdk/examples/simple/CMakeLists.txt
浏览文件 @
5386d5e7
...
@@ -8,14 +8,12 @@ aux_source_directory(src src_files)
...
@@ -8,14 +8,12 @@ aux_source_directory(src src_files)
include_directories
(
src
)
include_directories
(
src
)
include_directories
(
../../megasearch_sdk/include
)
include_directories
(
../../megasearch_sdk/include
)
include_directories
(
/usr/include
)
link_directories
(
${
CMAKE_BINARY_DIR
}
/megasearch_sdk
)
link_directories
(
${
CMAKE_BINARY_DIR
}
/megasearch_sdk
)
add_executable
(
sdk_simple
add_executable
(
sdk_simple
./main.cpp
./main.cpp
${
src_files
}
${
src_files
}
${
service_files
}
)
)
target_link_libraries
(
sdk_simple
target_link_libraries
(
sdk_simple
...
...
cpp/src/sdk/examples/simple/main.cpp
浏览文件 @
5386d5e7
...
@@ -19,7 +19,8 @@ main(int argc, char *argv[]) {
...
@@ -19,7 +19,8 @@ main(int argc, char *argv[]) {
printf
(
"Client start...
\n
"
);
printf
(
"Client start...
\n
"
);
std
::
string
app_name
=
basename
(
argv
[
0
]);
std
::
string
app_name
=
basename
(
argv
[
0
]);
static
struct
option
long_options
[]
=
{{
"conf_file"
,
optional_argument
,
0
,
'c'
},
static
struct
option
long_options
[]
=
{{
"server"
,
optional_argument
,
0
,
's'
},
{
"port"
,
optional_argument
,
0
,
'p'
},
{
"help"
,
no_argument
,
0
,
'h'
},
{
"help"
,
no_argument
,
0
,
'h'
},
{
NULL
,
0
,
0
,
0
}};
{
NULL
,
0
,
0
,
0
}};
...
@@ -28,9 +29,9 @@ main(int argc, char *argv[]) {
...
@@ -28,9 +29,9 @@ main(int argc, char *argv[]) {
app_name
=
argv
[
0
];
app_name
=
argv
[
0
];
int
value
;
int
value
;
while
((
value
=
getopt_long
(
argc
,
argv
,
"
c:p:d
h"
,
long_options
,
&
option_index
))
!=
-
1
)
{
while
((
value
=
getopt_long
(
argc
,
argv
,
"
s:p:
h"
,
long_options
,
&
option_index
))
!=
-
1
)
{
switch
(
value
)
{
switch
(
value
)
{
case
'
h
'
:
{
case
'
s
'
:
{
char
*
address_ptr
=
strdup
(
optarg
);
char
*
address_ptr
=
strdup
(
optarg
);
address
=
address_ptr
;
address
=
address_ptr
;
free
(
address_ptr
);
free
(
address_ptr
);
...
@@ -38,12 +39,14 @@ main(int argc, char *argv[]) {
...
@@ -38,12 +39,14 @@ main(int argc, char *argv[]) {
}
}
case
'p'
:
{
case
'p'
:
{
char
*
port_ptr
=
strdup
(
optarg
);
char
*
port_ptr
=
strdup
(
optarg
);
address
=
port_ptr
;
port
=
port_ptr
;
free
(
port_ptr
);
free
(
port_ptr
);
break
;
break
;
}
}
case
'h'
:
default:
default:
break
;
print_help
(
app_name
);
return
EXIT_SUCCESS
;
}
}
}
}
...
@@ -58,7 +61,8 @@ void
...
@@ -58,7 +61,8 @@ void
print_help
(
const
std
::
string
&
app_name
)
{
print_help
(
const
std
::
string
&
app_name
)
{
printf
(
"
\n
Usage: %s [OPTIONS]
\n\n
"
,
app_name
.
c_str
());
printf
(
"
\n
Usage: %s [OPTIONS]
\n\n
"
,
app_name
.
c_str
());
printf
(
" Options:
\n
"
);
printf
(
" Options:
\n
"
);
printf
(
" -h Megasearch server address
\n
"
);
printf
(
" -s --server Server address, default 127.0.0.1
\n
"
);
printf
(
" -p Megasearch server port
\n
"
);
printf
(
" -p --port Server port, default 33001
\n
"
);
printf
(
" -h --help Print help information
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
\ No newline at end of file
cpp/src/sdk/examples/simple/src/ClientTest.cpp
浏览文件 @
5386d5e7
...
@@ -13,6 +13,16 @@
...
@@ -13,6 +13,16 @@
using
namespace
megasearch
;
using
namespace
megasearch
;
namespace
{
namespace
{
std
::
string
GetTableName
();
static
const
std
::
string
TABLE_NAME
=
GetTableName
();
static
const
std
::
string
VECTOR_COLUMN_NAME
=
"face_vector"
;
static
const
std
::
string
ID_COLUMN_NAME
=
"aid"
;
static
const
std
::
string
CITY_COLUMN_NAME
=
"city"
;
static
constexpr
int64_t
TABLE_DIMENSION
=
512
;
static
constexpr
int64_t
TOTAL_ROW_COUNT
=
100000
;
static
constexpr
int64_t
TOP_K
=
10
;
static
constexpr
int64_t
SEARCH_TARGET
=
5000
;
//change this value, result is different
#define BLOCK_SPLITER std::cout << "===========================================" << std::endl;
#define BLOCK_SPLITER std::cout << "===========================================" << std::endl;
...
@@ -76,12 +86,6 @@ namespace {
...
@@ -76,12 +86,6 @@ namespace {
return
s_id
;
return
s_id
;
}
}
static
const
std
::
string
TABLE_NAME
=
GetTableName
();
static
const
std
::
string
VECTOR_COLUMN_NAME
=
"face_vector"
;
static
const
std
::
string
AGE_COLUMN_NAME
=
"age"
;
static
const
std
::
string
CITY_COLUMN_NAME
=
"city"
;
static
const
int64_t
TABLE_DIMENSION
=
512
;
TableSchema
BuildTableSchema
()
{
TableSchema
BuildTableSchema
()
{
TableSchema
tb_schema
;
TableSchema
tb_schema
;
VectorColumn
col1
;
VectorColumn
col1
;
...
@@ -90,7 +94,7 @@ namespace {
...
@@ -90,7 +94,7 @@ namespace {
col1
.
store_raw_vector
=
true
;
col1
.
store_raw_vector
=
true
;
tb_schema
.
vector_column_array
.
emplace_back
(
col1
);
tb_schema
.
vector_column_array
.
emplace_back
(
col1
);
Column
col2
=
{
ColumnType
::
int8
,
AGE
_COLUMN_NAME
};
Column
col2
=
{
ColumnType
::
int8
,
ID
_COLUMN_NAME
};
tb_schema
.
attribute_column_array
.
emplace_back
(
col2
);
tb_schema
.
attribute_column_array
.
emplace_back
(
col2
);
Column
col3
=
{
ColumnType
::
int16
,
CITY_COLUMN_NAME
};
Column
col3
=
{
ColumnType
::
int16
,
CITY_COLUMN_NAME
};
...
@@ -139,7 +143,7 @@ namespace {
...
@@ -139,7 +143,7 @@ namespace {
if
(
vector_record_array
)
{
if
(
vector_record_array
)
{
RowRecord
record
;
RowRecord
record
;
record
.
vector_map
.
insert
(
std
::
make_pair
(
VECTOR_COLUMN_NAME
,
f_p
));
record
.
vector_map
.
insert
(
std
::
make_pair
(
VECTOR_COLUMN_NAME
,
f_p
));
record
.
attribute_map
[
AGE_COLUMN_NAME
]
=
std
::
to_string
(
k
%
100
);
record
.
attribute_map
[
ID_COLUMN_NAME
]
=
std
::
to_string
(
k
);
record
.
attribute_map
[
CITY_COLUMN_NAME
]
=
CITY_MAP
.
at
(
k
%
CITY_MAP
.
size
());
record
.
attribute_map
[
CITY_COLUMN_NAME
]
=
CITY_MAP
.
at
(
k
%
CITY_MAP
.
size
());
vector_record_array
->
emplace_back
(
record
);
vector_record_array
->
emplace_back
(
record
);
}
}
...
@@ -147,7 +151,7 @@ namespace {
...
@@ -147,7 +151,7 @@ namespace {
if
(
query_record_array
)
{
if
(
query_record_array
)
{
QueryRecord
record
;
QueryRecord
record
;
record
.
vector_map
.
insert
(
std
::
make_pair
(
VECTOR_COLUMN_NAME
,
f_p
));
record
.
vector_map
.
insert
(
std
::
make_pair
(
VECTOR_COLUMN_NAME
,
f_p
));
record
.
selected_column_array
.
push_back
(
AGE
_COLUMN_NAME
);
record
.
selected_column_array
.
push_back
(
ID
_COLUMN_NAME
);
record
.
selected_column_array
.
push_back
(
CITY_COLUMN_NAME
);
record
.
selected_column_array
.
push_back
(
CITY_COLUMN_NAME
);
query_record_array
->
emplace_back
(
record
);
query_record_array
->
emplace_back
(
record
);
}
}
...
@@ -161,16 +165,20 @@ ClientTest::Test(const std::string& address, const std::string& port) {
...
@@ -161,16 +165,20 @@ ClientTest::Test(const std::string& address, const std::string& port) {
ConnectParam
param
=
{
address
,
port
};
ConnectParam
param
=
{
address
,
port
};
conn
->
Connect
(
param
);
conn
->
Connect
(
param
);
{
//
get
server version
{
//server version
std
::
string
version
=
conn
->
ServerVersion
();
std
::
string
version
=
conn
->
ServerVersion
();
std
::
cout
<<
"MegaSearch server version: "
<<
version
<<
std
::
endl
;
std
::
cout
<<
"MegaSearch server version: "
<<
version
<<
std
::
endl
;
}
}
{
//sdk version
std
::
string
version
=
conn
->
ClientVersion
();
std
::
cout
<<
"SDK version: "
<<
version
<<
std
::
endl
;
}
{
{
std
::
cout
<<
"ShowTables"
<<
std
::
endl
;
std
::
vector
<
std
::
string
>
tables
;
std
::
vector
<
std
::
string
>
tables
;
Status
stat
=
conn
->
ShowTables
(
tables
);
Status
stat
=
conn
->
ShowTables
(
tables
);
std
::
cout
<<
"
F
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
std
::
cout
<<
"
ShowTables f
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
std
::
cout
<<
"All tables: "
<<
std
::
endl
;
std
::
cout
<<
"All tables: "
<<
std
::
endl
;
for
(
auto
&
table
:
tables
)
{
for
(
auto
&
table
:
tables
)
{
std
::
cout
<<
"
\t
"
<<
table
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
table
<<
std
::
endl
;
...
@@ -180,26 +188,23 @@ ClientTest::Test(const std::string& address, const std::string& port) {
...
@@ -180,26 +188,23 @@ ClientTest::Test(const std::string& address, const std::string& port) {
{
//create table
{
//create table
TableSchema
tb_schema
=
BuildTableSchema
();
TableSchema
tb_schema
=
BuildTableSchema
();
PrintTableSchema
(
tb_schema
);
PrintTableSchema
(
tb_schema
);
std
::
cout
<<
"CreateTable"
<<
std
::
endl
;
Status
stat
=
conn
->
CreateTable
(
tb_schema
);
Status
stat
=
conn
->
CreateTable
(
tb_schema
);
std
::
cout
<<
"
F
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
std
::
cout
<<
"
CreateTable f
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
}
}
{
//describe table
{
//describe table
TableSchema
tb_schema
;
TableSchema
tb_schema
;
std
::
cout
<<
"DescribeTable"
<<
std
::
endl
;
Status
stat
=
conn
->
DescribeTable
(
TABLE_NAME
,
tb_schema
);
Status
stat
=
conn
->
DescribeTable
(
TABLE_NAME
,
tb_schema
);
std
::
cout
<<
"
F
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
std
::
cout
<<
"
DescribeTable f
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
PrintTableSchema
(
tb_schema
);
PrintTableSchema
(
tb_schema
);
}
}
{
//add vectors
{
//add vectors
std
::
vector
<
RowRecord
>
record_array
;
std
::
vector
<
RowRecord
>
record_array
;
BuildVectors
(
0
,
10000
,
&
record_array
,
nullptr
);
BuildVectors
(
0
,
TOTAL_ROW_COUNT
,
&
record_array
,
nullptr
);
std
::
vector
<
int64_t
>
record_ids
;
std
::
vector
<
int64_t
>
record_ids
;
std
::
cout
<<
"AddVector"
<<
std
::
endl
;
Status
stat
=
conn
->
AddVector
(
TABLE_NAME
,
record_array
,
record_ids
);
Status
stat
=
conn
->
AddVector
(
TABLE_NAME
,
record_array
,
record_ids
);
std
::
cout
<<
"
F
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
std
::
cout
<<
"
AddVector f
unction call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
PrintRecordIdArray
(
record_ids
);
PrintRecordIdArray
(
record_ids
);
}
}
...
@@ -207,18 +212,17 @@ ClientTest::Test(const std::string& address, const std::string& port) {
...
@@ -207,18 +212,17 @@ ClientTest::Test(const std::string& address, const std::string& port) {
std
::
cout
<<
"Waiting data persist. Sleep 10 seconds ..."
<<
std
::
endl
;
std
::
cout
<<
"Waiting data persist. Sleep 10 seconds ..."
<<
std
::
endl
;
sleep
(
10
);
sleep
(
10
);
std
::
vector
<
QueryRecord
>
record_array
;
std
::
vector
<
QueryRecord
>
record_array
;
BuildVectors
(
500
,
5
10
,
nullptr
,
&
record_array
);
BuildVectors
(
SEARCH_TARGET
,
SEARCH_TARGET
+
10
,
nullptr
,
&
record_array
);
std
::
vector
<
TopKQueryResult
>
topk_query_result_array
;
std
::
vector
<
TopKQueryResult
>
topk_query_result_array
;
std
::
cout
<<
"SearchVector"
<<
std
::
endl
;
Status
stat
=
conn
->
SearchVector
(
TABLE_NAME
,
record_array
,
topk_query_result_array
,
TOP_K
);
Status
stat
=
conn
->
SearchVector
(
TABLE_NAME
,
record_array
,
topk_query_result_array
,
10
);
std
::
cout
<<
"SearchVector function call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
std
::
cout
<<
"Function call status: "
<<
stat
.
ToString
()
<<
std
::
endl
;
PrintSearchResult
(
topk_query_result_array
);
PrintSearchResult
(
topk_query_result_array
);
}
}
// {//delete table
// {//delete table
// Status stat = conn->DeleteTable(TABLE_NAME);
// Status stat = conn->DeleteTable(TABLE_NAME);
// std::cout << "Delete
table result
: " << stat.ToString() << std::endl;
// std::cout << "Delete
Table function call status
: " << stat.ToString() << std::endl;
// }
// }
{
//server status
{
//server status
...
...
cpp/src/server/RocksIdMapper.cpp
浏览文件 @
5386d5e7
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include "utils/Log.h"
#include "utils/Log.h"
#include "utils/CommonUtil.h"
#include "utils/CommonUtil.h"
#include "rocksdb/db.h"
#include "rocksdb/slice.h"
#include "rocksdb/slice.h"
#include "rocksdb/options.h"
#include "rocksdb/options.h"
...
...
cpp/src/server/RocksIdMapper.h
浏览文件 @
5386d5e7
...
@@ -8,13 +8,16 @@
...
@@ -8,13 +8,16 @@
#include "utils/Error.h"
#include "utils/Error.h"
#include "VecIdMapper.h"
#include "VecIdMapper.h"
#include "rocksdb/db.h"
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <unordered_map>
#include <unordered_map>
#include <mutex>
#include <mutex>
namespace
rocksdb
{
class
DB
;
class
ColumnFamilyHandle
;
}
namespace
zilliz
{
namespace
zilliz
{
namespace
vecwise
{
namespace
vecwise
{
namespace
server
{
namespace
server
{
...
...
cpp/src/server/VecIdMapper.cpp
浏览文件 @
5386d5e7
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include "rocksdb/options.h"
#include "rocksdb/options.h"
#include <exception>
#include <exception>
#include <unordered_map>
namespace
zilliz
{
namespace
zilliz
{
namespace
vecwise
{
namespace
vecwise
{
...
@@ -30,6 +31,30 @@ IVecIdMapper* IVecIdMapper::GetInstance() {
...
@@ -30,6 +31,30 @@ IVecIdMapper* IVecIdMapper::GetInstance() {
#endif
#endif
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class
SimpleIdMapper
:
public
IVecIdMapper
{
public:
SimpleIdMapper
();
~
SimpleIdMapper
();
ServerError
AddGroup
(
const
std
::
string
&
group
)
override
;
bool
IsGroupExist
(
const
std
::
string
&
group
)
const
override
;
ServerError
AllGroups
(
std
::
vector
<
std
::
string
>&
groups
)
const
override
;
ServerError
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
Get
(
const
std
::
string
&
nid
,
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
const
override
;
ServerError
Get
(
const
std
::
vector
<
std
::
string
>&
nid
,
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
const
override
;
ServerError
Delete
(
const
std
::
string
&
nid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
DeleteGroup
(
const
std
::
string
&
group
)
override
;
private:
using
ID_MAPPING
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
;
mutable
std
::
unordered_map
<
std
::
string
,
ID_MAPPING
>
id_groups_
;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SimpleIdMapper
::
SimpleIdMapper
()
{
SimpleIdMapper
::
SimpleIdMapper
()
{
...
...
cpp/src/server/VecIdMapper.h
浏览文件 @
5386d5e7
...
@@ -9,11 +9,6 @@
...
@@ -9,11 +9,6 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <unordered_map>
namespace
rocksdb
{
class
DB
;
}
namespace
zilliz
{
namespace
zilliz
{
namespace
vecwise
{
namespace
vecwise
{
...
@@ -40,29 +35,6 @@ public:
...
@@ -40,29 +35,6 @@ public:
virtual
ServerError
DeleteGroup
(
const
std
::
string
&
group
)
=
0
;
virtual
ServerError
DeleteGroup
(
const
std
::
string
&
group
)
=
0
;
};
};
class
SimpleIdMapper
:
public
IVecIdMapper
{
public:
SimpleIdMapper
();
~
SimpleIdMapper
();
ServerError
AddGroup
(
const
std
::
string
&
group
)
override
;
bool
IsGroupExist
(
const
std
::
string
&
group
)
const
override
;
ServerError
AllGroups
(
std
::
vector
<
std
::
string
>&
groups
)
const
override
;
ServerError
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
Get
(
const
std
::
string
&
nid
,
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
const
override
;
ServerError
Get
(
const
std
::
vector
<
std
::
string
>&
nid
,
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
const
override
;
ServerError
Delete
(
const
std
::
string
&
nid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
DeleteGroup
(
const
std
::
string
&
group
)
override
;
private:
using
ID_MAPPING
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
;
mutable
std
::
unordered_map
<
std
::
string
,
ID_MAPPING
>
id_groups_
;
};
}
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录