Skip to content

Complete Vector feature v2 (float16) serialization and bulk copy support - #365

Draft
Shiwani Gupta (shiwanigupta0809) wants to merge 3 commits into
mainfrom
dev/shiwanigupta/vector16_complete
Draft

Complete Vector feature v2 (float16) serialization and bulk copy support#365
Shiwani Gupta (shiwanigupta0809) wants to merge 3 commits into
mainfrom
dev/shiwanigupta/vector16_complete

Conversation

@shiwanigupta0809

@shiwanigupta0809 Shiwani Gupta (shiwanigupta0809) commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

Completes Phase 2 of Vector feature v2 (float16) support in mssql-tds. Phase 1
(feature negotiation and deserialization) landed in PR 7493 and left
todo!("Phase 2: Float16 serialization") in the value serializer, so float16
vectors could be read from the server but not written back. This PR implements
the write path and enables float16 by default.

Serializationtds_value_serializer.rs replaces the todo!() with a real
implementation that narrows f32 values to IEEE 754 half-precision using
round-to-nearest-even (via the half crate), matching the msodbcsql reference
driver's Float32ToFloat16Bits. Elements are written little-endian, 2 bytes each,
behind the standard 8-byte vector header.

Bulk copybulk_copy_metadata.rs now emits vector(N, float16) in generated
DDL when the column's base type is float16. Previously it always emitted
vector(N), which SQL Server interprets as float32, so bulk copy of float16
columns produced a type mismatch.

Default versionclient_context.rs flips the default VectorVersion from
V1 to V2, resolving the // TODO: make V2 as default when full V2 support is added left by Phase 1. Version negotiation is unchanged: the client advertises
v2, and the server may still ack v1, in which case behavior is identical to today.

Tests

  • 3 serializer unit tests covering float32 elements, float16 elements, and
    round-to-nearest-even behavior (0.1f320x2E66)
  • 2 bulk copy metadata tests for float16 dimension math and DDL generation
  • 2 SqlVector tests for try_from_f16 and the higher float16 dimension ceiling
    (3996 vs. 1998)
  • 1 feature negotiation test for a v2 ack
  • 14 float16 integration tests covering query, parameter binding, output
    parameters, NULL handling, max dimensions, precision loss, mixed base types,
    and bulk copy

mssql-tds/tests/common/mod.rs now honors a DB_DATABASE env var so integration
tests can target a database with PREVIEW_FEATURES = 1 enabled, defaulting to
master as before.

Related Issues

https://sqlclientdrivers.visualstudio.com/mssql-rs/_workitems/edit/45020
https://sqlclientdrivers.visualstudio.com/mssql-rs/_workitems/edit/45021

Checklist

  • cargo bfmt passes
  • cargo bclippy passes
  • cargo btest passes
  • New/changed functionality has tests
  • Public API changes are documented

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Completes float16 Vector v2 write support in mssql-tds.

Changes:

  • Adds float16 serialization and bulk-copy metadata.
  • Defaults vector negotiation to v2.
  • Expands unit and integration coverage.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mssql-tds/src/connection/client_context.rs Defaults vector negotiation to v2.
mssql-tds/src/datatypes/bulk_copy_metadata.rs Generates float16 vector DDL.
mssql-tds/src/datatypes/sql_vector.rs Tests float16 construction and limits.
mssql-tds/src/datatypes/tds_value_serializer.rs Serializes float16 elements.
mssql-tds/src/message/features/vectorfeature.rs Tests v2 acknowledgement.
mssql-tds/tests/common/mod.rs Supports configurable test databases.
mssql-tds/tests/test_bulk_copy_vector.rs Adds float16 bulk-copy tests.
mssql-tds/tests/test_vector_type.rs Adds float16 integration tests.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3804 to +3814
// 0.1 is not representable in f16; nearest half is 0x2E66.
let vector = crate::datatypes::sql_vector::SqlVector::try_from_f16(vec![0.1]).unwrap();
let ctx = vector_ctx(8 + 2);
block_on(TdsValueSerializer::serialize_value(
&mut w,
&ColumnValues::Vector(vector),
&ctx,
))
.unwrap();
let p = payload(&w);
assert_eq!(&p[10..12], &0x2E66u16.to_le_bytes());
}
VectorData::Float16(_) => {
todo!("Phase 2: Float16 serialization");
VectorData::Float16(vs) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants