Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/singlestoredb/tests/test_vectorstore.py
469 views
1
import os
2
import unittest
3
4
from vectorstore import VectorDB
5
6
import singlestoredb as s2
7
from . import utils
8
9
10
class TestVectorDB(unittest.TestCase):
11
12
driver = s2
13
14
dbname: str = ''
15
dbexisted: bool = False
16
17
@classmethod
18
def setUpClass(cls) -> None:
19
sql_file = os.path.join(os.path.dirname(__file__), 'empty.sql')
20
cls.dbname, cls.dbexisted = utils.load_sql(sql_file) # type: ignore
21
22
@classmethod
23
def tearDownClass(cls) -> None:
24
if not cls.dbexisted:
25
utils.drop_database(cls.dbname) # type: ignore
26
27
def test_vectordb_from_params(self) -> None:
28
db: VectorDB = s2.vector_db(database=type(self).dbname)
29
index = db.create_index(
30
name='test_index', dimension=3,
31
tags={'name': 'test_tag'},
32
)
33
assert index.name == 'test_index'
34
assert index.dimension == 3
35
assert index.tags == {'name': 'test_tag'}
36
assert db.has_index('test_index')
37
38
def test_vectordb_from_connection(self) -> None:
39
with s2.connect(database=type(self).dbname) as conn:
40
db: VectorDB = conn.vector_db
41
index = db.create_index(
42
name='test_index_1',
43
dimension=4, tags={'name': 'test_tag'},
44
)
45
assert index.name == 'test_index_1'
46
assert index.dimension == 4
47
assert index.tags == {'name': 'test_tag'}
48
assert db.has_index('test_index_1')
49
50
db2: VectorDB = conn.vector_db
51
assert db2.has_index('test_index_1')
52
53