Skip to content

Commit 7ec7ffc

Browse files
committed
Polishing
1 parent f3e4873 commit 7ec7ffc

11 files changed

Lines changed: 1241 additions & 140 deletions

File tree

README.md

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# python-vector
1+
# Timescale-vector
22

33
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
44

@@ -8,15 +8,76 @@ documentation.
88
## Install
99

1010
``` sh
11-
pip install python_vector
11+
pip install timescale_vector
1212
```
1313

1414
## How to use
1515

16-
Fill me in please! Don’t forget code examples:
16+
Load up your postgres credentials. Safest way is with a .env file:
1717

1818
``` python
19-
1+1
19+
from dotenv import load_dotenv, find_dotenv
20+
import os
2021
```
2122

22-
2
23+
``` python
24+
_ = load_dotenv(find_dotenv())
25+
connection_string = os.environ['PG_CONNECTION_STRING']
26+
```
27+
28+
Next, create the client.
29+
30+
This takes three arguments: - A connection string - The name of the
31+
collection - Number of dimensions
32+
33+
``` python
34+
vec = client.Async(connection_string, "my_data", 2)
35+
```
36+
37+
Next, create the tables for the collection:
38+
39+
``` python
40+
await vec.create_tables()
41+
```
42+
43+
Next, insert some data. The data record contains: - A uuid to uniquely
44+
identify the emedding - A json blob of metadata about the embedding -
45+
The text the embedding represents - The embedding itself
46+
47+
Because this data already includes uuids we only allow upserts
48+
49+
``` python
50+
import uuid
51+
```
52+
53+
``` python
54+
await vec.upsert([\
55+
(uuid.uuid4(), '''{"animal":"fox"}''', "the brown fox", [1.0,1.3]),\
56+
(uuid.uuid4(), '''{"animal":"fox", "action":"jump"}''', "jumped over the", [1.0,10.8]),\
57+
])
58+
```
59+
60+
Now you can query for similar items:
61+
62+
``` python
63+
await vec.search([1.0, 9.0])
64+
```
65+
66+
[<Record id=UUID('25df4eea-a17f-42c2-9426-d09b8ca40e32') metadata='{"action": "jump", "animal": "fox"}' contents='jumped over the' embedding=array([ 1. , 10.8], dtype=float32) ?column?=0.00016793422934946456>,
67+
<Record id=UUID('605e3ff5-3503-4006-826f-c84ecbb535d4') metadata='{"animal": "fox"}' contents='the brown fox' embedding=array([1. , 1.3], dtype=float32) ?column?=0.14489260377438218>]
68+
69+
You can specify the number of records to return.
70+
71+
``` python
72+
await vec.search([1.0, 9.0], k=1)
73+
```
74+
75+
[<Record id=UUID('25df4eea-a17f-42c2-9426-d09b8ca40e32') metadata='{"action": "jump", "animal": "fox"}' contents='jumped over the' embedding=array([ 1. , 10.8], dtype=float32) ?column?=0.00016793422934946456>]
76+
77+
You can also specify a filter on the metadata as a simple dictionary
78+
79+
``` python
80+
await vec.search([1.0, 9.0], k=1, filter={"action": "jump"})
81+
```
82+
83+
[<Record id=UUID('25df4eea-a17f-42c2-9426-d09b8ca40e32') metadata='{"action": "jump", "animal": "fox"}' contents='jumped over the' embedding=array([ 1. , 10.8], dtype=float32) ?column?=0.00016793422934946456>]

0 commit comments

Comments
 (0)