Function ai_similarity failing with “Unexpected server response" error

Remove NULL values from the data before passing it to the function.

Written by anshuman.sahu

Last published at: April 29th, 2025

Problem

When you try to use the ai_similarity function to calculate the similarity score between two strings, you receive an Unexpected server response error.

 

Example code

SELECT ai_similarity('Apache Spark', NULL);

 

Example error message

[AI_FUNCTION_INVALID_HTTP_RESPONSE] Invalid HTTP response for function `ai_similarity`: Unexpected server response: Length of the left (1) is different from the right (0) SQLSTATE: 08000

 

Cause

You’re passing NULL as an argument, which means you’re providing input data with NULL values to the ai_similarity function. The function only takes STRING expressions as arguments.

 

Solution

Filter out all NULL values from the input data. For details, refer to the ai_similarity function (AWSAzureGCP) documentation.