diff --git a/scripts/index-api.ts b/scripts/index-api.ts index 73e09ae..8e86a03 100644 --- a/scripts/index-api.ts +++ b/scripts/index-api.ts @@ -1,3 +1,9 @@ +// MUST set environment variable before any imports that use @xenova/transformers +// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc) +if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') { + process.env.ONNXRUNTIME_BACKEND = 'wasm'; +} + import { ApiIndexer } from '../src/search/api-indexer.js'; import path from 'path'; diff --git a/scripts/index-docs.ts b/scripts/index-docs.ts index a6dd2f4..153b76b 100644 --- a/scripts/index-docs.ts +++ b/scripts/index-docs.ts @@ -1,5 +1,11 @@ #!/usr/bin/env tsx +// MUST set environment variable before any imports that use @xenova/transformers +// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc) +if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') { + process.env.ONNXRUNTIME_BACKEND = 'wasm'; +} + import { LanceDBIndexer, DocumentSource } from '../src/search/lancedb-indexer.js'; import path from 'path'; import { fileURLToPath } from 'url'; diff --git a/scripts/index-source.ts b/scripts/index-source.ts index a74c1f8..4540fae 100644 --- a/scripts/index-source.ts +++ b/scripts/index-source.ts @@ -1,3 +1,9 @@ +// MUST set environment variable before any imports that use @xenova/transformers +// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc) +if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') { + process.env.ONNXRUNTIME_BACKEND = 'wasm'; +} + import { SourceCodeIndexer } from '../src/search/source-code-indexer.js'; async function main() { diff --git a/src/search/lancedb-indexer.ts b/src/search/lancedb-indexer.ts index 7e72d2b..dd62ccc 100644 --- a/src/search/lancedb-indexer.ts +++ b/src/search/lancedb-indexer.ts @@ -58,13 +58,10 @@ export class LanceDBIndexer { console.log('Initializing LanceDB connection...'); this.db = await connect(this.dbPath); - // Configure ONNX Runtime backend based on environment variable - // TRANSFORMERS_BACKEND=wasm for Alpine Linux (musl libc) - // Default: native ONNX Runtime (faster, requires glibc) - const backend = process.env.TRANSFORMERS_BACKEND; - if (backend === 'wasm' || backend === 'onnxruntime-web') { + // Log which backend is being used + const backend = process.env.ONNXRUNTIME_BACKEND; + if (backend === 'wasm') { console.log('Using WASM backend for Transformers.js (Alpine/musl compatibility mode)'); - process.env.ONNXRUNTIME_BACKEND = 'wasm'; } else { console.log('Using native ONNX Runtime backend (glibc required)'); }