From cf9a8bf91d920e89256816d79cdcab8b17ee1cab Mon Sep 17 00:00:00 2001 From: Gatefixer <313497061+lancedb-gatefixer[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 04:09:09 +0000 Subject: [PATCH] fix(node): support pre-Haswell x86_64 CPUs --- nodejs/.cargo/config.toml | 18 ++++++++ nodejs/__test__/cpu_compatibility.test.ts | 50 +++++++++++++++++++++++ nodejs/ci/pre_haswell_smoke.js | 37 +++++++++++++++++ nodejs/package.json | 1 + 4 files changed, 106 insertions(+) create mode 100644 nodejs/.cargo/config.toml create mode 100644 nodejs/__test__/cpu_compatibility.test.ts create mode 100644 nodejs/ci/pre_haswell_smoke.js diff --git a/nodejs/.cargo/config.toml b/nodejs/.cargo/config.toml new file mode 100644 index 000000000..c2f1a2a91 --- /dev/null +++ b/nodejs/.cargo/config.toml @@ -0,0 +1,18 @@ +# Keep Node's Linux x64 addons compatible with pre-Haswell CPUs. +# lance-linalg dispatches hot vector kernels to newer SIMD tiers at runtime. +[target.x86_64-unknown-linux-gnu] +rustflags = [ + "-C", + "target-cpu=x86-64-v2", + "-C", + "target-feature=-avx2,-fma,-f16c", +] + +# Preserve the workspace's dynamic C runtime configuration for musl. +[target.x86_64-unknown-linux-musl] +rustflags = [ + "-C", + "target-cpu=x86-64-v2", + "-C", + "target-feature=-crt-static,-avx2,-fma,-f16c", +] diff --git a/nodejs/__test__/cpu_compatibility.test.ts b/nodejs/__test__/cpu_compatibility.test.ts new file mode 100644 index 000000000..20e5196ef --- /dev/null +++ b/nodejs/__test__/cpu_compatibility.test.ts @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright The LanceDB Authors + +import * as tmp from "tmp"; + +import { connect } from "../lancedb"; +import { + Field, + FixedSizeList, + Float32, + Int32, + Schema, + makeArrowTable, +} from "../lancedb/arrow"; + +test("cosine vector search runs on the pre-Haswell build baseline", async () => { + const tmpDir = tmp.dirSync({ unsafeCleanup: true }); + + try { + const db = await connect(tmpDir.name); + const schema = new Schema([ + new Field("id", new Int32(), false), + new Field( + "vector", + new FixedSizeList(3, new Field("item", new Float32(), false)), + false, + ), + ]); + const data = makeArrowTable( + [ + { id: 1, vector: [1, 0, 0] }, + { id: 2, vector: [0, 1, 0] }, + ], + { schema }, + ); + const table = await db.createTable("vectors", data); + + const results = await table + .vectorSearch([1, 0, 0]) + .distanceType("cosine") + .limit(1) + .toArray(); + + expect(results).toHaveLength(1); + expect(results[0].id).toBe(1); + expect(results[0]._distance).toBeCloseTo(0); + } finally { + tmpDir.removeCallback(); + } +}, 60_000); diff --git a/nodejs/ci/pre_haswell_smoke.js b/nodejs/ci/pre_haswell_smoke.js new file mode 100644 index 000000000..0cc9a685f --- /dev/null +++ b/nodejs/ci/pre_haswell_smoke.js @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright The LanceDB Authors + +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const os = require("node:os"); +const path = require("node:path"); + +const { connect } = require("../dist"); + +async function main() { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "lancedb-cpu-")); + + try { + const db = await connect(tmpDir); + const table = await db.createTable("vectors", [ + { id: 1, vector: [1, 0, 0] }, + { id: 2, vector: [0, 1, 0] }, + ]); + const results = await table + .vectorSearch([1, 0, 0]) + .distanceType("cosine") + .limit(1) + .toArray(); + + assert.equal(results.length, 1); + assert.equal(results[0].id, 1); + assert.ok(Math.abs(results[0]._distance) < 1e-6); + } finally { + fs.rmSync(tmpDir, { force: true, recursive: true }); + } +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/nodejs/package.json b/nodejs/package.json index f3f719af2..9f80df0e4 100644 --- a/nodejs/package.json +++ b/nodejs/package.json @@ -88,6 +88,7 @@ "lint-fix": "biome check --write . && biome format --write .", "prepublishOnly": "napi prepublish -t npm", "test": "jest --verbose", + "test:pre-haswell": "node ci/pre_haswell_smoke.js", "integration": "S3_TEST=1 pnpm test", "universal": "napi universalize", "version": "napi version"