|
354 | 354 | " if self.pool == None:\n",
|
355 | 355 | " async def init(conn):\n",
|
356 | 356 | " 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", |
357 | 364 | " self.pool = await asyncpg.create_pool(dsn=self.service_url, init=init)\n",
|
358 | 365 | " return self.pool.acquire()\n",
|
359 | 366 | "\n",
|
|
694 | 701 | "rec = await vec.search([1.0, 2.0], k=4, filter=[{\"key_1\":\"val_1\"}, {\"key2\":\"val2\"}, {\"no such key\": \"no such val\"}])\n",
|
695 | 702 | "assert len(rec) == 2\n",
|
696 | 703 | "\n",
|
| 704 | + "assert isinstance(rec[0][SEARCH_RESULT_METADATA_IDX], dict)\n", |
| 705 | + "\n", |
697 | 706 | "try:\n",
|
698 | 707 | " # can't upsert using both keys and dictionaries\n",
|
699 | 708 | " await vec.upsert([ \\\n",
|
|
1212 | 1221 | "rec = vec.search([1.0, 2.0], filter={\"key_1\":\"val_1\", \"key_2\":\"val_2\"})\n",
|
1213 | 1222 | "assert rec[0][SEARCH_RESULT_CONTENTS_IDX] == 'the brown fox'\n",
|
1214 | 1223 | "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", |
1215 | 1225 | "assert rec[0][SEARCH_RESULT_DISTANCE_IDX] == 0.0009438353921149556\n",
|
1216 | 1226 | "\n",
|
1217 | 1227 | "vec.delete_all()\n",
|
|
0 commit comments