Forum Discussion
SQL Server 2025 VECTOR functions accepting JSON array strings
Hello!
Playing with new VECTOR type and functions, I can read following https://learn.microsoft.com/en-us/sql/t-sql/functions/vector-distance-transact-sql?view=sql-server-ver17 for vector parameters:
An expression that evaluates to vector data type.
To me this means that any expression (including character strings as JSON-arrays) can be used as parameter.
Since INSERT statement accepts to convert a JSON-array string to a VECTOR, I would expect that these function also accept this conversion.
However, it appears that we are forced to cast the JSON-array to VECTOR.
Any chance to improve this?
Here some T-SQL example:
declare v1 as VECTOR(3) = '[-1,1,0]'
declare S1 as VARCHAR(50) = '[-1,1,0]'
drop table tab1;
create table tab1 (pkey int not null primary key, emb vector(3));
insert into tab1 values ( 101, v1 );
insert into tab1 values ( 102, S1 );
select * from tab1 order by pkey;
select vector_distance('cosine',emb,@v1) from tab1;
select vector_distance('cosine',emb,@s1) from tab1; -- fails
Seb
1 Reply
- carlwalkCopper Contributor
In SQL Server 2025, the new VECTOR functions like VECTOR_DISTANCE work only with actual VECTOR values. You can store a JSON array string in a VECTOR column because SQL Server can convert it when inserting, but the functions won’t automatically convert a JSON string to a VECTOR when you use it. You need to explicitly cast the JSON array to VECTOR first for the functions to work. Essentially, JSON arrays don’t magically become vectors you have to tell SQL Server to treat them that way.