-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimple.py
More file actions
49 lines (38 loc) · 1.17 KB
/
simple.py
File metadata and controls
49 lines (38 loc) · 1.17 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
import asyncio
from typing import Optional
from vechord.embedding import GeminiDenseEmbedding
from vechord.registry import VechordRegistry
from vechord.spec import PrimaryKeyAutoIncrease, Table, Vector
DenseVector = Vector[3072]
class Document(Table, kw_only=True):
uid: Optional[PrimaryKeyAutoIncrease] = None
title: str = ""
text: str
vec: DenseVector
async def main():
async with (
VechordRegistry(
"simple",
"postgresql://postgres:postgres@172.17.0.1:5432/",
tables=[Document],
) as vr,
GeminiDenseEmbedding() as emb,
):
# add a document
text = "my personal long note"
doc = Document(
title="note", text=text, vec=DenseVector(await emb.vectorize_chunk(text))
)
await vr.insert(doc)
# load
docs = await vr.select_by(Document.partial_init(), limit=1)
print(docs)
# query
res = await vr.search_by_vector(
Document, await emb.vectorize_query("note"), topk=1
)
print(res)
# drop
await vr.clear_storage(drop_table=True)
if __name__ == "__main__":
asyncio.run(main())