Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
d37f89dc
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,发现更多精彩内容 >>
提交
d37f89dc
编写于
3月 24, 2019
作者:
X
xj.lin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some test
上级
584c60d3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
3 deletion
+65
-3
pyengine/engine/ingestion/build_index.py
pyengine/engine/ingestion/build_index.py
+1
-1
pyengine/engine/ingestion/tests/__init__.py
pyengine/engine/ingestion/tests/__init__.py
+0
-0
pyengine/engine/ingestion/tests/test_build.py
pyengine/engine/ingestion/tests/test_build.py
+63
-0
pyengine/engine/retrieval/tests/basic_test.py
pyengine/engine/retrieval/tests/basic_test.py
+1
-2
未找到文件。
pyengine/engine/ingestion/build_index.py
浏览文件 @
d37f89dc
...
...
@@ -35,7 +35,7 @@ class DefaultIndex(Index):
# maybe need to specif parameters
pass
def
build
(
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
def
build
(
self
,
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
index
=
faiss
.
IndexFlatL2
(
d
)
# trained
index
.
add
(
vectors
)
return
index
...
...
pyengine/engine/ingestion/tests/__init__.py
0 → 100644
浏览文件 @
d37f89dc
pyengine/engine/ingestion/tests/test_build.py
0 → 100644
浏览文件 @
d37f89dc
from
..build_index
import
*
import
faiss
import
numpy
as
np
import
unittest
class
TestBuildIndex
(
unittest
.
TestCase
):
def
test_factory_method
(
self
):
pass
def
test_default_index
(
self
):
d
=
64
nb
=
10000
nq
=
100
_
,
xb
,
xq
=
get_dataset
(
d
,
nb
,
500
,
nq
)
# Expected result
index
=
faiss
.
IndexFlatL2
(
d
)
index
.
add
(
xb
)
Dref
,
Iref
=
index
.
search
(
xq
,
5
)
builder
=
DefaultIndex
()
index2
=
builder
.
build
(
d
,
xb
)
Dnew
,
Inew
=
index2
.
search
(
xq
,
5
)
assert
np
.
all
(
Dnew
==
Dref
)
and
np
.
all
(
Inew
==
Iref
)
def
test_increase
(
self
):
d
=
64
nb
=
10000
nq
=
100
_
,
xb
,
xq
=
get_dataset
(
d
,
nb
,
500
,
nq
)
index
=
faiss
.
IndexFlatL2
(
d
)
index
.
add
(
xb
)
pass
def
test_serialize
(
self
):
pass
def
get_dataset
(
d
,
nb
,
nt
,
nq
):
"""A dataset that is not completely random but still challenging to
index
"""
d1
=
10
# intrinsic dimension (more or less)
n
=
nb
+
nt
+
nq
rs
=
np
.
random
.
RandomState
(
1338
)
x
=
rs
.
normal
(
size
=
(
n
,
d1
))
x
=
np
.
dot
(
x
,
rs
.
rand
(
d1
,
d
))
# now we have a d1-dim ellipsoid in d-dimensional space
# higher factor (>4) -> higher frequency -> less linear
x
=
x
*
(
rs
.
rand
(
d
)
*
4
+
0.1
)
x
=
np
.
sin
(
x
)
x
=
x
.
astype
(
'float32'
)
return
x
[:
nt
],
x
[
nt
:
-
nq
],
x
[
-
nq
:]
if
__name__
==
"__main__"
:
unittest
.
main
()
\ No newline at end of file
pyengine/engine/retrieval/tests/basic_test.py
浏览文件 @
d37f89dc
...
...
@@ -77,8 +77,7 @@ faiss.write_index(index, writer)
ar_data
=
faiss
.
vector_to_array
(
writer
.
data
)
import
pickle
pickle
.
dump
(
ar_data
,
open
(
"/tmp/faiss/ser_1"
,
"wb"
))
#index_3 = pickle.load("/tmp/faiss/ser_1")
index_3
=
pickle
.
load
(
"/tmp/faiss/ser_1"
)
# index_2 = faiss.IndexFlatL2(d) # build the index
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录