data-api-builder
data-api-builder copied to clipboard
[Enh]: Support `Vector` data type in MSSQL
Vector data type
In SQL (Azure SQL Database and SQL Server 2025+), the VECTOR datatype is an ordered array of FLOAT32 values (single-precision floating point numbers).
CREATE TABLE embeddings (
id INT PRIMARY KEY,
embedding VECTOR(1536) -- an array of 1536 float32 values
)
FOR JSON support
Using FOR JSON, VECTOR columns are emitted as arrays of floats.
SELECT id, embedding FROM embeddings FOR JSON AUTO;
Returns:
[
{
"id": 1,
"embedding": [0.01, 0.23, -0.17, 0.56, 0.88]
},
{
"id": 2,
"embedding": [-0.04, 0.39, 0.27, -0.95, 0.02]
}
]
Inserting a vector
INSERT INTO embeddings (id, embedding)
VALUES (
1,
VECTOR([0.01, 0.23, -0.17, 0.56, 0.88])
);
- The
VECTOR([...])constructor is required. - Values must be valid
FLOAT32. - The number of elements must match the declared dimension exactly.
To check the declared dimension of a VECTOR column:
SELECT
c.name AS column_name,
t.name AS data_type,
c.vector_dimensions AS declared_vector_dimension
FROM sys.columns c
JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE c.object_id = OBJECT_ID('dbo.embeddings')
AND t.name = 'VECTOR';
Result:
| column_name | data_type | declared_vector_dimension |
|---|---|---|
| embedding | vector | 1536 |
Validation responsibility
DAB validates type (must be an array of floats). SQL engine enforces dimension length. This avoids redundant parsing and extra roundtrips to SQL.
Data API builder behavior
DAB exposes VECTOR columns as arrays in REST and GraphQL.
Query operations
REST output example:
{
"value": [
{
"id": 1,
"embedding": [0.01, 0.23, -0.17, 0.56, 0.88, 0.0, 0.14, ...]
},
{
"id": 2,
"embedding": [-0.04, 0.39, 0.27, -0.95, 0.02, 0.12, 0.33, ...]
},
{
"id": 3,
"embedding": [0.10, 0.45, -0.06, 0.08, -0.23, 0.19, 0.41, ...]
}
]
}
Mutation operations
POST /embeddings
Content-Type: application/json
{
"id": 4,
"embedding": [0.11, -0.02, 0.33, 0.47, 0.18, 0.26, -0.09, ...]
}