Skip to content

Commit 54fbab5

Browse files
authored
docs: add github links (#46)
1 parent 28d92cb commit 54fbab5

File tree

2 files changed

+25
-47
lines changed

2 files changed

+25
-47
lines changed

docs/chat_message_history.ipynb

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"\n",
1414
"This notebook goes over how to use `Cloud SQL for MySQL` to store chat message history with the `MySQLChatMessageHistory` class.\n",
1515
"\n",
16+
"Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/).\n",
17+
"\n",
1618
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/docs/chat_message_history.ipynb)"
1719
]
1820
},
@@ -26,7 +28,9 @@
2628
"## Before You Begin\n",
2729
"\n",
2830
"To run this notebook, you will need to do the following:\n",
31+
"\n",
2932
" * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n",
33+
" * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/marketplace/product/google/sqladmin.googleapis.com)\n",
3034
" * [Create a Cloud SQL for MySQL instance](https://cloud.google.com/sql/docs/mysql/create-instance)\n",
3135
" * [Create a Cloud SQL database](https://cloud.google.com/sql/docs/mysql/create-manage-databases)\n",
3236
" * [Add an IAM database user to the database](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users#creating-a-database-user) (Optional)"
@@ -144,30 +148,6 @@
144148
"!gcloud config set project {PROJECT_ID}"
145149
]
146150
},
147-
{
148-
"cell_type": "markdown",
149-
"id": "rEWWNoNnKOgq",
150-
"metadata": {
151-
"id": "rEWWNoNnKOgq"
152-
},
153-
"source": [
154-
"### 💡 API Enablement\n",
155-
"The `langchain-google-cloud-sql-mysql` package requires that you [enable the Cloud SQL Admin API](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com) in your Google Cloud Project."
156-
]
157-
},
158-
{
159-
"cell_type": "code",
160-
"execution_count": 3,
161-
"id": "5utKIdq7KYi5",
162-
"metadata": {
163-
"id": "5utKIdq7KYi5"
164-
},
165-
"outputs": [],
166-
"source": [
167-
"# enable Cloud SQL Admin API\n",
168-
"!gcloud services enable sqladmin.googleapis.com"
169-
]
170-
},
171151
{
172152
"cell_type": "markdown",
173153
"id": "f8f2830ee9ca1e01",
@@ -218,7 +198,7 @@
218198
"\n",
219199
"To create a `MySQLEngine` using `MySQLEngine.from_instance()` you need to provide only 4 things:\n",
220200
"\n",
221-
"1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n",
201+
"1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n",
222202
"1. `region` : Region where the Cloud SQL instance is located.\n",
223203
"1. `instance` : The name of the Cloud SQL instance.\n",
224204
"1. `database` : The name of the database to connect to on the Cloud SQL instance.\n",
@@ -230,6 +210,7 @@
230210
"* [Manage users with IAM database authentication](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users)\n",
231211
"\n",
232212
"Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/mysql/built-in-authentication) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `MySQLEngine.from_instance()`:\n",
213+
"\n",
233214
"* `user` : Database user to use for built-in database authentication and login\n",
234215
"* `password` : Database password to use for built-in database authentication and login.\n"
235216
]
@@ -545,7 +526,7 @@
545526
"name": "python",
546527
"nbconvert_exporter": "python",
547528
"pygments_lexer": "ipython3",
548-
"version": "3.9.1"
529+
"version": "3.11.5"
549530
}
550531
},
551532
"nbformat": 4,

docs/document_loader.ipynb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"source": [
77
"# Google Cloud SQL for MySQL\n",
88
"\n",
9-
"> [Cloud SQL](https://cloud.google.com/sql) is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability. It offers [MySQL](https://cloud.google.com/sql/mysql), [PostgreSQL](https://cloud.google.com/sql/postgres), and [SQL Server](https://cloud.google.com/sql/sqlserver) database engines. Extend your database application to build AI-powered experiences leveraging Cloud SQL's Langchain integrations.\n",
9+
"> [Cloud SQL](https://cloud.google.com/sql) is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability. It offers [MySQL](https://cloud.google.com/sql/mysql), [PostgreSQL](https://cloud.google.com/sql/postgresql), and [SQL Server](https://cloud.google.com/sql/sqlserver) database engines. Extend your database application to build AI-powered experiences leveraging Cloud SQL's Langchain integrations.\n",
1010
"\n",
1111
"This notebook goes over how to use [Cloud SQL for MySQL](https://cloud.google.com/sql/mysql) to [save, load and delete langchain documents](https://python.langchain.com/docs/modules/data_connection/document_loaders/) with `MySQLLoader` and `MySQLDocumentSaver`.\n",
1212
"\n",
13+
"Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/).\n",
14+
"\n",
1315
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/docs/document_loader.ipynb)"
1416
]
1517
},
@@ -20,7 +22,9 @@
2022
"## Before You Begin\n",
2123
"\n",
2224
"To run this notebook, you will need to do the following:\n",
25+
"\n",
2326
"* [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n",
27+
"* [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/marketplace/product/google/sqladmin.googleapis.com)\n",
2428
"* [Create a Cloud SQL for MySQL instance](https://cloud.google.com/sql/docs/mysql/create-instance)\n",
2529
"* [Create a Cloud SQL database](https://cloud.google.com/sql/docs/mysql/create-manage-databases)\n",
2630
"* [Add an IAM database user to the database](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users#creating-a-database-user) (Optional)\n",
@@ -136,24 +140,6 @@
136140
"auth.authenticate_user()"
137141
]
138142
},
139-
{
140-
"cell_type": "markdown",
141-
"metadata": {},
142-
"source": [
143-
"### API Enablement\n",
144-
"The `langchain-google-cloud-sql-mysql` package requires that you [enable the Cloud SQL Admin API](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com) in your Google Cloud Project."
145-
]
146-
},
147-
{
148-
"cell_type": "code",
149-
"execution_count": null,
150-
"metadata": {},
151-
"outputs": [],
152-
"source": [
153-
"# enable Cloud SQL Admin API\n",
154-
"!gcloud services enable sqladmin.googleapis.com"
155-
]
156-
},
157143
{
158144
"cell_type": "markdown",
159145
"metadata": {},
@@ -179,10 +165,12 @@
179165
"By default, [IAM database authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication#iam-db-auth) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the envionment.\n",
180166
"\n",
181167
"For more informatin on IAM database authentication please see:\n",
168+
"\n",
182169
"* [Configure an instance for IAM database authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances)\n",
183170
"* [Manage users with IAM database authentication](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users)\n",
184171
"\n",
185172
"Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/mysql/built-in-authentication) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `MySQLEngine.from_instance()`:\n",
173+
"\n",
186174
"* `user` : Database user to use for built-in database authentication and login\n",
187175
"* `password` : Database password to use for built-in database authentication and login."
188176
]
@@ -207,6 +195,7 @@
207195
"### Initialize a table\n",
208196
"\n",
209197
"Initialize a table of default schema via `MySQLEngine.init_document_table(<table_name>)`. Table Columns:\n",
198+
"\n",
210199
"- page_content (type: text)\n",
211200
"- langchain_metadata (type: JSON)\n",
212201
"\n",
@@ -229,6 +218,7 @@
229218
"### Save documents\n",
230219
"\n",
231220
"Save langchain documents with `MySQLDocumentSaver.add_documents(<documents>)`. To initialize `MySQLDocumentSaver` class you need to provide 2 things:\n",
221+
"\n",
232222
"1. `engine` - An instance of a `MySQLEngine` engine.\n",
233223
"2. `table_name` - The name of the table within the Cloud SQL database to store langchain documents."
234224
]
@@ -241,8 +231,8 @@
241231
},
242232
"outputs": [],
243233
"source": [
244-
"from langchain_google_cloud_sql_mysql import MySQLDocumentSaver\n",
245234
"from langchain_core.documents import Document\n",
235+
"from langchain_google_cloud_sql_mysql import MySQLDocumentSaver\n",
246236
"\n",
247237
"test_docs = [\n",
248238
" Document(\n",
@@ -274,6 +264,7 @@
274264
"metadata": {},
275265
"source": [
276266
"Load langchain documents with `MySQLLoader.load()` or `MySQLLoader.lazy_load()`. `lazy_load` returns a generator that only queries database during the iteration. To initialize `MySQLLoader` class you need to provide:\n",
267+
"\n",
277268
"1. `engine` - An instance of a `MySQLEngine` engine.\n",
278269
"2. `table_name` - The name of the table within the Cloud SQL database to store langchain documents."
279270
]
@@ -345,6 +336,7 @@
345336
"For table with default schema (page_content, langchain_metadata), the deletion criteria is:\n",
346337
"\n",
347338
"A `row` should be deleted if there exists a `document` in the list, such that\n",
339+
"\n",
348340
"- `document.page_content` equals `row[page_content]`\n",
349341
"- `document.metadata` equals `row[langchain_metadata]`"
350342
]
@@ -402,7 +394,7 @@
402394
" CREATE TABLE IF NOT EXISTS `{TABLE_NAME}`(\n",
403395
" fruit_id INT AUTO_INCREMENT PRIMARY KEY,\n",
404396
" fruit_name VARCHAR(100) NOT NULL,\n",
405-
" variety VARCHAR(50), \n",
397+
" variety VARCHAR(50),\n",
406398
" quantity_in_stock INT NOT NULL,\n",
407399
" price_per_unit DECIMAL(6,2) NOT NULL,\n",
408400
" organic TINYINT(1) NOT NULL\n",
@@ -449,6 +441,7 @@
449441
"metadata": {},
450442
"source": [
451443
"We can specify the content and metadata we want to load by setting the `content_columns` and `metadata_columns` when initializing the `MySQLLoader`.\n",
444+
"\n",
452445
"1. `content_columns`: The columns to write into the `page_content` of the document.\n",
453446
"2. `metadata_columns`: The columns to write into the `metadata` of the document.\n",
454447
"\n",
@@ -487,12 +480,14 @@
487480
"metadata": {},
488481
"source": [
489482
"In order to save langchain document into table with customized metadata fields. We need first create such a table via `MySQLEngine.init_document_table()`, and specify the list of `metadata_columns` we want it to have. In this example, the created table will have table columns:\n",
483+
"\n",
490484
"- description (type: text): for storing fruit description.\n",
491485
"- fruit_name (type text): for storing fruit name.\n",
492486
"- organic (type tinyint(1)): to tell if the fruit is organic.\n",
493487
"- other_metadata (type: JSON): for storing other metadata information of the fruit.\n",
494488
"\n",
495489
"We can use the following parameters with `MySQLEngine.init_document_table()` to create the table:\n",
490+
"\n",
496491
"1. `table_name`: The name of the table within the Cloud SQL database to store langchain documents.\n",
497492
"2. `metadata_columns`: A list of `sqlalchemy.Column` indicating the list of metadata columns we need.\n",
498493
"3. `content_column`: The name of column to store `page_content` of langchain document. Default: `page_content`.\n",
@@ -532,6 +527,7 @@
532527
"metadata": {},
533528
"source": [
534529
"Save documents with `MySQLDocumentSaver.add_documents(<documents>)`. As you can see in this example, \n",
530+
"\n",
535531
"- `document.page_content` will be saved into `description` column.\n",
536532
"- `document.metadata.fruit_name` will be saved into `fruit_name` column.\n",
537533
"- `document.metadata.organic` will be saved into `organic` column.\n",
@@ -585,6 +581,7 @@
585581
"We can also delete documents from table with customized metadata columns via `MySQLDocumentSaver.delete(<documents>)`. The deletion criteria is:\n",
586582
"\n",
587583
"A `row` should be deleted if there exists a `document` in the list, such that\n",
584+
"\n",
588585
"- `document.page_content` equals `row[page_content]`\n",
589586
"- For every metadata field `k` in `document.metadata`\n",
590587
" - `document.metadata[k]` equals `row[k]` or `document.metadata[k]` equals `row[langchain_metadata][k]`\n",

0 commit comments

Comments
 (0)