Skip to content

Commit e1837df

Browse files
committed
Doc fixes
1 parent a892636 commit e1837df

File tree

2 files changed

+82
-83
lines changed

2 files changed

+82
-83
lines changed

nbs/00_vector.ipynb

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@
5050
"service_url = os.environ['TIMESCALE_SERVICE_URL']"
5151
]
5252
},
53-
{
54-
"attachments": {},
55-
"cell_type": "markdown",
56-
"metadata": {},
57-
"source": [
58-
"# Query Builder"
59-
]
60-
},
6153
{
6254
"cell_type": "code",
6355
"execution_count": null,
@@ -85,48 +77,30 @@
8577
"outputs": [],
8678
"source": [
8779
"#| export\n",
88-
"\n",
89-
"SEARCH_RESULT_ID_IDX = 0\n",
90-
"SEARCH_RESULT_METADATA_IDX = 1\n",
91-
"SEARCH_RESULT_CONTENTS_IDX = 2\n",
92-
"SEARCH_RESULT_EMBEDDING_IDX = 3\n",
93-
"SEARCH_RESULT_DISTANCE_IDX = 4"
94-
]
95-
},
96-
{
97-
"cell_type": "code",
98-
"execution_count": null,
99-
"metadata": {},
100-
"outputs": [],
101-
"source": [
102-
"#| export\n",
103-
"\n",
10480
"#copied from Cassandra: https://docs.datastax.com/en/drivers/python/3.2/_modules/cassandra/util.html#uuid_from_time\n",
105-
"def uuid_from_time(time_arg=None, node=None, clock_seq=None):\n",
106-
" if time_arg is None:\n",
107-
" return uuid.uuid1(node, clock_seq)\n",
81+
"def uuid_from_time(time_arg = None, node=None, clock_seq=None):\n",
10882
" \"\"\"\n",
109-
" Converts a datetime or timestamp to a type 1 :class:`uuid.UUID`.\n",
110-
"\n",
111-
" :param time_arg:\n",
112-
" The time to use for the timestamp portion of the UUID.\n",
113-
" This can either be a :class:`datetime` object or a timestamp\n",
114-
" in seconds (as returned from :meth:`time.time()`).\n",
115-
" :type datetime: :class:`datetime` or timestamp\n",
116-
"\n",
117-
" :param node:\n",
118-
" None integer for the UUID (up to 48 bits). If not specified, this\n",
119-
" field is randomized.\n",
120-
" :type node: long\n",
121-
"\n",
122-
" :param clock_seq:\n",
123-
" Clock sequence field for the UUID (up to 14 bits). If not specified,\n",
124-
" a random sequence is generated.\n",
125-
" :type clock_seq: int\n",
126-
"\n",
127-
" :rtype: :class:`uuid.UUID`\n",
128-
"\n",
83+
" Converts a datetime or timestamp to a type 1 `uuid.UUID`.\n",
84+
"\n",
85+
" Parameters\n",
86+
" ----------\n",
87+
" time_arg\n",
88+
" The time to use for the timestamp portion of the UUID.\n",
89+
" This can either be a `datetime` object or a timestamp in seconds\n",
90+
" (as returned from `time.time()`).\n",
91+
" node\n",
92+
" Bytes for the UUID (up to 48 bits). If not specified, this\n",
93+
" field is randomized.\n",
94+
" clock_seq\n",
95+
" Clock sequence field for the UUID (up to 14 bits). If not specified,\n",
96+
" a random sequence is generated.\n",
97+
"\n",
98+
" Returns\n",
99+
" -------\n",
100+
" uuid.UUID: For the given time, node, and clock sequence\n",
129101
" \"\"\"\n",
102+
" if time_arg is None:\n",
103+
" return uuid.uuid1(node, clock_seq)\n",
130104
" if hasattr(time_arg, 'utctimetuple'):\n",
131105
" seconds = int(calendar.timegm(time_arg.utctimetuple()))\n",
132106
" microseconds = (seconds * 1e6) + time_arg.time().microsecond\n",
@@ -157,6 +131,29 @@
157131
" clock_seq_hi_variant, clock_seq_low, node), version=1)"
158132
]
159133
},
134+
{
135+
"attachments": {},
136+
"cell_type": "markdown",
137+
"metadata": {},
138+
"source": [
139+
"# Query Builder"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"#| export\n",
149+
"\n",
150+
"SEARCH_RESULT_ID_IDX = 0\n",
151+
"SEARCH_RESULT_METADATA_IDX = 1\n",
152+
"SEARCH_RESULT_CONTENTS_IDX = 2\n",
153+
"SEARCH_RESULT_EMBEDDING_IDX = 3\n",
154+
"SEARCH_RESULT_DISTANCE_IDX = 4"
155+
]
156+
},
160157
{
161158
"cell_type": "code",
162159
"execution_count": null,
@@ -166,6 +163,9 @@
166163
"#| export\n",
167164
"class UUIDTimeRange:\n",
168165
" def __init__(self, start_date: Optional[datetime] = None, end_date: Optional[datetime] = None, start_inclusive=True, end_inclusive=False):\n",
166+
" \"\"\"\n",
167+
" A UUIDTimeRange is a time range predicate on the UUID Version 1 timestamps.\n",
168+
" \"\"\"\n",
169169
" if start_date is not None and end_date is not None:\n",
170170
" if start_date > end_date:\n",
171171
" raise Exception(\"start_date must be before end_date\")\n",
@@ -1278,8 +1278,7 @@
12781278
" raised = True\n",
12791279
"assert raised\n",
12801280
"\n",
1281-
"import datetime\n",
1282-
"specific_datetime = datetime.datetime(2018, 8, 10, 15, 30, 0)\n",
1281+
"specific_datetime = datetime(2018, 8, 10, 15, 30, 0)\n",
12831282
"await vec.upsert([\n",
12841283
" # current time\n",
12851284
" (uuid.uuid1(), {\"key\": \"val\"}, \"the brown fox\", [1.0, 1.2]),\n",
@@ -1969,8 +1968,7 @@
19691968
" raised = True\n",
19701969
"assert raised\n",
19711970
"\n",
1972-
"import datetime\n",
1973-
"specific_datetime = datetime.datetime(2018, 8, 10, 15, 30, 0)\n",
1971+
"specific_datetime = datetime(2018, 8, 10, 15, 30, 0)\n",
19741972
"vec.upsert([\n",
19751973
" # current time\n",
19761974
" (uuid.uuid1(), {\"key\": \"val\"}, \"the brown fox\", [1.0, 1.2]),\n",

timescale_vector/client.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'SEARCH_RESULT_DISTANCE_IDX', 'uuid_from_time', 'UUIDTimeRange', 'Predicates', 'QueryBuilder', 'Async',
66
'Sync']
77

8-
# %% ../nbs/00_vector.ipynb 6
8+
# %% ../nbs/00_vector.ipynb 5
99
import asyncpg
1010
import uuid
1111
from pgvector.asyncpg import register_vector
@@ -18,40 +18,31 @@
1818
from datetime import datetime
1919
import calendar
2020

21-
# %% ../nbs/00_vector.ipynb 7
22-
SEARCH_RESULT_ID_IDX = 0
23-
SEARCH_RESULT_METADATA_IDX = 1
24-
SEARCH_RESULT_CONTENTS_IDX = 2
25-
SEARCH_RESULT_EMBEDDING_IDX = 3
26-
SEARCH_RESULT_DISTANCE_IDX = 4
27-
28-
# %% ../nbs/00_vector.ipynb 8
21+
# %% ../nbs/00_vector.ipynb 6
2922
#copied from Cassandra: https://docs.datastax.com/en/drivers/python/3.2/_modules/cassandra/util.html#uuid_from_time
30-
def uuid_from_time(time_arg=None, node=None, clock_seq=None):
31-
if time_arg is None:
32-
return uuid.uuid1(node, clock_seq)
23+
def uuid_from_time(time_arg = None, node=None, clock_seq=None):
3324
"""
34-
Converts a datetime or timestamp to a type 1 :class:`uuid.UUID`.
35-
36-
:param time_arg:
37-
The time to use for the timestamp portion of the UUID.
38-
This can either be a :class:`datetime` object or a timestamp
39-
in seconds (as returned from :meth:`time.time()`).
40-
:type datetime: :class:`datetime` or timestamp
41-
42-
:param node:
43-
None integer for the UUID (up to 48 bits). If not specified, this
44-
field is randomized.
45-
:type node: long
46-
47-
:param clock_seq:
48-
Clock sequence field for the UUID (up to 14 bits). If not specified,
49-
a random sequence is generated.
50-
:type clock_seq: int
51-
52-
:rtype: :class:`uuid.UUID`
53-
25+
Converts a datetime or timestamp to a type 1 `uuid.UUID`.
26+
27+
Parameters
28+
----------
29+
time_arg
30+
The time to use for the timestamp portion of the UUID.
31+
This can either be a `datetime` object or a timestamp in seconds
32+
(as returned from `time.time()`).
33+
node
34+
Bytes for the UUID (up to 48 bits). If not specified, this
35+
field is randomized.
36+
clock_seq
37+
Clock sequence field for the UUID (up to 14 bits). If not specified,
38+
a random sequence is generated.
39+
40+
Returns
41+
-------
42+
uuid.UUID: For the given time, node, and clock sequence
5443
"""
44+
if time_arg is None:
45+
return uuid.uuid1(node, clock_seq)
5546
if hasattr(time_arg, 'utctimetuple'):
5647
seconds = int(calendar.timegm(time_arg.utctimetuple()))
5748
microseconds = (seconds * 1e6) + time_arg.time().microsecond
@@ -81,9 +72,19 @@ def uuid_from_time(time_arg=None, node=None, clock_seq=None):
8172
return uuid.UUID(fields=(time_low, time_mid, time_hi_version,
8273
clock_seq_hi_variant, clock_seq_low, node), version=1)
8374

75+
# %% ../nbs/00_vector.ipynb 8
76+
SEARCH_RESULT_ID_IDX = 0
77+
SEARCH_RESULT_METADATA_IDX = 1
78+
SEARCH_RESULT_CONTENTS_IDX = 2
79+
SEARCH_RESULT_EMBEDDING_IDX = 3
80+
SEARCH_RESULT_DISTANCE_IDX = 4
81+
8482
# %% ../nbs/00_vector.ipynb 9
8583
class UUIDTimeRange:
8684
def __init__(self, start_date: Optional[datetime] = None, end_date: Optional[datetime] = None, start_inclusive=True, end_inclusive=False):
85+
"""
86+
A UUIDTimeRange is a time range predicate on the UUID Version 1 timestamps.
87+
"""
8788
if start_date is not None and end_date is not None:
8889
if start_date > end_date:
8990
raise Exception("start_date must be before end_date")

0 commit comments

Comments
 (0)