Skip to content

Commit 3978e18

Browse files
committed
fix lint
1 parent d433304 commit 3978e18

41 files changed

Lines changed: 340 additions & 927 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

install.py

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,52 @@
44

55

66
def docker_tag_base():
7-
return 'vdbbench'
7+
return "vdbbench"
8+
89

910
def dockerfile_path_base():
10-
return os.path.join('vectordb_bench/', '../Dockerfile')
11+
return os.path.join("vectordb_bench/", "../Dockerfile")
12+
1113

1214
def docker_tag(track, algo):
13-
return docker_tag_base() + '-' + track + '-' + algo
15+
return docker_tag_base() + "-" + track + "-" + algo
1416

1517

1618
def build(tag, args, dockerfile):
17-
print('Building %s...' % tag)
19+
print("Building %s..." % tag)
1820
if args is not None and len(args) != 0:
1921
q = " ".join(["--build-arg " + x.replace(" ", "\\ ") for x in args])
2022
else:
2123
q = ""
2224

2325
try:
24-
command = 'docker build %s --rm -t %s -f' \
25-
% (q, tag)
26-
command += ' %s .' % dockerfile
26+
command = "docker build %s --rm -t %s -f" % (q, tag)
27+
command += " %s ." % dockerfile
2728
print(command)
2829
subprocess.check_call(command, shell=True)
29-
return {tag: 'success'}
30+
return {tag: "success"}
3031
except subprocess.CalledProcessError:
31-
return {tag: 'fail'}
32+
return {tag: "fail"}
33+
3234

3335
def build_multiprocess(args):
3436
return build(*args)
3537

3638

3739
if __name__ == "__main__":
38-
parser = argparse.ArgumentParser(
39-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
40-
parser.add_argument(
41-
"--proc",
42-
default=1,
43-
type=int,
44-
help="the number of process to build docker images")
40+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
41+
parser.add_argument("--proc", default=1, type=int, help="the number of process to build docker images")
42+
parser.add_argument("--track", choices=["none"], default="none")
43+
parser.add_argument("--algorithm", metavar="NAME", help="build only the named algorithm image", default=None)
4544
parser.add_argument(
46-
'--track',
47-
choices=['none'],
48-
default='none'
45+
"--dockerfile", metavar="PATH", help="build only the image from a Dockerfile path", default=None
4946
)
50-
parser.add_argument(
51-
'--algorithm',
52-
metavar='NAME',
53-
help='build only the named algorithm image',
54-
default=None)
55-
parser.add_argument(
56-
'--dockerfile',
57-
metavar='PATH',
58-
help='build only the image from a Dockerfile path',
59-
default=None)
60-
parser.add_argument(
61-
'--build-arg',
62-
help='pass given args to all docker builds',
63-
nargs="+")
47+
parser.add_argument("--build-arg", help="pass given args to all docker builds", nargs="+")
6448
args = parser.parse_args()
6549

66-
print('Building base image...')
67-
68-
subprocess.check_call(
69-
'docker build \
70-
--rm -t %s -f %s .' % (docker_tag_base(), dockerfile_path_base()), shell=True)
50+
print("Building base image...")
7151

72-
print('Building end.')
52+
subprocess.check_call("docker build \
53+
--rm -t %s -f %s ." % (docker_tag_base(), dockerfile_path_base()), shell=True)
7354

55+
print("Building end.")

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
22

33
from os.path import dirname, abspath
4+
45
sys.path.append(dirname(dirname(abspath(__file__))))

tests/test_bench_runner.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
import logging
33
from vectordb_bench.interface import BenchMarkRunner
44
from vectordb_bench.models import (
5-
DB, IndexType, CaseType, TaskConfig, CaseConfig,
5+
DB,
6+
IndexType,
7+
CaseType,
8+
TaskConfig,
9+
CaseConfig,
610
)
711

812
log = logging.getLogger(__name__)
913

14+
1015
class TestBenchRunner:
1116
def test_get_results(self):
1217
runner = BenchMarkRunner()
@@ -17,7 +22,7 @@ def test_get_results(self):
1722
def test_performance_case_whole(self):
1823
runner = BenchMarkRunner()
1924

20-
task_config=TaskConfig(
25+
task_config = TaskConfig(
2126
db=DB.Milvus,
2227
db_config=DB.Milvus.config(),
2328
db_case_config=DB.Milvus.case_config_cls(index=IndexType.Flat)(),
@@ -32,7 +37,7 @@ def test_performance_case_whole(self):
3237
def test_performance_case_clean(self):
3338
runner = BenchMarkRunner()
3439

35-
task_config=TaskConfig(
40+
task_config = TaskConfig(
3641
db=DB.Milvus,
3742
db_config=DB.Milvus.config(),
3843
db_case_config=DB.Milvus.case_config_cls(index=IndexType.Flat)(),
@@ -44,17 +49,18 @@ def test_performance_case_clean(self):
4449
runner.stop_running()
4550

4651
def test_performance_case_no_error(self):
47-
task_config=TaskConfig(
52+
task_config = TaskConfig(
4853
db=DB.ZillizCloud,
4954
db_config=DB.ZillizCloud.config(uri="xxx", user="abc", password="1234"),
5055
db_case_config=DB.ZillizCloud.case_config_cls()(),
5156
case_config=CaseConfig(case_id=CaseType.PerformanceSZero),
5257
)
5358

5459
t = task_config.copy()
55-
d = t.json(exclude={'db_config': {'password', 'api_key'}})
60+
d = t.json(exclude={"db_config": {"password", "api_key"}})
5661
log.info(f"{d}")
5762

5863
import ujson
64+
5965
loads = ujson.loads(d)
6066
log.info(f"{loads}")

tests/test_chroma.py

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import chromadb
88

9-
109
log = logging.getLogger(__name__)
1110

1211
""" Tests for Chroma, assumes Chroma is running on localhost:8000,
@@ -19,13 +18,11 @@
1918
3. default port is 8000, default host is localhost"""
2019

2120

22-
23-
dict = {} #Assumes chroma is acception connections on localhost:8000
24-
dict['name'] = "chroma"
25-
dict['host'] = "localhost"
26-
dict['port'] = 8000
27-
dict['password'] = "chroma"
28-
21+
dict = {} # Assumes chroma is acception connections on localhost:8000
22+
dict["name"] = "chroma"
23+
dict["host"] = "localhost"
24+
dict["port"] = 8000
25+
dict["password"] = "chroma"
2926

3027

3128
class TestChroma:
@@ -34,7 +31,6 @@ def test_insert_and_search(self):
3431

3532
dbcls = DB.Chroma.init_cls
3633
dbConfig = DB.Chroma.config_cls
37-
3834

3935
dim = 16
4036
chrma = dbcls(
@@ -49,50 +45,37 @@ def test_insert_and_search(self):
4945
filter_value = 0.9
5046
embeddings = [[np.random.random() for _ in range(dim)] for _ in range(count)]
5147

52-
5348
# insert
5449
with chrma.init():
55-
#chrma.client.delete_collection("example2")
56-
assert (chrma.client.heartbeat() is not None), "chroma client is not connected"
50+
# chrma.client.delete_collection("example2")
51+
assert chrma.client.heartbeat() is not None, "chroma client is not connected"
5752
res = chrma.insert_embeddings(embeddings=embeddings, metadata=range(count))
5853
# bulk_insert return
59-
assert (
60-
res[0] == count
61-
), f"the return count of bulk insert ({res}) is not equal to count ({count})"
54+
assert res[0] == count, f"the return count of bulk insert ({res}) is not equal to count ({count})"
6255

6356
# count entries in chroma database
6457
countRes = chrma.collection.count()
65-
66-
assert (
67-
countRes == count
68-
), f"the return count of redis client ({countRes}) is not equal to count ({count})"
58+
59+
assert countRes == count, f"the return count of redis client ({countRes}) is not equal to count ({count})"
6960

7061
# search
7162
with chrma.init():
7263
test_id = np.random.randint(count)
73-
#log.info(f"test_id: {test_id}")
64+
# log.info(f"test_id: {test_id}")
7465
q = embeddings[test_id]
7566

7667
res = chrma.search_embedding(query=q, k=100)
7768
print(res)
78-
assert (
79-
res[0] == int(test_id)
80-
), f"the most nearest neighbor ({res[0]}) id is not test_id ({int(test_id)}"
81-
69+
assert res[0] == int(test_id), f"the most nearest neighbor ({res[0]}) id is not test_id ({int(test_id)}"
8270

8371
# search with filters, assumes filter format {id: int, metadata: >=int}
8472
with chrma.init():
8573
filter_value = int(count * filter_value)
8674
test_id = np.random.randint(filter_value, count)
8775
q = embeddings[test_id]
8876

89-
90-
res = chrma.search_embedding(
91-
query=q, k=100, filters={"id": filter_value}
92-
)
93-
assert (
94-
res[0] == int(test_id)
95-
), f"the most nearest neighbor ({res[0]}) id is not test_id ({test_id})"
77+
res = chrma.search_embedding(query=q, k=100, filters={"id": filter_value})
78+
assert res[0] == int(test_id), f"the most nearest neighbor ({res[0]}) id is not test_id ({test_id})"
9679
isFilter = True
9780
id_list = []
9881
for id in res:
@@ -101,5 +84,3 @@ def test_insert_and_search(self):
10184
isFilter = False
10285
break
10386
assert isFilter, f"Filter not working, id_list: {id_list}"
104-
105-

tests/test_data_source.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
log = logging.getLogger("vectordb_bench")
77

8+
89
class TestReader:
9-
@pytest.mark.parametrize("type_case", [
10-
(k, v) for k, v in type2case.items()
11-
])
10+
@pytest.mark.parametrize("type_case", [(k, v) for k, v in type2case.items()])
1211
def test_type_cases(self, type_case):
1312
self.per_case_test(type_case)
1413

15-
1614
def per_case_test(self, type_case):
1715
t, ca_cls = type_case
1816
ca = ca_cls()

tests/test_dataset.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from pydantic import ValidationError
55
from vectordb_bench.backend.data_source import DatasetSource
66

7-
87
log = logging.getLogger("vectordb_bench")
98

9+
1010
class TestDataSet:
1111
def test_iter_dataset(self):
1212
for ds in Dataset:
@@ -29,6 +29,7 @@ def test_iter_cohere(self):
2929
cohere_10m.prepare()
3030

3131
import time
32+
3233
before = time.time()
3334
for i in cohere_10m:
3435
log.debug(i.head(1))
@@ -40,9 +41,11 @@ def test_iter_cohere(self):
4041
def test_iter_laion(self):
4142
laion_100m = Dataset.LAION.manager(100_000_000)
4243
from vectordb_bench.backend.data_source import DatasetSource
44+
4345
laion_100m.prepare(source=DatasetSource.AliyunOSS)
4446

4547
import time
48+
4649
before = time.time()
4750
for i in laion_100m:
4851
log.debug(i.head(1))
@@ -74,4 +77,3 @@ def test_download_small(self):
7477
files=files,
7578
local_ds_root=openai_50k.data_dir,
7679
)
77-

tests/test_elasticsearch_cloud.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
)
77
import numpy as np
88

9-
109
log = logging.getLogger(__name__)
1110

1211
cloud_id = ""
@@ -41,9 +40,7 @@ def test_insert_and_search(self):
4140
with es.init():
4241
res = es.insert_embeddings(embeddings=embeddings, metadata=range(count))
4342
# bulk_insert return
44-
assert (
45-
res == count
46-
), f"the return count of bulk insert ({res}) is not equal to count ({count})"
43+
assert res == count, f"the return count of bulk insert ({res}) is not equal to count ({count})"
4744

4845
# indice_count return
4946
es.client.indices.refresh()
@@ -61,23 +58,17 @@ def test_insert_and_search(self):
6158

6259
res = es.search_embedding(query=q, k=100)
6360
log.info(f"search_results_id: {res}")
64-
assert (
65-
res[0] == test_id
66-
), f"the most nearest neighbor ({res[0]}) id is not test_id ({test_id})"
61+
assert res[0] == test_id, f"the most nearest neighbor ({res[0]}) id is not test_id ({test_id})"
6762

6863
# search with filters
6964
with es.init():
7065
test_id = np.random.randint(count * filter_rate, count)
7166
log.info(f"test_id: {test_id}")
7267
q = embeddings[test_id]
7368

74-
res = es.search_embedding(
75-
query=q, k=100, filters={"id": count * filter_rate}
76-
)
69+
res = es.search_embedding(query=q, k=100, filters={"id": count * filter_rate})
7770
log.info(f"search_results_id: {res}")
78-
assert (
79-
res[0] == test_id
80-
), f"the most nearest neighbor ({res[0]}) id is not test_id ({test_id})"
71+
assert res[0] == test_id, f"the most nearest neighbor ({res[0]}) id is not test_id ({test_id})"
8172
isFilter = True
8273
for id in res:
8374
if id < count * filter_rate:

tests/test_models.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import pytest
22
import logging
3-
from vectordb_bench.models import (
4-
TaskConfig, CaseConfig,
5-
CaseResult, TestResult,
6-
Metric, CaseType
7-
)
8-
from vectordb_bench.backend.clients import (
9-
DB,
10-
IndexType
11-
)
3+
from vectordb_bench.models import TaskConfig, CaseConfig, CaseResult, TestResult, Metric, CaseType
4+
from vectordb_bench.backend.clients import DB, IndexType
125

136
from vectordb_bench import config
147

15-
168
log = logging.getLogger("vectordb_bench")
179

1810

@@ -33,7 +25,7 @@ def test_test_result(self):
3325
test_result.flush()
3426

3527
with pytest.raises(ValueError):
36-
result = TestResult.read_file('nosuchfile.json')
28+
result = TestResult.read_file("nosuchfile.json")
3729

3830
def test_test_result_read_write(self):
3931
result_dir = config.RESULTS_LOCAL_DIR

0 commit comments

Comments
 (0)