Skip to content

Commit 7ef9335

Browse files
authored
docs: Update sample python notebooks to reflect the support for custom schema. (#204)
Specifying custom database schema names is now supported by all library methods. This commit highlights the same in the python notebooks.
1 parent ce7d0cc commit 7ef9335

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

docs/chat_message_history.ipynb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@
287287
"engine.init_chat_history_table(table_name=TABLE_NAME)"
288288
]
289289
},
290+
{
291+
"cell_type": "markdown",
292+
"id": "345b76b8",
293+
"metadata": {},
294+
"source": [
295+
"#### Optional Tip: 💡\n",
296+
"You can also specify a schema name by passing `schema_name` wherever you pass `table_name`. Eg:\n",
297+
"\n",
298+
"```python\n",
299+
"SCHEMA_NAME=\"my_schema\"\n",
300+
"\n",
301+
"engine.init_chat_history_table(\n",
302+
" table_name=TABLE_NAME,\n",
303+
" schema_name=SCHEMA_NAME # Default: \"public\"\n",
304+
")\n",
305+
"```"
306+
]
307+
},
290308
{
291309
"cell_type": "markdown",
292310
"id": "zSYQTYf3UfOi",
@@ -300,7 +318,8 @@
300318
"\n",
301319
"1. `engine` - An instance of a `PostgresEngine` engine.\n",
302320
"1. `session_id` - A unique identifier string that specifies an id for the session.\n",
303-
"1. `table_name` : The name of the table within the Cloud SQL database to store the chat message history."
321+
"1. `table_name` : The name of the table within the Cloud SQL database to store the chat message history.\n",
322+
"1. `schema_name` : The name of the database schema containing the chat message history table."
304323
]
305324
},
306325
{
@@ -315,7 +334,10 @@
315334
"from langchain_google_cloud_sql_pg import PostgresChatMessageHistory\n",
316335
"\n",
317336
"history = PostgresChatMessageHistory.create_sync(\n",
318-
" engine, session_id=\"test_session\", table_name=TABLE_NAME\n",
337+
" engine,\n",
338+
" session_id=\"test_session\",\n",
339+
" table_name=TABLE_NAME,\n",
340+
" # schema_name=SCHEMA_NAME,\n",
319341
")\n",
320342
"history.add_user_message(\"hi!\")\n",
321343
"history.add_ai_message(\"whats up?\")"
@@ -456,6 +478,7 @@
456478
" engine,\n",
457479
" session_id=session_id,\n",
458480
" table_name=TABLE_NAME,\n",
481+
" # schema_name=SCHEMA_NAME,\n",
459482
" ),\n",
460483
" input_messages_key=\"question\",\n",
461484
" history_messages_key=\"history\",\n",

docs/document_loader.ipynb

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@
257257
")"
258258
]
259259
},
260+
{
261+
"cell_type": "markdown",
262+
"metadata": {},
263+
"source": [
264+
"#### Optional Tip: 💡\n",
265+
"You can also specify a schema name by passing `schema_name` wherever you pass `table_name`. Eg:\n",
266+
"\n",
267+
"```python\n",
268+
"SCHEMA_NAME=\"my_schema\"\n",
269+
"\n",
270+
"await engine.ainit_document_table(\n",
271+
" table_name=TABLE_NAME,\n",
272+
" schema_name=SCHEMA_NAME # Default: \"public\"\n",
273+
" \n",
274+
" ...\n",
275+
")\n",
276+
"```"
277+
]
278+
},
260279
{
261280
"cell_type": "markdown",
262281
"metadata": {
@@ -277,7 +296,11 @@
277296
"from langchain_google_cloud_sql_pg import PostgresLoader\n",
278297
"\n",
279298
"# Creating a basic PostgreSQL object\n",
280-
"loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)"
299+
"loader = await PostgresLoader.create(\n",
300+
" engine,\n",
301+
" table_name=TABLE_NAME,\n",
302+
" # schema_name=SCHEMA_NAME,\n",
303+
")"
281304
]
282305
},
283306
{
@@ -304,7 +327,11 @@
304327
"from langchain_google_cloud_sql_pg import PostgresLoader\n",
305328
"\n",
306329
"# Creating a basic PostgresLoader object\n",
307-
"loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)\n",
330+
"loader = await PostgresLoader.create(\n",
331+
" engine,\n",
332+
" table_name=TABLE_NAME,\n",
333+
" # schema_name=SCHEMA_NAME,\n",
334+
")\n",
308335
"\n",
309336
"docs = await loader.aload()\n",
310337
"print(docs)"
@@ -328,6 +355,7 @@
328355
"loader = await PostgresLoader.create(\n",
329356
" engine,\n",
330357
" table_name=TABLE_NAME,\n",
358+
" # schema_name=SCHEMA_NAME,\n",
331359
" content_columns=[\"product_name\"], # Optional\n",
332360
" metadata_columns=[\"id\"], # Optional\n",
333361
")\n",
@@ -356,6 +384,7 @@
356384
"loader = await PostgresLoader.create(\n",
357385
" engine,\n",
358386
" table_name=TABLE_NAME,\n",
387+
" # schema_name=SCHEMA_NAME,\n",
359388
" content_columns=[\"product_name\", \"description\"],\n",
360389
" format=\"YAML\",\n",
361390
")\n",
@@ -383,6 +412,7 @@
383412
"saver = await PostgresDocumentSaver.create(\n",
384413
" engine,\n",
385414
" table_name=TABLE_NAME,\n",
415+
" # schema_name=SCHEMA_NAME,\n",
386416
" content_column=\"product_name\",\n",
387417
" metadata_columns=[\"description\", \"content\"],\n",
388418
" metadata_json_column=\"metadata\",\n",
@@ -427,7 +457,7 @@
427457
"metadata": {},
428458
"source": [
429459
"### Load the documents with PostgresLoader\n",
430-
"PostgresLoader can be used with `TABLE_NAME` to query and load the whole table."
460+
"PostgresLoader can be used with `TABLE_NAME` (and optionally `SCHEMA_NAME`) to query and load the whole table."
431461
]
432462
},
433463
{
@@ -436,7 +466,11 @@
436466
"metadata": {},
437467
"outputs": [],
438468
"source": [
439-
"loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)\n",
469+
"loader = await PostgresLoader.create(\n",
470+
" engine,\n",
471+
" table_name=TABLE_NAME,\n",
472+
" # schema_name=SCHEMA_NAME,\n",
473+
")\n",
440474
"docs = await loader.aload()\n",
441475
"\n",
442476
"print(docs)"

docs/vector_store.ipynb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,25 @@
258258
")"
259259
]
260260
},
261+
{
262+
"cell_type": "markdown",
263+
"metadata": {},
264+
"source": [
265+
"#### Optional Tip: 💡\n",
266+
"You can also specify a schema name by passing `schema_name` wherever you pass `table_name`. Eg:\n",
267+
"\n",
268+
"```python\n",
269+
"SCHEMA_NAME=\"my_schema\"\n",
270+
"\n",
271+
"await engine.ainit_vectorstore_table(\n",
272+
" table_name=TABLE_NAME,\n",
273+
" schema_name=SCHEMA_NAME, # Default: \"public\"\n",
274+
" \n",
275+
" ...\n",
276+
")\n",
277+
"```"
278+
]
279+
},
261280
{
262281
"cell_type": "markdown",
263282
"metadata": {},
@@ -322,6 +341,7 @@
322341
"store = await PostgresVectorStore.create( # Use .create() to initialize an async vector store\n",
323342
" engine=engine,\n",
324343
" table_name=TABLE_NAME,\n",
344+
" # schema_name=SCHEMA_NAME,\n",
325345
" embedding_service=embedding,\n",
326346
")"
327347
]
@@ -365,6 +385,7 @@
365385
" ids=ids,\n",
366386
" engine=engine,\n",
367387
" table_name=TABLE_NAME,\n",
388+
" # schema_name=SCHEMA_NAME,\n",
368389
" embedding_service=embedding,\n",
369390
")"
370391
]
@@ -515,9 +536,11 @@
515536
"\n",
516537
"# Set table name\n",
517538
"TABLE_NAME = \"vectorstore_custom\"\n",
539+
"# SCHEMA_NAME = \"my_schema\"\n",
518540
"\n",
519541
"await engine.ainit_vectorstore_table(\n",
520542
" table_name=TABLE_NAME,\n",
543+
" # schema_name=SCHEMA_NAME,\n",
521544
" vector_size=768, # VertexAI model: textembedding-gecko@latest\n",
522545
" metadata_columns=[Column(\"len\", \"INTEGER\")],\n",
523546
")\n",
@@ -527,6 +550,7 @@
527550
"custom_store = await PostgresVectorStore.create(\n",
528551
" engine=engine,\n",
529552
" table_name=TABLE_NAME,\n",
553+
" # schema_name=SCHEMA_NAME,\n",
530554
" embedding_service=embedding,\n",
531555
" metadata_columns=[\"len\"],\n",
532556
" # Connect to a existing VectorStore by customizing the table schema:\n",

0 commit comments

Comments
 (0)