66import numpy as np
77import chromadb
88
9-
109log = logging .getLogger (__name__ )
1110
1211""" Tests for Chroma, assumes Chroma is running on localhost:8000,
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
3128class 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-
0 commit comments