Skip to content

Commit 138bbff

Browse files
committed
make jsonb decode to a dict in the async client
1 parent 5a68262 commit 138bbff

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

nbs/00_vector.ipynb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@
354354
" if self.pool == None:\n",
355355
" async def init(conn):\n",
356356
" await register_vector(conn)\n",
357+
" #decode to a dict, but accept a string as input in upsert\n",
358+
" await conn.set_type_codec(\n",
359+
" 'jsonb',\n",
360+
" encoder=str,\n",
361+
" decoder=json.loads,\n",
362+
" schema='pg_catalog')\n",
363+
"\n",
357364
" self.pool = await asyncpg.create_pool(dsn=self.service_url, init=init)\n",
358365
" return self.pool.acquire()\n",
359366
"\n",
@@ -694,6 +701,8 @@
694701
"rec = await vec.search([1.0, 2.0], k=4, filter=[{\"key_1\":\"val_1\"}, {\"key2\":\"val2\"}, {\"no such key\": \"no such val\"}])\n",
695702
"assert len(rec) == 2\n",
696703
"\n",
704+
"assert isinstance(rec[0][SEARCH_RESULT_METADATA_IDX], dict)\n",
705+
"\n",
697706
"try:\n",
698707
" # can't upsert using both keys and dictionaries\n",
699708
" await vec.upsert([ \\\n",
@@ -1212,6 +1221,7 @@
12121221
"rec = vec.search([1.0, 2.0], filter={\"key_1\":\"val_1\", \"key_2\":\"val_2\"})\n",
12131222
"assert rec[0][SEARCH_RESULT_CONTENTS_IDX] == 'the brown fox'\n",
12141223
"assert rec[0][SEARCH_RESULT_METADATA_IDX] == {'key_1': 'val_1', 'key_2': 'val_2'}\n",
1224+
"assert isinstance(rec[0][SEARCH_RESULT_METADATA_IDX], dict)\n",
12151225
"assert rec[0][SEARCH_RESULT_DISTANCE_IDX] == 0.0009438353921149556\n",
12161226
"\n",
12171227
"vec.delete_all()\n",

timescale_vector/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ async def connect(self):
219219
if self.pool == None:
220220
async def init(conn):
221221
await register_vector(conn)
222+
#decode to a dict, but accept a string as input in upsert
223+
await conn.set_type_codec(
224+
'jsonb',
225+
encoder=str,
226+
decoder=json.loads,
227+
schema='pg_catalog')
228+
222229
self.pool = await asyncpg.create_pool(dsn=self.service_url, init=init)
223230
return self.pool.acquire()
224231

0 commit comments

Comments
 (0)