postgresml/postgresml

`pgml.predict` does not work with specific models that are not the deployed model

gaspardc-met opened this issue · 3 comments

The documentation of pgml.predict states that you can use a model id to predict with a specific model.
image

However, this does not seem to be possible with the current code on main:
image

This despite the model ID corresponding to a model in this project:
image

Is this a planned feature or a deprecated feature ?

Are you passing a TEXT rather than INTEGER as the model_id? This function is overloaded and TEXT is interpreted as a project.name. We have a test for this functionality in the examples that currently passes:

https://github.com/postgresml/postgresml/blob/master/pgml-extension/examples/regression.sql#L30

I'm running this in python with psycopg2, so I'm passing the int in a string and not really forcing the type

here is a sample code ran with pd.read_sql_query :

                # Prepare the SQL command for inference
                FEATURES_SQL = ", ".join(FEATURES)
                sql_command = f"""
                        SELECT
                            {TARGET} AS actual,
                            pgml.predict(
                                '{model_id}',
                                ARRAY[{FEATURES_SQL}]
                            ) AS prediction
                        FROM
                            {relation_name};
                        """

                # Execute the SQL command
                predictions = pd.read_sql_query(sql_command, engine)

You should be using bind parameters, per the psycopg documentation. String interpolation is fraught with bugs and security risks.

https://www.psycopg.org/psycopg3/docs/basic/params.html