Skip to content

Commit 28fd2b2

Browse files
claudevdmClaudedamccorm
authored
Mysql embeddings (#35393)
* Add MySQL vector writer. * Trigger tests again. * Comments. * Fix lints etc. * Comment. * Fix typo * Lint fix. * Update sdks/python/apache_beam/ml/rag/ingestion/mysql_common.py Co-authored-by: Danny McCormick <dannymccormick@google.com> --------- Co-authored-by: Claude <cvandermerwe@google.com> Co-authored-by: Danny McCormick <dannymccormick@google.com>
1 parent a265cc6 commit 28fd2b2

6 files changed

Lines changed: 1679 additions & 150 deletions

File tree

sdks/java/extensions/schemaio-expansion-service/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ dependencies {
6464
permitUnusedDeclared 'com.google.cloud:alloydb-jdbc-connector:1.2.0'
6565
implementation 'com.google.cloud.sql:postgres-socket-factory:1.25.0'
6666
permitUnusedDeclared 'com.google.cloud.sql:postgres-socket-factory:1.25.0'
67+
implementation 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.25.0'
68+
permitUnusedDeclared 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.25.0'
6769
testImplementation library.java.junit
6870
testImplementation library.java.mockito_core
6971
runtimeOnly ("org.xerial:sqlite-jdbc:3.49.1.0")

sdks/python/apache_beam/ml/rag/ingestion/cloudsql.py

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
from typing import List
2222
from typing import Optional
2323

24+
from apache_beam.ml.rag.ingestion import mysql
25+
from apache_beam.ml.rag.ingestion import mysql_common
26+
from apache_beam.ml.rag.ingestion import postgres
27+
from apache_beam.ml.rag.ingestion import postgres_common
2428
from apache_beam.ml.rag.ingestion.jdbc_common import ConnectionConfig
2529
from apache_beam.ml.rag.ingestion.jdbc_common import WriteConfig
26-
from apache_beam.ml.rag.ingestion.postgres import ColumnSpecsBuilder
27-
from apache_beam.ml.rag.ingestion.postgres import PostgresVectorWriterConfig
28-
from apache_beam.ml.rag.ingestion.postgres_common import ColumnSpec
29-
from apache_beam.ml.rag.ingestion.postgres_common import ConflictResolution
3030

3131

3232
@dataclass
@@ -138,18 +138,19 @@ def from_base_config(cls, config: LanguageConnectorConfig):
138138
return cls(**asdict(config))
139139

140140

141-
class CloudSQLPostgresVectorWriterConfig(PostgresVectorWriterConfig):
141+
class CloudSQLPostgresVectorWriterConfig(postgres.PostgresVectorWriterConfig):
142142
def __init__(
143143
self,
144144
connection_config: LanguageConnectorConfig,
145145
table_name: str,
146146
*,
147147
# pylint: disable=dangerous-default-value
148148
write_config: WriteConfig = WriteConfig(),
149-
column_specs: List[ColumnSpec] = ColumnSpecsBuilder.with_defaults().build(
150-
),
151-
conflict_resolution: Optional[ConflictResolution] = ConflictResolution(
152-
on_conflict_fields=[], action='IGNORE')):
149+
column_specs: List[postgres_common.ColumnSpec] = postgres_common.
150+
ColumnSpecsBuilder.with_defaults().build(),
151+
conflict_resolution: Optional[
152+
postgres_common.ConflictResolution] = postgres_common.
153+
ConflictResolution(on_conflict_fields=[], action='IGNORE')):
153154
"""Configuration for writing vectors to ClouSQL Postgres.
154155
155156
Supports flexible schema configuration through column specifications and
@@ -218,3 +219,45 @@ def __init__(
218219
table_name=table_name,
219220
column_specs=column_specs,
220221
conflict_resolution=conflict_resolution)
222+
223+
224+
@dataclass
225+
class _MySQLConnectorConfig(LanguageConnectorConfig):
226+
def to_jdbc_url(self) -> str:
227+
"""Convert options to a properly formatted MySQL JDBC URL."""
228+
return self._build_jdbc_url(
229+
socketFactory="com.google.cloud.sql.mysql.SocketFactory",
230+
database_type="mysql")
231+
232+
def additional_jdbc_args(self) -> Dict[str, List[Any]]:
233+
return {
234+
'classpath': [
235+
"mysql:mysql-connector-java:8.0.22",
236+
"com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.25.0"
237+
]
238+
}
239+
240+
@classmethod
241+
def from_base_config(cls, config: LanguageConnectorConfig):
242+
return cls(**asdict(config))
243+
244+
245+
class CloudSQLMySQLVectorWriterConfig(mysql.MySQLVectorWriterConfig):
246+
def __init__(
247+
self,
248+
connection_config: LanguageConnectorConfig,
249+
table_name: str,
250+
*,
251+
write_config: WriteConfig = WriteConfig(),
252+
# pylint: disable=dangerous-default-value
253+
column_specs: List[mysql_common.ColumnSpec] = mysql_common.
254+
ColumnSpecsBuilder.with_defaults().build(),
255+
conflict_resolution: Optional[mysql_common.ConflictResolution] = None):
256+
self.connector_config = _MySQLConnectorConfig.from_base_config(
257+
connection_config)
258+
super().__init__(
259+
connection_config=self.connector_config.to_connection_config(),
260+
write_config=write_config,
261+
table_name=table_name,
262+
column_specs=column_specs,
263+
conflict_resolution=conflict_resolution)

0 commit comments

Comments
 (0)