Skill 3.1.6
Generate embeddings
Key Concepts
AI_GENERATE_EMBEDDINGS(text USE MODEL model_name) calls the external model and returns the embedding, which can be assigned to a vector(n) column in an UPDATE, INSERT ... SELECT or MERGE, or to a variable for a query. Optional PARAMETERS JSON, such as {"dimensions":768}, overrides the model definition per call. Combined with AI_GENERATE_CHUNKS, one statement can chunk documents and embed every chunk.
Embeddings can also be generated outside the database, for example with the OpenAI or Foundry SDKs in an application or pipeline, and written to the vector column, or by calling the REST endpoint with sp_invoke_external_rest_endpoint. Large backfills should run in batches to respect the model's rate limits and the database's outbound connection limits, with retries for 429 responses. The same model and dimensions must be used for stored embeddings and query embeddings.