From b38125a89821b283e248f1a206b966bdca8d126d Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Tue, 9 Apr 2024 14:02:21 -0400 Subject: [PATCH 1/4] chore: add additional details and update link in notebooks (#62) --- docs/vector_store.ipynb | 21 +++++++++++++++++---- samples/langchain_quick_start.ipynb | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/vector_store.ipynb b/docs/vector_store.ipynb index ac293fc..b69b085 100644 --- a/docs/vector_store.ipynb +++ b/docs/vector_store.ipynb @@ -29,7 +29,7 @@ "\n", " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com)\n", - " * [Create a Cloud SQL instance.](https://cloud.google.com/sql/docs/mysql/connect-instance-auth-proxy#create-instance) (version must be >= 8.0.36)\n", + " * [Create a Cloud SQL instance.](https://cloud.google.com/sql/docs/mysql/connect-instance-auth-proxy#create-instance) (version must be >= **8.0.36** with **cloudsql_vector** database flag configured to \"On\")\n", " * [Create a Cloud SQL database.](https://cloud.google.com/sql/docs/mysql/create-manage-databases)\n", " * [Add a User to the database.](https://cloud.google.com/sql/docs/mysql/create-manage-users)" ] @@ -154,7 +154,11 @@ }, "source": [ "### Set Cloud SQL database values\n", - "Find your database values, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql?_ga=2.223735448.2062268965.1707700487-2088871159.1707257687)." + "Find your database values, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql?_ga=2.223735448.2062268965.1707700487-2088871159.1707257687).\n", + "\n", + "**Note:** MySQL vector support is only available on MySQL instances with version **>= 8.0.36**.\n", + "\n", + "For existing instances, you may need to perform a [self-service maintenance update](https://cloud.google.com/sql/docs/mysql/self-service-maintenance) to update your maintenance version to **MYSQL_8_0_36.R20240401.03_00** or greater. Once updated, [configure your database flags](https://cloud.google.com/sql/docs/mysql/flags) to have the new **cloudsql_vector** flag to \"On\"." ] }, { @@ -237,7 +241,7 @@ "source": [ "engine.init_vectorstore_table(\n", " table_name=TABLE_NAME,\n", - " vector_size=768, # Vector size for VertexAI model(textembedding-gecko@latest),\n", + " vector_size=768, # Vector size for VertexAI model(textembedding-gecko@latest)\n", ")" ] }, @@ -439,7 +443,16 @@ }, "source": [ "### Add an index\n", - "Speed up vector search queries by applying a vector index. Learn more about [MySQL vector indexes](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/src/langchain_google_cloud_sql_mysql/indexes.py)." + "Speed up vector search queries by applying a vector index. Learn more about [MySQL vector indexes](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/src/langchain_google_cloud_sql_mysql/indexes.py).\n", + "\n", + "**Note:** For IAM database authentication (default usage), the IAM database user will need to be granted the following permissions by a privileged database user for full control of vector indexes.\n", + "\n", + "```\n", + "GRANT EXECUTE ON PROCEDURE mysql.create_vector_index TO ''@'%';\n", + "GRANT EXECUTE ON PROCEDURE mysql.alter_vector_index TO ''@'%';\n", + "GRANT EXECUTE ON PROCEDURE mysql.drop_vector_index TO ''@'%';\n", + "GRANT SELECT ON mysql.vector_indexes TO ''@'%';\n", + "```" ] }, { diff --git a/samples/langchain_quick_start.ipynb b/samples/langchain_quick_start.ipynb index 5b356c7..96daea5 100644 --- a/samples/langchain_quick_start.ipynb +++ b/samples/langchain_quick_start.ipynb @@ -273,7 +273,7 @@ "\n", "**Note:** MySQL vector support is only available on MySQL instances with version **>= 8.0.36**.\n", "\n", - "> For existing instances, you may need to perform a [self-service maintenance update](MYSQL_8_0_36.R20240401.03_00) to update your maintenance version to **MYSQL_8_0_36.R20240401.03_00** or greater. Once updated, [configure your database flags](https://cloud.google.com/sql/docs/mysql/flags) to have thew new **cloudsql_vector** flag to \"On\".\n", + "> For existing instances, you may need to perform a [self-service maintenance update](https://cloud.google.com/sql/docs/mysql/self-service-maintenance) to update your maintenance version to **MYSQL_8_0_36.R20240401.03_00** or greater. Once updated, [configure your database flags](https://cloud.google.com/sql/docs/mysql/flags) to have thew new **cloudsql_vector** flag to \"On\".\n", "\n", "> ⏳ - Creating a Cloud SQL instance may take a few minutes." ] @@ -287,7 +287,7 @@ }, "outputs": [], "source": [ - "#@markdown Please fill in the both the Google Cloud region and name of your Cloud SQL instance. Once filled in, run the cell.\n", + "#@markdown Please fill in both the Google Cloud region and name of your Cloud SQL instance. Once filled in, run the cell.\n", "\n", "# Please fill in these values.\n", "REGION = \"us-central1\" #@param {type:\"string\"}\n", From 40babc57298ee5687c4d4a2cc9684447dd46ed63 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Mon, 15 Apr 2024 19:29:26 +0200 Subject: [PATCH 2/4] chore(deps): update dependency idna to v3.7 [security] (#64) --- .kokoro/requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.kokoro/requirements.txt b/.kokoro/requirements.txt index 8069e8e..d62fc3f 100644 --- a/.kokoro/requirements.txt +++ b/.kokoro/requirements.txt @@ -255,9 +255,9 @@ googleapis-common-protos==1.63.0 \ --hash=sha256:17ad01b11d5f1d0171c06d3ba5c04c54474e883b66b949722b4938ee2694ef4e \ --hash=sha256:ae45f75702f7c08b541f750854a678bd8f534a1a6bace6afe975f1d0a82d6632 # via google-api-core -idna==3.6 \ - --hash=sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca \ - --hash=sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f +idna==3.7 \ + --hash=sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc \ + --hash=sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0 # via requests importlib-metadata==4.13.0 \ --hash=sha256:8a8a81bcf996e74fee46f0d16bd3eaa382a7eb20fd82445c3ad11f4090334116 \ From 4832524b4b5ab9eddeb2a1bdc919608f59945652 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Mon, 15 Apr 2024 18:52:58 -0400 Subject: [PATCH 3/4] fix: allow similarity search on table names with special characters (#65) --- src/langchain_google_cloud_sql_mysql/vectorstore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/langchain_google_cloud_sql_mysql/vectorstore.py b/src/langchain_google_cloud_sql_mysql/vectorstore.py index 2ac2f93..ba7521e 100644 --- a/src/langchain_google_cloud_sql_mysql/vectorstore.py +++ b/src/langchain_google_cloud_sql_mysql/vectorstore.py @@ -675,7 +675,7 @@ def _query_collection( ) if query_options.search_type == SearchType.KNN: filter = f"WHERE {filter}" if filter else "" - stmt = f"SELECT {column_query}, {distance_function}({self.embedding_column}, string_to_vector('{embedding}')) AS distance FROM {self.table_name} {filter} ORDER BY distance LIMIT {k};" + stmt = f"SELECT {column_query}, {distance_function}({self.embedding_column}, string_to_vector('{embedding}')) AS distance FROM `{self.table_name}` {filter} ORDER BY distance LIMIT {k};" else: filter = f"AND {filter}" if filter else "" num_partitions = ( @@ -683,7 +683,7 @@ def _query_collection( if query_options.num_partitions else "" ) - stmt = f"SELECT {column_query}, {distance_function}({self.embedding_column}, string_to_vector('{embedding}')) AS distance FROM {self.table_name} WHERE NEAREST({self.embedding_column}) TO (string_to_vector('{embedding}'), 'num_neighbors={k}{num_partitions}') {filter} ORDER BY distance;" + stmt = f"SELECT {column_query}, {distance_function}({self.embedding_column}, string_to_vector('{embedding}')) AS distance FROM `{self.table_name}` WHERE NEAREST({self.embedding_column}) TO (string_to_vector('{embedding}'), 'num_neighbors={k}{num_partitions}') {filter} ORDER BY distance;" # return self.engine._fetch(stmt) if map_results: From 34c05ba1ea430889fe604f5425fec1d7de3e7e7f Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 08:56:25 -0700 Subject: [PATCH 4/4] chore(main): release 0.2.1 (#66) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ src/langchain_google_cloud_sql_mysql/version.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0100495..579b63f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.2.1](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/compare/v0.2.0...v0.2.1) (2024-04-15) + + +### Bug Fixes + +* Allow similarity search on table names with special characters ([#65](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/issues/65)) ([4832524](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/commit/4832524b4b5ab9eddeb2a1bdc919608f59945652)) + ## [0.2.0](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/compare/v0.1.0...v0.2.0) (2024-04-08) diff --git a/src/langchain_google_cloud_sql_mysql/version.py b/src/langchain_google_cloud_sql_mysql/version.py index 20c5861..fffa9d9 100644 --- a/src/langchain_google_cloud_sql_mysql/version.py +++ b/src/langchain_google_cloud_sql_mysql/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.2.0" +__version__ = "0.2.1"