forked from surister/cratedb-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (31 loc) · 922 Bytes
/
main.py
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
33
34
35
36
37
import os
from openai import OpenAI
from crate import client as crate
from embeddings.openai import get_embedding
from embeddings.io import insert_vectors_to_cratedb, get_indexes, knn_search
token = os.getenv('OPENAITOKEN')
client = OpenAI(api_key=token)
connection = crate.connect('http://192.168.88.251:4200')
indexes = get_indexes(connection, 'fs_search5')
query = 'knn search vectors'
embedding = get_embedding(query, token=token)
# Should probably bulk create.
for i in indexes:
print(f'Creating indexes for {i}')
response = client.embeddings.create(
input=i[1],
model="text-embedding-3-large",
dimensions=2048
)
print('Got')
print(response.data)
print('Inserting to CrateDB')
insert_vectors_to_cratedb(
connection,
'fs_vec_big2',
'fs_search_id',
'xs',
[
(i[0], response.data[0].embedding),
]
)