Documentation Home
MySQL 9.1 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.3Mb
PDF (A4) - 40.5Mb
Man Pages (TGZ) - 259.3Kb
Man Pages (Zip) - 366.4Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


MySQL 9.1 Reference Manual  /  ...  /  ml Namespace and Convenience Methods

27.3.8.2 ml Namespace and Convenience Methods

The GenAI API also provides the convenience methods described in this section under the ml namespace. These methods act as wrappers for the LLM methods; rather than being invoked as LLM instance methods, they take the model ID as one one of the options passed to them. ml.generate() and ml.rag() return only the text portions of the values returned by their LLM counterparts.

ml.generate()

This method is wrapper for LLM.generate(). It loads the model specified by the model_id specified as one of the options, generates a response based on the prompt using this model, and returns the response. The default model_id ("cohere.command") is used if one is not specified.

Arguments

  • prompt (String) (default "cohere.command"): The desired prompt

  • options (Object) (default {}): The options employed for generation; these follow the same rules as the options used with LLM.generate()

Return type

  • String: The text of the response

Usage

  • //  Both invocations use "cohere.command" as the model_id
    
    let response = ml.generate("What is Mysql?", {max_tokens: 10})
    
    let response = ml.generate("What is Mysql?", {model_id: "cohere.command", max_tokens: 10})
ml.embed()

This method is a wrapper for LLM.embed().

Arguments

  • query (String): Text of a natural-language query

  • options (Object) (default {}): The options employed for generation; these follow the same rules as the options used with LLM.embed(); the default model_id is "all_minilm_l12_v2"

Return type

  • Float32Array (MySQL VECTOR): The embedding

Usage

  • //  These produce the same result
    
    let embedding = ml.embed("What is Mysql?", {model_id: "all_minilm_l12_v2"})
    
    let embedding = ml.embed("What is Mysql?", {})
ml.rag()

This is a wrapper for LLM.rag().

Arguments

  • query (String): Text of a natural-language query

  • options (Object) (default {}): The options employed for generation; these follow the same rules as the options used with LLM.rag(); the default model_id is "mistral-7b-instruct-v1"

Return type

  • String: Response text

Usage

  • //  These produce the same result
    
    let result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1, model_options: {model_id: "mistral-7b-instruct-v1"}})
    
    let result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1})