|
21 | 21 | from typing import List |
22 | 22 | from typing import Optional |
23 | 23 |
|
| 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 |
24 | 28 | from apache_beam.ml.rag.ingestion.jdbc_common import ConnectionConfig |
25 | 29 | 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 |
30 | 30 |
|
31 | 31 |
|
32 | 32 | @dataclass |
@@ -138,18 +138,19 @@ def from_base_config(cls, config: LanguageConnectorConfig): |
138 | 138 | return cls(**asdict(config)) |
139 | 139 |
|
140 | 140 |
|
141 | | -class CloudSQLPostgresVectorWriterConfig(PostgresVectorWriterConfig): |
| 141 | +class CloudSQLPostgresVectorWriterConfig(postgres.PostgresVectorWriterConfig): |
142 | 142 | def __init__( |
143 | 143 | self, |
144 | 144 | connection_config: LanguageConnectorConfig, |
145 | 145 | table_name: str, |
146 | 146 | *, |
147 | 147 | # pylint: disable=dangerous-default-value |
148 | 148 | 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')): |
153 | 154 | """Configuration for writing vectors to ClouSQL Postgres. |
154 | 155 | |
155 | 156 | Supports flexible schema configuration through column specifications and |
@@ -218,3 +219,45 @@ def __init__( |
218 | 219 | table_name=table_name, |
219 | 220 | column_specs=column_specs, |
220 | 221 | 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