/var/opt/nydus/ops/mysql/ai/genai/__pycache__
NameSizeModeActions
embedding.cpython-312.pyc76660644editdlrm
generation.cpython-312.pyc58120644editdlrm
vector_store.cpython-312.pyc194820644editdlrm
__init__.cpython-312.pyc6030644editdlrm
Edit: /var/opt/nydus/ops/mysql/ai/genai/__pycache__/embedding.cpython-312.pyc (7666B)
N jdZddlmZmZmZddlZddlmZddl m Z ddl m Z m Z mZmZmZmZmZddlmZGdd eZy) zEmbeddings integration utilities for MySQL Connector/Python. Provides MyEmbeddings class to generate embeddings via MySQL HeatWave using ML_EMBED_TABLE and ML_EMBED_ROW. )DictListOptionalN) Embeddings) PrivateAttr)atomic_transaction execute_sqlformat_value_sql source_schemasql_table_from_dfsql_table_to_dftemporary_sql_tables)MySQLConnectionAbstractceZdZUdZeZeed< d dedee ffd Z de e de e e fdZd e de e fd ZxZS) MyEmbeddingsa Embedding generator class that uses a MySQL database to compute embeddings for input text. This class batches input text into temporary SQL tables, invokes MySQL's ML_EMBED_TABLE to generate embeddings, and retrieves the results as lists of floats. Attributes: _db_connection (MySQLConnectionAbstract): MySQL connection used for all database operations. schema_name (str): Name of the database schema to use. options_placeholder (str): SQL-ready placeholder string for ML_EMBED_TABLE options. options_params (dict): Dictionary of concrete option values to be passed as SQL parameters. _db_connection db_connectionoptionsct|||_t||_|xsi}t |\|_|_y)a Initialize MyEmbeddings with a database connection and optional embedding parameters. References: https://dev.mysql.com/doc/heatwave/en/mys-hwgenai-ml-embed-row.html A full list of supported options can be found under "options" NOTE: The supported "options" are the intersection of the options provided in https://dev.mysql.com/doc/heatwave/en/mys-hwgenai-ml-embed-row.html https://dev.mysql.com/doc/heatwave/en/mys-hwgenai-ml-embed-table.html Args: db_connection: Active MySQL connector database connection. options: Optional dictionary of options for embedding operations. Raises: ValueError: If the schema name is not valid DatabaseError: If a database connection issue occurs. If an operational error occurs during execution. N)super__init__rr schema_namer options_placeholderoptions_params)selfrr __class__s I/opt/nydus/tmp/pip-target-a90h98xg/lib/python/mysql/ai/genai/embedding.pyrzMyEmbeddings.__init__FsC0 +(7-R8H8Q5 $"5textsreturnc |sgStjtt||d}t |j 5}t |j 5}t||j|\}}|j|j|fd|d|d|jd}t|||jt||j|}|djjstd|dDr t!d |dj#} | D cgc] } t%| } } | cd d d cd d d Scc} w#1swYnxYw d d d y #1swYy xYw) a Generate embeddings for a list of input texts using the MySQL ML embedding procedure. References: https://dev.mysql.com/doc/heatwave/en/mys-hwgenai-ml-embed-table.html Args: texts: List of input strings to embed. Returns: List of lists of floats, with each inner list containing the embedding for a text. Raises: DatabaseError: If provided options are invalid or unsupported. If a database connection issue occurs. If an operational error occurs during execution. ValueError: If one or more text entries were unable to be embedded. Implementation notes: - Creates a temporary table to pass input text to the MySQL embedding service. - Adds a primary key to ensure results preserve input order. - Calls ML_EMBED_TABLE and fetches the resulting embeddings. - Deletes the temporary table after use to avoid polluting the database. - Embedding vectors are extracted from the "embeddings" column of the result table. )idtextzCALL sys.ML_EMBED_TABLE('z .text', 'z.embeddings', )params embeddingsc3$K|]}|du ywN).0es r z/MyEmbeddings.embed_documents..sA#>aT #>sz:Failure to generate embeddings for one or more text entry.N)pd DataFramerangelenrrrr rappendrr rr isnullany ValueErrortolistlist) rrdfcursortemporary_tablesqualified_table_name table_name embed_query df_embeddingsr'r,s rembed_documentszMyEmbeddings.embed_documentsds8I \\s5z!2EB C t22 3v !4!4 59I/@(("0 , *  # #T%5%5z$B C()*()++,    D4G4G H,FD4D4DjQM\*113779SA#0#>A>!P '|4;;=J+56:a$q':J6? 6 5 4 3<7; 6 5 5 4 3 3s7E2CE/EE E2EE% !E22E;r#ct|j5}t|d|jd|g|jt |j dcdddS#1swYyxYw)a Generate an embedding for a single text string. References: https://dev.mysql.com/doc/heatwave/en/mys-hwgenai-ml-embed-row.html Args: text: The input string to embed. Returns: List of floats representing the embedding vector. Raises: DatabaseError: If provided options are invalid or unsupported. If a database connection issue occurs. If an operational error occurs during execution. Example: >>> MyEmbeddings(db_conn).embed_query("Hello world") [0.1, 0.2, ...] zSELECT sys.ML_EMBED_ROW("%s", r$r%rN)rrr rrr7fetchone)rr#r9s rr=zMyEmbeddings.embed_queryse.  3 3 4 01I1I0J!L3t223  )!,- 5 4 4s AA&&A/r))__name__ __module__ __qualname____doc__rrr__annotations__rrrrstrfloatr?r= __classcell__)rs@rrr6su /:mN+;QUR4R?G~RrPs=: ('0 >O.:O.r