Skip to content

feat: add SQL Server VECTOR data type support - #1841

Open
Ananya2 wants to merge 8 commits into
tediousjs:masterfrom
Ananya2:anagarg/vector-datatype-support
Open

Ananya2 wants to merge 8 commits into
tediousjs:masterfrom
Ananya2:anagarg/vector-datatype-support

Conversation

@Ananya2

@Ananya2 Ananya2 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add native support for SQL Server's VECTOR data type, including float32 and float16 elements, across result sets, parameters, stored procedures, prepared statements, table-valued parameters, and bulk load.

Changes

  • Add TYPES.Vector, using Float32Array for vector(n) and Float16Array for vector(n, float16).
  • Infer a parameter's base type from its typed array value. Use baseType when there is no value, such as null and output parameters, bulk-load columns, and TVP columns.
  • Add the vectorTypeSupport connection option: 'off' (default), 'v1', or 'v2'. Keeping 'off' as the default avoids changing results for existing users.
  • Encode and decode VECTOR's binary payload, including its header, dimension count, element type, and NULL representation.
  • Copy typed-array bytes directly in little-endian order, swapping bytes on big-endian platforms; the driver does not convert or round element values.
  • Return VECTOR values as Float32Array or Float16Array, with baseType and dimensions in metadata.
  • Request VECTORSUPPORT version 1 at most when Float16Array is unavailable, such as on Node.js 22, and reject float16 parameters and columns clearly.
  • Report vector declaration errors from prepare() through the request callback instead of throwing synchronously.
  • Add server-free unit tests for encoding, decoding, malformed values, and validation, plus public-API integration tests.

API example

const connection = new Connection({
  ...config,
  options: { ...config.options, vectorTypeSupport: 'v2' }
});

request.addParameter('embedding', TYPES.Vector, new Float32Array([0.1, 0.2, 0.3]));
request.addParameter('embedding16', TYPES.Vector, new Float16Array([0.1, 0.2, 0.3]));

// Null and output parameters require a dimension count.
request.addOutputParameter('result', TYPES.Vector, null, {
  length: 3,
  baseType: 'float16'
});

Compatibility

Native VECTOR support requires TDS 7.4 and successful feature negotiation. VECTORSUPPORT version 1 supports float32; version 2 also supports
float16. With the default 'off', VECTOR columns continue to be returned as JSON text.

On SQL Server 2025, float16 is a preview feature. A version 1 connection returns float16 values as JSON text in varchar(max) and still returns float32 values natively.

Testing

  • npm run lint: ESLint and TypeScript checks passed.
  • Unit tests: 756 passing; one existing SmallDateTime daylight-saving test fails in this environment.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.71930% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.21%. Comparing base (f759e3e) to head (9ba88d3).

Files with missing lines Patch % Lines
src/connection.ts 83.92% 6 Missing and 3 partials ⚠️
src/data-types/vector.ts 92.80% 6 Missing and 3 partials ⚠️
src/token/handler.ts 33.33% 3 Missing and 3 partials ⚠️
src/value-parser.ts 71.42% 1 Missing and 1 partial ⚠️
src/bulk-load.ts 66.66% 0 Missing and 1 partial ⚠️
src/data-types/tvp.ts 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1841      +/-   ##
==========================================
+ Coverage   83.90%   84.21%   +0.31%     
==========================================
  Files          96       97       +1     
  Lines        4735     4955     +220     
  Branches      889      944      +55     
==========================================
+ Hits         3973     4173     +200     
- Misses        509      520      +11     
- Partials      253      262       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arthurschreiber arthurschreiber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this, it's a big piece of work, and the negotiation and wire format handling read well. Before going into details, I'd like to change the shape of the public API, because that affects most of vector.ts.

Vector values should be typed arrays only, in both directions. A Float32Array for vector(n) and a Float16Array for vector(n, float16), with no number[] for parameters, bulk load, TVPs or results. Details are in the inline comments.

Other points:

  • vectorTypeSupport defaulting to 'v2' changes what existing users get back for vector columns today.
  • src/data-types/vector.ts has no unit tests.
  • The float16 tests don't run against any of our SQL Server jobs. Float16 is a preview feature on SQL Server 2025 and needs PREVIEW_FEATURES enabled; the last inline comment suggests tests that can run there.

Generated by Claude Code

Comment thread src/data-types/vector.ts Resolved
Comment thread src/data-types/vector.ts Resolved
Comment thread src/data-types/vector.ts Resolved
Comment thread src/connection.ts Resolved
Comment thread src/metadata-parser.ts Resolved
Comment thread src/data-types/vector.ts Resolved

@arthurschreiber arthurschreiber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the quick turnaround. This addresses everything from the last round, and the typed array API reads well. I ran the vector unit tests on Node.js 22 and 24 and the vector integration tests against SQL Server 2025 on both, and they pass.

Three things before merge:

  • The PR description is out of date. It still says inputs can be number[], results are number[], 'v2' is the default, and float16 values are rounded. Could you rewrite it to match the current API? It will likely end up as the commit message.
  • An explicit invalid length on a bulk load column makes execBulkLoad throw and leaks the row source (inline).
  • The integration tests skip themselves when negotiation fails, and the login side has no unit tests (inline).

The other inline comments are small and can be follow-ups if you prefer.


Generated by Claude Code

Comment thread src/connection.ts Resolved
Comment thread src/connection.ts Resolved
Comment thread src/data-types/vector.ts Resolved
Comment thread src/token/handler.ts Resolved
Comment thread src/bulk-load.ts Resolved
Comment thread src/data-types/tvp.ts Resolved
@saurabh500

saurabh500 commented Nov 25, 2026 •

Copy link
Copy Markdown

Please preserve backward compatibility for existing, non-VECTOR parameters in this PR, including error types and synchronous throw versus asynchronous callback behavior. The current Linux CI failures expose a concrete change in those behaviors; please fix the implementation rather than changing the existing tests to accept it.

Reproduction: no running SQL Server is needed. From the repository root, save the following as a temporary .js file and run it with node -r ./test/setup.js <file> on master and this branch:

const { Connection, Request, TYPES } = require('./src/tedious');

for (const method of ['execSql', 'prepare']) {
  const connection = new Connection({ server: 'localhost' });
  const request = new Request('SELECT 1', (error) => {
    console.log(method, 'callback:', error?.constructor.name, error?.code);
  });
  request.addParameter('tvp', TYPES.TVP, null);

  try {
    connection[method](request);
    console.log(method, 'returned without throwing');
  } catch (error) {
    console.log(method, 'synchronous throw:', error.constructor.name, error.code);
  }
}

On the base implementation, both methods throw TypeError synchronously. In this PR, execSql throws RequestError (EPARAM), while prepare returns and then invokes the callback asynchronously with RequestError (EPARAM). These differences are established by the current CI failures and the implementation diff; I have not run this standalone script locally because dependency installation failed.

Please run these checks on Node.js 22, 24 and 26 and share the results:

  1. Run the existing abort-signal tests unchanged:
    npx mocha --forbid-only test/unit/abort-signal-test.ts
    In particular, retain the four cases asserting no listener registration or cancellation when execSql or prepare throws. Also compare the null-TVP behavior above with VECTOR support disabled, using both an active signal and an already-aborted signal: error type, synchronous throw versus callback, callback count, remaining abort listeners, and cancellation state should preserve the existing behavior.
  2. Run the related parameter/VECTOR tests, then the full unit suite and lint/type check:
    npx mocha --forbid-only test/unit/connection-test.ts test/unit/rpcrequest-payload-test.ts test/unit/vector-data-type-test.ts
    npm test
    npm run lint

Please keep the new VECTOR validation scoped so it does not change existing non-VECTOR error handling. Updating the test setup or expected error alone would not demonstrate that backward compatibility is maintained.

This branch has not been deployed

No deployments
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.

4 participants