Skip to content

Commit df70976

Browse files
docs: update docs/vector_store.ipynb (#472)
* fix(docs): update docs/vector_store.ipynb * chore: format notebook doc --------- Co-authored-by: Averi Kitsch <[email protected]>
1 parent d5dd585 commit df70976

File tree

1 file changed

+52
-33
lines changed

1 file changed

+52
-33
lines changed

docs/vector_store.ipynb

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"outputs": [],
5555
"source": [
56-
"%pip install --upgrade --quiet langchain-google-alloydb-pg langchain-google-vertexai google-cloud-alloydb-connector[pg8000]"
56+
"%pip install --upgrade --quiet langchain-google-alloydb-pg langchain-google-vertexai"
5757
]
5858
},
5959
{
@@ -336,9 +336,7 @@
336336
"source": [
337337
"from langchain_google_vertexai import VertexAIEmbeddings\n",
338338
"\n",
339-
"embedding = VertexAIEmbeddings(\n",
340-
" model_name=\"textembedding-gecko@latest\", project=PROJECT_ID\n",
341-
")"
339+
"embedding = VertexAIEmbeddings(model_name=\"text-embedding-005\", project=PROJECT_ID)"
342340
]
343341
},
344342
{
@@ -408,7 +406,7 @@
408406
" engine=engine,\n",
409407
" table_name=TABLE_NAME,\n",
410408
" # schema_name=SCHEMA_NAME,\n",
411-
" embedding_service=embedding,\n",
409+
" embedding=embedding,\n",
412410
")"
413411
]
414412
},
@@ -553,7 +551,7 @@
553551
"\n",
554552
"VECTOR_SIZE = 768 # Replace with the vector size of your embedding model\n",
555553
"index = ScaNNIndex()\n",
556-
"await store.set_maintenance_work_mem(index.num_leaves, VECTOR_SIZE)\n",
554+
"await store.aset_maintenance_work_mem(index.num_leaves, VECTOR_SIZE)\n",
557555
"await store.aapply_vector_index(index)"
558556
]
559557
},
@@ -818,8 +816,6 @@
818816
"metadata": {},
819817
"outputs": [],
820818
"source": [
821-
"import uuid\n",
822-
"\n",
823819
"docs = await custom_store.asimilarity_search(query, filter={\"price_usd\": {\"$gte\": 100}})\n",
824820
"\n",
825821
"print(docs)"
@@ -840,8 +836,6 @@
840836
"metadata": {},
841837
"outputs": [],
842838
"source": [
843-
"import uuid\n",
844-
"\n",
845839
"docs = await custom_store.asimilarity_search(query, filter=\"price_usd > 100\")\n",
846840
"\n",
847841
"print(docs)"
@@ -860,23 +854,15 @@
860854
"source": [
861855
"#### For v0.13.0+\n",
862856
"\n",
863-
"**Important Update:** Support for string filters has been deprecated. To filter data on the JSON metadata, you must first create a new column for the specific key you wish to filter on. Use the following SQL command to set this up."
864-
]
865-
},
866-
{
867-
"cell_type": "code",
868-
"execution_count": null,
869-
"metadata": {
870-
"vscode": {
871-
"languageId": "sql"
872-
}
873-
},
874-
"outputs": [],
875-
"source": [
876-
"ALTER TABLE vectorstore_table ADD COLUMN category VARCHAR;\n",
877-
"UPDATE vectorstore_table\n",
857+
"**Important Update:** Support for string filters has been deprecated. To filter data on the JSON metadata, you must first create a new column for the specific key you wish to filter on. Use the following SQL command to set this up.\n",
858+
"\n",
859+
"```\n",
860+
"ALTER TABLE products ADD COLUMN category_from_json VARCHAR;\n",
861+
"\n",
862+
"UPDATE products\n",
878863
"SET\n",
879-
" category = metadata ->> 'category';"
864+
" category_from_json = metadata ->> 'category';\n",
865+
"```"
880866
]
881867
},
882868
{
@@ -892,9 +878,34 @@
892878
"metadata": {},
893879
"outputs": [],
894880
"source": [
895-
"import uuid\n",
881+
"TABLE_NAME = \"products\"\n",
882+
"# SCHEMA_NAME = \"my_schema\"\n",
883+
"\n",
884+
"# Reinitialize AlloyDBVectorStore with category_from_json\n",
885+
"custom_store = await AlloyDBVectorStore.create(\n",
886+
" engine=engine,\n",
887+
" table_name=TABLE_NAME,\n",
888+
" # schema_name=SCHEMA_NAME,\n",
889+
" embedding_service=embedding,\n",
890+
" # Connect to existing VectorStore by customizing below column names\n",
891+
" id_column=\"product_id\",\n",
892+
" content_column=\"description\",\n",
893+
" embedding_column=\"embed\",\n",
894+
" metadata_columns=[\n",
895+
" \"name\",\n",
896+
" \"category\",\n",
897+
" \"category_from_json\",\n",
898+
" \"price_usd\",\n",
899+
" \"quantity\",\n",
900+
" \"sku\",\n",
901+
" \"image_url\",\n",
902+
" ],\n",
903+
" metadata_json_column=\"metadata\",\n",
904+
")\n",
896905
"\n",
897-
"docs = await custom_store.asimilarity_search(query, filter={\"category\": \"Electronics\"})\n",
906+
"docs = await custom_store.asimilarity_search(\n",
907+
" query, filter={\"category_from_json\": \"Electronics\"}\n",
908+
")\n",
898909
"\n",
899910
"print(docs)"
900911
]
@@ -915,8 +926,6 @@
915926
"metadata": {},
916927
"outputs": [],
917928
"source": [
918-
"import uuid\n",
919-
"\n",
920929
"docs = await custom_store.asimilarity_search(\n",
921930
" query, filter=\"metadata->>'category' = 'Electronics'\"\n",
922931
")\n",
@@ -1069,6 +1078,8 @@
10691078
"metadata": {},
10701079
"outputs": [],
10711080
"source": [
1081+
"from langchain_google_alloydb_pg import Column\n",
1082+
"\n",
10721083
"TABLE_NAME = \"hybrid_search_products\"\n",
10731084
"\n",
10741085
"await engine.ainit_vectorstore_table(\n",
@@ -1078,7 +1089,14 @@
10781089
" id_column=\"product_id\",\n",
10791090
" content_column=\"description\",\n",
10801091
" embedding_column=\"embed\",\n",
1081-
" metadata_columns=[\"name\", \"category\", \"price_usd\", \"quantity\", \"sku\", \"image_url\"],\n",
1092+
" metadata_columns=[\n",
1093+
" Column(\"name\", \"VARCHAR(255)\"),\n",
1094+
" Column(\"category\", \"VARCHAR(255)\"),\n",
1095+
" Column(\"price_usd\", \"DECIMAL(10, 2)\"),\n",
1096+
" Column(\"quantity\", \"INTEGER\"),\n",
1097+
" Column(\"sku\", \"VARCHAR(255)\"),\n",
1098+
" Column(\"image_url\", \"VARCHAR(255)\"),\n",
1099+
" ],\n",
10821100
" metadata_json_column=\"metadata\",\n",
10831101
" hybrid_search_config=hybrid_search_config,\n",
10841102
" store_metadata=True,\n",
@@ -1212,7 +1230,8 @@
12121230
"toc_visible": true
12131231
},
12141232
"kernelspec": {
1215-
"display_name": "Python 3",
1233+
"display_name": "venv (3.13.7)",
1234+
"language": "python",
12161235
"name": "python3"
12171236
},
12181237
"language_info": {
@@ -1225,7 +1244,7 @@
12251244
"name": "python",
12261245
"nbconvert_exporter": "python",
12271246
"pygments_lexer": "ipython3",
1228-
"version": "3.12.3"
1247+
"version": "3.13.7"
12291248
}
12301249
},
12311250
"nbformat": 4,

0 commit comments

Comments
 (0)