mirror of
https://github.com/lancedb/lancedb.git
synced 2026-08-18 12:08:35 +00:00
fix(node): support pre-Haswell x86_64 CPUs
This commit is contained in:
@@ -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",
|
||||
]
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
});
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user