File size: 802 Bytes
c1a5559
 
 
6ecf1c3
c1a5559
 
 
6ecf1c3
c1a5559
02cd7f1
 
 
 
 
c1a5559
02cd7f1
 
 
 
 
 
c1a5559
02cd7f1
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os

from dotenv import load_dotenv
import kdbai_client as kdbai

load_dotenv()

session = kdbai.Session(api_key=os.getenv("KDBAI_API_KEY"), endpoint=os.getenv("KDBAI_ENDPOINT"))

schema = [
    {"name": "document_id", "type": "bytes"},
    {"name": "text", "type": "bytes"},
    {"name": "embedding", "type": "float32s"},
]

indexFlat = {
    "name": "flat_index",
    "type": "flat",
    "column": "embedding",
    "params": {"dims": 768, "metric": "CS"},
}

KDBAI_TABLE_NAME = "daily_med_v2"
database = session.database("default")
# First ensure the table does not already exist
for table in database.tables:
    if table.name == KDBAI_TABLE_NAME:
        ## table.drop()
        print("exist")
        break
table = database.create_table(KDBAI_TABLE_NAME, schema=schema, indexes=[indexFlat])