@sqliteai/sqlite-vector 0.9.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +326 -0
- package/dist/index.d.mts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +162 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +151 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# @sqliteai/sqlite-vector
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@sqliteai/sqlite-vector)
|
|
4
|
+
[](../../../LICENSE.md)
|
|
5
|
+
|
|
6
|
+
> SQLite Vector extension for Node.js - Cross-platform vector embeddings and similarity search
|
|
7
|
+
|
|
8
|
+
**SQLite Vector** brings powerful vector search capabilities to SQLite in Node.js. Perfect for Edge AI, semantic search, RAG applications, and similarity matching - all running locally without external dependencies.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- ✅ **Cross-platform** - Works on macOS, Linux (glibc/musl), and Windows
|
|
13
|
+
- ✅ **Zero configuration** - Automatically detects and loads the correct binary for your platform
|
|
14
|
+
- ✅ **TypeScript native** - Full type definitions included
|
|
15
|
+
- ✅ **Modern ESM + CJS** - Works with both ES modules and CommonJS
|
|
16
|
+
- ✅ **Small footprint** - Only downloads binaries for your platform (~30MB)
|
|
17
|
+
- ✅ **Offline-ready** - No external services required
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @sqliteai/sqlite-vector
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The package automatically downloads the correct native extension for your platform during installation.
|
|
26
|
+
|
|
27
|
+
### Supported Platforms
|
|
28
|
+
|
|
29
|
+
| Platform | Architecture | Package |
|
|
30
|
+
|----------|-------------|---------|
|
|
31
|
+
| macOS | ARM64 (Apple Silicon) | `@sqliteai/sqlite-vector-darwin-arm64` |
|
|
32
|
+
| macOS | x86_64 (Intel) | `@sqliteai/sqlite-vector-darwin-x86_64` |
|
|
33
|
+
| Linux | ARM64 (glibc) | `@sqliteai/sqlite-vector-linux-arm64` |
|
|
34
|
+
| Linux | ARM64 (musl/Alpine) | `@sqliteai/sqlite-vector-linux-arm64-musl` |
|
|
35
|
+
| Linux | x86_64 (glibc) | `@sqliteai/sqlite-vector-linux-x86_64` |
|
|
36
|
+
| Linux | x86_64 (musl/Alpine) | `@sqliteai/sqlite-vector-linux-x86_64-musl` |
|
|
37
|
+
| Windows | x86_64 | `@sqliteai/sqlite-vector-win32-x86_64` |
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
### Basic Usage
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { getExtensionPath } from '@sqliteai/sqlite-vector';
|
|
45
|
+
import Database from 'better-sqlite3';
|
|
46
|
+
|
|
47
|
+
// Get the path to the vector extension
|
|
48
|
+
const extensionPath = getExtensionPath();
|
|
49
|
+
|
|
50
|
+
// Load it into your SQLite database
|
|
51
|
+
const db = new Database(':memory:');
|
|
52
|
+
db.loadExtension(extensionPath);
|
|
53
|
+
|
|
54
|
+
// Use vector functions
|
|
55
|
+
db.exec(`
|
|
56
|
+
CREATE TABLE embeddings (
|
|
57
|
+
id INTEGER PRIMARY KEY,
|
|
58
|
+
vector BLOB,
|
|
59
|
+
text TEXT
|
|
60
|
+
);
|
|
61
|
+
`);
|
|
62
|
+
|
|
63
|
+
// Initialize vector search
|
|
64
|
+
db.prepare("SELECT vector_init('embeddings', 'vector', 'type=FLOAT32,dimension=384')").run();
|
|
65
|
+
|
|
66
|
+
// Insert vectors (using your embedding model)
|
|
67
|
+
const embedding = new Float32Array(384);
|
|
68
|
+
// ... fill embedding with your model's output
|
|
69
|
+
|
|
70
|
+
db.prepare('INSERT INTO embeddings (vector, text) VALUES (?, ?)').run(
|
|
71
|
+
Buffer.from(embedding.buffer),
|
|
72
|
+
'Sample text'
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Perform similarity search
|
|
76
|
+
const query = new Float32Array(384); // Your query embedding
|
|
77
|
+
const results = db.prepare(`
|
|
78
|
+
SELECT e.id, e.text, v.distance
|
|
79
|
+
FROM embeddings AS e
|
|
80
|
+
JOIN vector_quantize_scan('embeddings', 'vector', ?, 10) AS v
|
|
81
|
+
ON e.id = v.rowid
|
|
82
|
+
ORDER BY v.distance ASC
|
|
83
|
+
`).all(Buffer.from(query.buffer));
|
|
84
|
+
|
|
85
|
+
console.log(results);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### CommonJS
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const { getExtensionPath } = require('@sqliteai/sqlite-vector');
|
|
92
|
+
const Database = require('better-sqlite3');
|
|
93
|
+
|
|
94
|
+
const db = new Database(':memory:');
|
|
95
|
+
db.loadExtension(getExtensionPath());
|
|
96
|
+
|
|
97
|
+
// Ready to use
|
|
98
|
+
const version = db.prepare('SELECT vector_version()').pluck().get();
|
|
99
|
+
console.log('Vector extension version:', version);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Get Extension Information
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { getExtensionInfo } from '@sqliteai/sqlite-vector';
|
|
106
|
+
|
|
107
|
+
const info = getExtensionInfo();
|
|
108
|
+
console.log(info);
|
|
109
|
+
// {
|
|
110
|
+
// platform: 'darwin-arm64',
|
|
111
|
+
// packageName: '@sqliteai/sqlite-vector-darwin-arm64',
|
|
112
|
+
// binaryName: 'vector.dylib',
|
|
113
|
+
// path: '/path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib'
|
|
114
|
+
// }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Examples
|
|
118
|
+
|
|
119
|
+
For complete, runnable examples, see the [sqlite-extensions-guide](https://github.com/sqliteai/sqlite-extensions-guide/tree/main/examples/node):
|
|
120
|
+
|
|
121
|
+
- **[basic-usage.js](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/examples/node/basic-usage.js)** - Generic extension loading for any @sqliteai extension
|
|
122
|
+
- **[semantic-search.js](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/examples/node/semantic-search.js)** - Complete semantic search with OpenAI or on-device embeddings
|
|
123
|
+
- **[with-multiple-extensions.js](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/examples/node/with-multiple-extensions.js)** - Loading multiple extensions together (vector + sync + AI + js)
|
|
124
|
+
|
|
125
|
+
These examples are generic and work with all SQLite extensions: `sqlite-vector`, `sqlite-sync`, `sqlite-js`, and `sqlite-ai`.
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
### `getExtensionPath(): string`
|
|
130
|
+
|
|
131
|
+
Returns the absolute path to the SQLite Vector extension binary for the current platform.
|
|
132
|
+
|
|
133
|
+
**Returns:** `string` - Absolute path to the extension file (`.so`, `.dylib`, or `.dll`)
|
|
134
|
+
|
|
135
|
+
**Throws:** `ExtensionNotFoundError` - If the extension binary cannot be found for the current platform
|
|
136
|
+
|
|
137
|
+
**Example:**
|
|
138
|
+
```typescript
|
|
139
|
+
import { getExtensionPath } from '@sqliteai/sqlite-vector';
|
|
140
|
+
|
|
141
|
+
const path = getExtensionPath();
|
|
142
|
+
// => '/path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### `getExtensionInfo(): ExtensionInfo`
|
|
148
|
+
|
|
149
|
+
Returns detailed information about the extension for the current platform.
|
|
150
|
+
|
|
151
|
+
**Returns:** `ExtensionInfo` object with the following properties:
|
|
152
|
+
- `platform: Platform` - Current platform identifier (e.g., `'darwin-arm64'`)
|
|
153
|
+
- `packageName: string` - Name of the platform-specific npm package
|
|
154
|
+
- `binaryName: string` - Filename of the binary (e.g., `'vector.dylib'`)
|
|
155
|
+
- `path: string` - Full path to the extension binary
|
|
156
|
+
|
|
157
|
+
**Throws:** `ExtensionNotFoundError` - If the extension binary cannot be found
|
|
158
|
+
|
|
159
|
+
**Example:**
|
|
160
|
+
```typescript
|
|
161
|
+
import { getExtensionInfo } from '@sqliteai/sqlite-vector';
|
|
162
|
+
|
|
163
|
+
const info = getExtensionInfo();
|
|
164
|
+
console.log(`Running on ${info.platform}`);
|
|
165
|
+
console.log(`Extension path: ${info.path}`);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
### `getCurrentPlatform(): Platform`
|
|
171
|
+
|
|
172
|
+
Returns the current platform identifier.
|
|
173
|
+
|
|
174
|
+
**Returns:** `Platform` - One of:
|
|
175
|
+
- `'darwin-arm64'` - macOS ARM64
|
|
176
|
+
- `'darwin-x86_64'` - macOS x86_64
|
|
177
|
+
- `'linux-arm64'` - Linux ARM64 (glibc)
|
|
178
|
+
- `'linux-arm64-musl'` - Linux ARM64 (musl)
|
|
179
|
+
- `'linux-x86_64'` - Linux x86_64 (glibc)
|
|
180
|
+
- `'linux-x86_64-musl'` - Linux x86_64 (musl)
|
|
181
|
+
- `'win32-x86_64'` - Windows x86_64
|
|
182
|
+
|
|
183
|
+
**Throws:** `Error` - If the platform is unsupported
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### `isMusl(): boolean`
|
|
188
|
+
|
|
189
|
+
Detects if the system uses musl libc (Alpine Linux, etc.).
|
|
190
|
+
|
|
191
|
+
**Returns:** `boolean` - `true` if musl is detected, `false` otherwise
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### `class ExtensionNotFoundError extends Error`
|
|
196
|
+
|
|
197
|
+
Error thrown when the SQLite Vector extension cannot be found for the current platform.
|
|
198
|
+
|
|
199
|
+
## Vector Search Guide
|
|
200
|
+
|
|
201
|
+
For detailed information on how to use the vector search features, see the [main documentation](https://github.com/sqliteai/sqlite-vector/blob/main/README.md).
|
|
202
|
+
|
|
203
|
+
### Quick Reference
|
|
204
|
+
|
|
205
|
+
```sql
|
|
206
|
+
-- Initialize vector column
|
|
207
|
+
SELECT vector_init('table', 'column', 'type=FLOAT32,dimension=384');
|
|
208
|
+
|
|
209
|
+
-- Quantize vectors for faster search
|
|
210
|
+
SELECT vector_quantize('table', 'column');
|
|
211
|
+
|
|
212
|
+
-- Preload into memory for 4-5x speedup
|
|
213
|
+
SELECT vector_quantize_preload('table', 'column');
|
|
214
|
+
|
|
215
|
+
-- Search for similar vectors
|
|
216
|
+
SELECT * FROM table AS t
|
|
217
|
+
JOIN vector_quantize_scan('table', 'column', <query_vector>, <limit>) AS v
|
|
218
|
+
ON t.rowid = v.rowid
|
|
219
|
+
ORDER BY v.distance;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Distance Metrics
|
|
223
|
+
|
|
224
|
+
Specify the distance metric during initialization:
|
|
225
|
+
|
|
226
|
+
```sql
|
|
227
|
+
-- L2 (Euclidean) - default
|
|
228
|
+
SELECT vector_init('table', 'column', 'type=FLOAT32,dimension=384,distance=L2');
|
|
229
|
+
|
|
230
|
+
-- Cosine similarity
|
|
231
|
+
SELECT vector_init('table', 'column', 'type=FLOAT32,dimension=384,distance=COSINE');
|
|
232
|
+
|
|
233
|
+
-- Dot product
|
|
234
|
+
SELECT vector_init('table', 'column', 'type=FLOAT32,dimension=384,distance=DOT');
|
|
235
|
+
|
|
236
|
+
-- L1 (Manhattan)
|
|
237
|
+
SELECT vector_init('table', 'column', 'type=FLOAT32,dimension=384,distance=L1');
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Troubleshooting
|
|
241
|
+
|
|
242
|
+
### Extension Not Found
|
|
243
|
+
|
|
244
|
+
If you get `ExtensionNotFoundError`, try:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
# Force reinstall dependencies
|
|
248
|
+
npm install --force
|
|
249
|
+
|
|
250
|
+
# Or manually install the platform package
|
|
251
|
+
npm install @sqliteai/sqlite-vector-darwin-arm64 # Replace with your platform
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Platform Not Detected
|
|
255
|
+
|
|
256
|
+
The package should automatically detect your platform. If detection fails, please [open an issue](https://github.com/sqliteai/sqlite-vector/issues) with:
|
|
257
|
+
- Your OS and architecture
|
|
258
|
+
- Node.js version
|
|
259
|
+
- Output of `node -p "process.platform + '-' + process.arch"`
|
|
260
|
+
|
|
261
|
+
### Alpine Linux / musl
|
|
262
|
+
|
|
263
|
+
On Alpine Linux or other musl-based systems, the package automatically detects musl and installs the correct variant. If you encounter issues:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
# Verify musl detection
|
|
267
|
+
node -e "console.log(require('@sqliteai/sqlite-vector').isMusl())"
|
|
268
|
+
|
|
269
|
+
# Should print: true
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Development
|
|
273
|
+
|
|
274
|
+
### Building from Source
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Clone the repository
|
|
278
|
+
git clone https://github.com/sqliteai/sqlite-vector.git
|
|
279
|
+
cd sqlite-vector/packages/node
|
|
280
|
+
|
|
281
|
+
# Install dependencies
|
|
282
|
+
npm install
|
|
283
|
+
|
|
284
|
+
# Build TypeScript
|
|
285
|
+
npm run build
|
|
286
|
+
|
|
287
|
+
# Run tests
|
|
288
|
+
npm test
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Project Structure
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
packages/node/
|
|
295
|
+
├── src/
|
|
296
|
+
│ ├── index.ts # Main entry point
|
|
297
|
+
│ ├── platform.ts # Platform detection logic
|
|
298
|
+
│ └── index.test.ts # Test suite
|
|
299
|
+
├── dist/ # Compiled JavaScript (generated)
|
|
300
|
+
├── generate-platform-packages.js # Platform package generator
|
|
301
|
+
├── package.json
|
|
302
|
+
├── tsconfig.json
|
|
303
|
+
└── README.md
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Related Projects
|
|
307
|
+
|
|
308
|
+
- **[SQLite-AI](https://github.com/sqliteai/sqlite-ai)** - On-device AI inference and embedding generation
|
|
309
|
+
- **[SQLite-Sync](https://github.com/sqliteai/sqlite-sync)** - Sync on-device databases with the cloud
|
|
310
|
+
- **[SQLite-JS](https://github.com/sqliteai/sqlite-js)** - Define SQLite functions in JavaScript
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
This project is licensed under the [Elastic License 2.0](../../../LICENSE.md).
|
|
315
|
+
|
|
316
|
+
For production or managed service use, please [contact SQLite Cloud, Inc](mailto:info@sqlitecloud.io) for a commercial license.
|
|
317
|
+
|
|
318
|
+
## Contributing
|
|
319
|
+
|
|
320
|
+
Contributions are welcome! Please see the [main repository](https://github.com/sqliteai/sqlite-vector) for contribution guidelines.
|
|
321
|
+
|
|
322
|
+
## Support
|
|
323
|
+
|
|
324
|
+
- 📖 [Documentation](https://github.com/sqliteai/sqlite-vector/blob/main/API.md)
|
|
325
|
+
- 🐛 [Report Issues](https://github.com/sqliteai/sqlite-vector/issues)
|
|
326
|
+
- 💬 [Discussions](https://github.com/sqliteai/sqlite-vector/discussions)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported platform identifiers
|
|
3
|
+
*/
|
|
4
|
+
type Platform = 'darwin-arm64' | 'darwin-x86_64' | 'linux-arm64' | 'linux-arm64-musl' | 'linux-x86_64' | 'linux-x86_64-musl' | 'win32-x86_64';
|
|
5
|
+
/**
|
|
6
|
+
* Detects if the system uses musl libc (Alpine Linux, etc.)
|
|
7
|
+
* Uses multiple detection strategies for reliability
|
|
8
|
+
*/
|
|
9
|
+
declare function isMusl(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the current platform identifier
|
|
12
|
+
* @throws {Error} If the platform is unsupported
|
|
13
|
+
*/
|
|
14
|
+
declare function getCurrentPlatform(): Platform;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the package name for the current platform
|
|
17
|
+
*/
|
|
18
|
+
declare function getPlatformPackageName(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the binary filename for the current platform
|
|
21
|
+
*/
|
|
22
|
+
declare function getBinaryName(): string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Error thrown when the SQLite Vector extension cannot be found
|
|
26
|
+
*/
|
|
27
|
+
declare class ExtensionNotFoundError extends Error {
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the absolute path to the SQLite Vector extension binary for the current platform
|
|
32
|
+
*
|
|
33
|
+
* @returns Absolute path to the extension binary (.so, .dylib, or .dll)
|
|
34
|
+
* @throws {ExtensionNotFoundError} If the extension binary cannot be found
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { getExtensionPath } from '@sqliteai/sqlite-vector';
|
|
39
|
+
*
|
|
40
|
+
* const extensionPath = getExtensionPath();
|
|
41
|
+
* // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function getExtensionPath(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Information about the current platform and extension
|
|
47
|
+
*/
|
|
48
|
+
interface ExtensionInfo {
|
|
49
|
+
/** Current platform identifier (e.g., 'darwin-arm64') */
|
|
50
|
+
platform: Platform;
|
|
51
|
+
/** Name of the platform-specific npm package */
|
|
52
|
+
packageName: string;
|
|
53
|
+
/** Filename of the binary (e.g., 'vector.dylib') */
|
|
54
|
+
binaryName: string;
|
|
55
|
+
/** Full path to the extension binary */
|
|
56
|
+
path: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets detailed information about the SQLite Vector extension
|
|
60
|
+
*
|
|
61
|
+
* @returns Extension information object
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { getExtensionInfo } from '@sqliteai/sqlite-vector';
|
|
66
|
+
*
|
|
67
|
+
* const info = getExtensionInfo();
|
|
68
|
+
* console.log(info);
|
|
69
|
+
* // {
|
|
70
|
+
* // platform: 'darwin-arm64',
|
|
71
|
+
* // packageName: '@sqliteai/sqlite-vector-darwin-arm64',
|
|
72
|
+
* // binaryName: 'vector.dylib',
|
|
73
|
+
* // path: '/path/to/vector.dylib'
|
|
74
|
+
* // }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function getExtensionInfo(): ExtensionInfo;
|
|
78
|
+
declare const _default: {
|
|
79
|
+
getExtensionPath: typeof getExtensionPath;
|
|
80
|
+
getExtensionInfo: typeof getExtensionInfo;
|
|
81
|
+
ExtensionNotFoundError: typeof ExtensionNotFoundError;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { type ExtensionInfo, ExtensionNotFoundError, type Platform, _default as default, getBinaryName, getCurrentPlatform, getExtensionInfo, getExtensionPath, getPlatformPackageName, isMusl };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported platform identifiers
|
|
3
|
+
*/
|
|
4
|
+
type Platform = 'darwin-arm64' | 'darwin-x86_64' | 'linux-arm64' | 'linux-arm64-musl' | 'linux-x86_64' | 'linux-x86_64-musl' | 'win32-x86_64';
|
|
5
|
+
/**
|
|
6
|
+
* Detects if the system uses musl libc (Alpine Linux, etc.)
|
|
7
|
+
* Uses multiple detection strategies for reliability
|
|
8
|
+
*/
|
|
9
|
+
declare function isMusl(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the current platform identifier
|
|
12
|
+
* @throws {Error} If the platform is unsupported
|
|
13
|
+
*/
|
|
14
|
+
declare function getCurrentPlatform(): Platform;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the package name for the current platform
|
|
17
|
+
*/
|
|
18
|
+
declare function getPlatformPackageName(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the binary filename for the current platform
|
|
21
|
+
*/
|
|
22
|
+
declare function getBinaryName(): string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Error thrown when the SQLite Vector extension cannot be found
|
|
26
|
+
*/
|
|
27
|
+
declare class ExtensionNotFoundError extends Error {
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the absolute path to the SQLite Vector extension binary for the current platform
|
|
32
|
+
*
|
|
33
|
+
* @returns Absolute path to the extension binary (.so, .dylib, or .dll)
|
|
34
|
+
* @throws {ExtensionNotFoundError} If the extension binary cannot be found
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { getExtensionPath } from '@sqliteai/sqlite-vector';
|
|
39
|
+
*
|
|
40
|
+
* const extensionPath = getExtensionPath();
|
|
41
|
+
* // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function getExtensionPath(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Information about the current platform and extension
|
|
47
|
+
*/
|
|
48
|
+
interface ExtensionInfo {
|
|
49
|
+
/** Current platform identifier (e.g., 'darwin-arm64') */
|
|
50
|
+
platform: Platform;
|
|
51
|
+
/** Name of the platform-specific npm package */
|
|
52
|
+
packageName: string;
|
|
53
|
+
/** Filename of the binary (e.g., 'vector.dylib') */
|
|
54
|
+
binaryName: string;
|
|
55
|
+
/** Full path to the extension binary */
|
|
56
|
+
path: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets detailed information about the SQLite Vector extension
|
|
60
|
+
*
|
|
61
|
+
* @returns Extension information object
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { getExtensionInfo } from '@sqliteai/sqlite-vector';
|
|
66
|
+
*
|
|
67
|
+
* const info = getExtensionInfo();
|
|
68
|
+
* console.log(info);
|
|
69
|
+
* // {
|
|
70
|
+
* // platform: 'darwin-arm64',
|
|
71
|
+
* // packageName: '@sqliteai/sqlite-vector-darwin-arm64',
|
|
72
|
+
* // binaryName: 'vector.dylib',
|
|
73
|
+
* // path: '/path/to/vector.dylib'
|
|
74
|
+
* // }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function getExtensionInfo(): ExtensionInfo;
|
|
78
|
+
declare const _default: {
|
|
79
|
+
getExtensionPath: typeof getExtensionPath;
|
|
80
|
+
getExtensionInfo: typeof getExtensionInfo;
|
|
81
|
+
ExtensionNotFoundError: typeof ExtensionNotFoundError;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { type ExtensionInfo, ExtensionNotFoundError, type Platform, _default as default, getBinaryName, getCurrentPlatform, getExtensionInfo, getExtensionPath, getPlatformPackageName, isMusl };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var os = require('os');
|
|
8
|
+
var child_process = require('child_process');
|
|
9
|
+
|
|
10
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
12
|
+
}) : x)(function(x) {
|
|
13
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
15
|
+
});
|
|
16
|
+
var PLATFORM_EXTENSIONS = {
|
|
17
|
+
darwin: ".dylib",
|
|
18
|
+
linux: ".so",
|
|
19
|
+
win32: ".dll"
|
|
20
|
+
};
|
|
21
|
+
function isMusl() {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
if (os.platform() !== "linux") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const muslFiles = [
|
|
27
|
+
"/lib/ld-musl-x86_64.so.1",
|
|
28
|
+
"/lib/ld-musl-aarch64.so.1",
|
|
29
|
+
"/lib/ld-musl-armhf.so.1"
|
|
30
|
+
];
|
|
31
|
+
for (const file of muslFiles) {
|
|
32
|
+
if (fs.existsSync(file)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const lddVersion = child_process.execSync("ldd --version 2>&1", {
|
|
38
|
+
encoding: "utf-8",
|
|
39
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
40
|
+
});
|
|
41
|
+
if (lddVersion.includes("musl")) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
if (fs.existsSync("/etc/os-release")) {
|
|
48
|
+
const osRelease = fs.readFileSync("/etc/os-release", "utf-8");
|
|
49
|
+
if (osRelease.includes("Alpine") || osRelease.includes("musl")) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const report = (_b = (_a = process.report) == null ? void 0 : _a.getReport) == null ? void 0 : _b.call(_a);
|
|
57
|
+
if (((_c = report == null ? void 0 : report.header) == null ? void 0 : _c.glibcVersionRuntime) === "") {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
function getCurrentPlatform() {
|
|
65
|
+
const platformName = os.platform();
|
|
66
|
+
const archName = os.arch();
|
|
67
|
+
if (platformName === "darwin") {
|
|
68
|
+
if (archName === "arm64") return "darwin-arm64";
|
|
69
|
+
if (archName === "x64" || archName === "ia32") return "darwin-x86_64";
|
|
70
|
+
}
|
|
71
|
+
if (platformName === "linux") {
|
|
72
|
+
const muslSuffix = isMusl() ? "-musl" : "";
|
|
73
|
+
if (archName === "arm64") {
|
|
74
|
+
return `linux-arm64${muslSuffix}`;
|
|
75
|
+
}
|
|
76
|
+
if (archName === "x64" || archName === "ia32") {
|
|
77
|
+
return `linux-x86_64${muslSuffix}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (platformName === "win32") {
|
|
81
|
+
if (archName === "x64" || archName === "ia32") return "win32-x86_64";
|
|
82
|
+
}
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Unsupported platform: ${platformName}-${archName}. Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 (with glibc or musl support for Linux)`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function getPlatformPackageName() {
|
|
88
|
+
const currentPlatform = getCurrentPlatform();
|
|
89
|
+
return `@sqliteai/sqlite-vector-${currentPlatform}`;
|
|
90
|
+
}
|
|
91
|
+
function getBinaryName() {
|
|
92
|
+
const platformName = os.platform();
|
|
93
|
+
const extension = PLATFORM_EXTENSIONS[platformName];
|
|
94
|
+
if (!extension) {
|
|
95
|
+
throw new Error(`Unknown platform: ${platformName}`);
|
|
96
|
+
}
|
|
97
|
+
return `vector${extension}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/index.ts
|
|
101
|
+
var ExtensionNotFoundError = class extends Error {
|
|
102
|
+
constructor(message) {
|
|
103
|
+
super(message);
|
|
104
|
+
this.name = "ExtensionNotFoundError";
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
function tryLoadPlatformPackage() {
|
|
108
|
+
try {
|
|
109
|
+
const packageName = getPlatformPackageName();
|
|
110
|
+
const platformPackage = __require(packageName);
|
|
111
|
+
if ((platformPackage == null ? void 0 : platformPackage.path) && typeof platformPackage.path === "string") {
|
|
112
|
+
if (fs.existsSync(platformPackage.path)) {
|
|
113
|
+
return platformPackage.path;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
function getExtensionPath() {
|
|
121
|
+
const platformPath = tryLoadPlatformPackage();
|
|
122
|
+
if (platformPath) {
|
|
123
|
+
return path.resolve(platformPath);
|
|
124
|
+
}
|
|
125
|
+
const currentPlatform = getCurrentPlatform();
|
|
126
|
+
const packageName = getPlatformPackageName();
|
|
127
|
+
throw new ExtensionNotFoundError(
|
|
128
|
+
`SQLite Vector extension not found for platform: ${currentPlatform}
|
|
129
|
+
|
|
130
|
+
The platform-specific package "${packageName}" is not installed.
|
|
131
|
+
This usually happens when:
|
|
132
|
+
1. Your platform is not supported
|
|
133
|
+
2. npm failed to install optional dependencies
|
|
134
|
+
3. You're installing with --no-optional flag
|
|
135
|
+
|
|
136
|
+
Try running: npm install --force`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function getExtensionInfo() {
|
|
140
|
+
return {
|
|
141
|
+
platform: getCurrentPlatform(),
|
|
142
|
+
packageName: getPlatformPackageName(),
|
|
143
|
+
binaryName: getBinaryName(),
|
|
144
|
+
path: getExtensionPath()
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
var index_default = {
|
|
148
|
+
getExtensionPath,
|
|
149
|
+
getExtensionInfo,
|
|
150
|
+
ExtensionNotFoundError
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
exports.ExtensionNotFoundError = ExtensionNotFoundError;
|
|
154
|
+
exports.default = index_default;
|
|
155
|
+
exports.getBinaryName = getBinaryName;
|
|
156
|
+
exports.getCurrentPlatform = getCurrentPlatform;
|
|
157
|
+
exports.getExtensionInfo = getExtensionInfo;
|
|
158
|
+
exports.getExtensionPath = getExtensionPath;
|
|
159
|
+
exports.getPlatformPackageName = getPlatformPackageName;
|
|
160
|
+
exports.isMusl = isMusl;
|
|
161
|
+
//# sourceMappingURL=index.js.map
|
|
162
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platform.ts","../src/index.ts"],"names":["platform","existsSync","execSync","readFileSync","arch","resolve"],"mappings":";;;;;;;;;;;;;;;AAmBO,IAAM,mBAAA,GAA8C;AAAA,EACzD,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,KAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA;AAMO,SAAS,MAAA,GAAkB;AA7BlC,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,EAAA,IAAIA,WAAA,OAAe,OAAA,EAAS;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,0BAAA;AAAA,IACA,2BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,QAAQ,SAAA,EAAW;AAC5B,IAAA,IAAIC,aAAA,CAAW,IAAI,CAAA,EAAG;AACpB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI;AACF,IAAA,MAAM,UAAA,GAAaC,uBAAS,oBAAA,EAAsB;AAAA,MAChD,QAAA,EAAU,OAAA;AAAA,MACV,KAAA,EAAO,CAAC,MAAA,EAAQ,MAAA,EAAQ,MAAM;AAAA,KAC/B,CAAA;AAED,IAAA,IAAI,UAAA,CAAW,QAAA,CAAS,MAAM,CAAA,EAAG;AAC/B,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAGA,EAAA,IAAI;AACF,IAAA,IAAID,aAAA,CAAW,iBAAiB,CAAA,EAAG;AACjC,MAAA,MAAM,SAAA,GAAYE,eAAA,CAAa,iBAAA,EAAmB,OAAO,CAAA;AACzD,MAAA,IAAI,UAAU,QAAA,CAAS,QAAQ,KAAK,SAAA,CAAU,QAAA,CAAS,MAAM,CAAA,EAAG;AAC9D,QAAA,O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AAAA,EAGhB;AAEA,EAAA,OAAO,IAAA;AACT;AAgBO,SAAS,gBAAA,GAA2B;AAEzC,EAAA,MAAM,eAAe,sBAAA,EAAuB;AAC5C,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAOI,aAAQ,YAAY,CAAA;AAAA,EAC7B;AAGA,EAAA,MAAM,kBAAkB,kBAAA,EAAmB;AAC3C,EAAA,MAAM,cAAc,sBAAA,EAAuB;AAE3C,EAAA,MAAM,IAAI,sBAAA;AAAA,IACR,mDAAmD,eAAe;;AAAA,+BAAA,EAChC,WAAW,CAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,gCAAA;AAAA,GAM/C;AACF;AAmCO,SAAS,gBAAA,GAAkC;AAChD,EAAA,OAAO;AAAA,IACL,UAAU,kBAAA,EAAmB;AAAA,IAC7B,aAAa,sBAAA,EAAuB;AAAA,IACpC,YAAY,aAAA,EAAc;AAAA,IAC1B,MAAM,gBAAA;AAAiB,GACzB;AACF;AAGA,IAAO,aAAA,GAAQ;AAAA,EACb,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF","file":"index.js","sourcesContent":["import { platform, arch } from 'node:os';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\n\n/**\n * Supported platform identifiers\n */\nexport type Platform =\n | 'darwin-arm64'\n | 'darwin-x86_64'\n | 'linux-arm64'\n | 'linux-arm64-musl'\n | 'linux-x86_64'\n | 'linux-x86_64-musl'\n | 'win32-x86_64';\n\n/**\n * Binary extension for each platform\n */\nexport const PLATFORM_EXTENSIONS: Record<string, string> = {\n darwin: '.dylib',\n linux: '.so',\n win32: '.dll',\n} as const;\n\n/**\n * Detects if the system uses musl libc (Alpine Linux, etc.)\n * Uses multiple detection strategies for reliability\n */\nexport function isMusl(): boolean {\n // Only relevant for Linux\n if (platform() !== 'linux') {\n return false;\n }\n\n // Strategy 1: Check for musl-specific files\n const muslFiles = [\n '/lib/ld-musl-x86_64.so.1',\n '/lib/ld-musl-aarch64.so.1',\n '/lib/ld-musl-armhf.so.1',\n ];\n\n for (const file of muslFiles) {\n if (existsSync(file)) {\n return true;\n }\n }\n\n // Strategy 2: Check ldd version output\n try {\n const lddVersion = execSync('ldd --version 2>&1', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n if (lddVersion.includes('musl')) {\n return true;\n }\n } catch {\n // ldd command failed, continue to next strategy\n }\n\n // Strategy 3: Check /etc/os-release for Alpine\n try {\n if (existsSync('/etc/os-release')) {\n const osRelease = readFileSync('/etc/os-release', 'utf-8');\n if (osRelease.includes('Alpine') || osRelease.includes('musl')) {\n return true;\n }\n }\n } catch {\n // File read failed, continue to next strategy\n }\n\n // Strategy 4: Check process.report.getReport() for musl\n try {\n const report = (process as any).report?.getReport?.();\n if (report?.header?.glibcVersionRuntime === '') {\n // Empty glibc version often indicates musl\n return true;\n }\n } catch {\n // Report not available\n }\n\n return false;\n}\n\n/**\n * Gets the current platform identifier\n * @throws {Error} If the platform is unsupported\n */\nexport function getCurrentPlatform(): Platform {\n const platformName = platform();\n const archName = arch();\n\n // macOS\n if (platformName === 'darwin') {\n if (archName === 'arm64') return 'darwin-arm64';\n if (archName === 'x64' || archName === 'ia32') return 'darwin-x86_64';\n }\n\n // Linux (with musl detection)\n if (platformName === 'linux') {\n const muslSuffix = isMusl() ? '-musl' : '';\n\n if (archName === 'arm64') {\n return `linux-arm64${muslSuffix}` as Platform;\n }\n if (archName === 'x64' || archName === 'ia32') {\n return `linux-x86_64${muslSuffix}` as Platform;\n }\n }\n\n // Windows\n if (platformName === 'win32') {\n if (archName === 'x64' || archName === 'ia32') return 'win32-x86_64';\n }\n\n // Unsupported platform\n throw new Error(\n `Unsupported platform: ${platformName}-${archName}. ` +\n `Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 ` +\n `(with glibc or musl support for Linux)`\n );\n}\n\n/**\n * Gets the package name for the current platform\n */\nexport function getPlatformPackageName(): string {\n const currentPlatform = getCurrentPlatform();\n return `@sqliteai/sqlite-vector-${currentPlatform}`;\n}\n\n/**\n * Gets the binary filename for the current platform\n */\nexport function getBinaryName(): string {\n const platformName = platform();\n const extension = PLATFORM_EXTENSIONS[platformName];\n\n if (!extension) {\n throw new Error(`Unknown platform: ${platformName}`);\n }\n\n return `vector${extension}`;\n}\n","import { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport {\n getCurrentPlatform,\n getPlatformPackageName,\n getBinaryName,\n type Platform\n} from './platform.js';\n\n/**\n * Error thrown when the SQLite Vector extension cannot be found\n */\nexport class ExtensionNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ExtensionNotFoundError';\n }\n}\n\n/**\n * Attempts to load the platform-specific package\n * @returns The path to the extension binary, or null if not found\n */\nfunction tryLoadPlatformPackage(): string | null {\n try {\n const packageName = getPlatformPackageName();\n\n // Try to dynamically import the platform package\n // This works in both CommonJS and ESM\n const platformPackage = require(packageName);\n\n if (platformPackage?.path && typeof platformPackage.path === 'string') {\n if (existsSync(platformPackage.path)) {\n return platformPackage.path;\n }\n }\n } catch (error) {\n // Platform package not installed or failed to load\n // This is expected when optionalDependencies fail\n }\n\n return null;\n}\n\n/**\n * Gets the absolute path to the SQLite Vector extension binary for the current platform\n *\n * @returns Absolute path to the extension binary (.so, .dylib, or .dll)\n * @throws {ExtensionNotFoundError} If the extension binary cannot be found\n *\n * @example\n * ```typescript\n * import { getExtensionPath } from '@sqliteai/sqlite-vector';\n *\n * const extensionPath = getExtensionPath();\n * // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib\n * ```\n */\nexport function getExtensionPath(): string {\n // Try to load from platform-specific package\n const platformPath = tryLoadPlatformPackage();\n if (platformPath) {\n return resolve(platformPath);\n }\n\n // If we reach here, the platform package wasn't installed\n const currentPlatform = getCurrentPlatform();\n const packageName = getPlatformPackageName();\n\n throw new ExtensionNotFoundError(\n `SQLite Vector extension not found for platform: ${currentPlatform}\\n\\n` +\n `The platform-specific package \"${packageName}\" is not installed.\\n` +\n `This usually happens when:\\n` +\n ` 1. Your platform is not supported\\n` +\n ` 2. npm failed to install optional dependencies\\n` +\n ` 3. You're installing with --no-optional flag\\n\\n` +\n `Try running: npm install --force`\n );\n}\n\n/**\n * Information about the current platform and extension\n */\nexport interface ExtensionInfo {\n /** Current platform identifier (e.g., 'darwin-arm64') */\n platform: Platform;\n /** Name of the platform-specific npm package */\n packageName: string;\n /** Filename of the binary (e.g., 'vector.dylib') */\n binaryName: string;\n /** Full path to the extension binary */\n path: string;\n}\n\n/**\n * Gets detailed information about the SQLite Vector extension\n *\n * @returns Extension information object\n *\n * @example\n * ```typescript\n * import { getExtensionInfo } from '@sqliteai/sqlite-vector';\n *\n * const info = getExtensionInfo();\n * console.log(info);\n * // {\n * // platform: 'darwin-arm64',\n * // packageName: '@sqliteai/sqlite-vector-darwin-arm64',\n * // binaryName: 'vector.dylib',\n * // path: '/path/to/vector.dylib'\n * // }\n * ```\n */\nexport function getExtensionInfo(): ExtensionInfo {\n return {\n platform: getCurrentPlatform(),\n packageName: getPlatformPackageName(),\n binaryName: getBinaryName(),\n path: getExtensionPath(),\n };\n}\n\n// Default export for CommonJS compatibility\nexport default {\n getExtensionPath,\n getExtensionInfo,\n ExtensionNotFoundError,\n};\n\n// Re-export platform utilities\nexport { getCurrentPlatform, getPlatformPackageName, getBinaryName, isMusl } from './platform.js';\nexport type { Platform } from './platform.js';\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { platform, arch } from 'os';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
|
|
6
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
7
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
8
|
+
}) : x)(function(x) {
|
|
9
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
10
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
|
+
});
|
|
12
|
+
var PLATFORM_EXTENSIONS = {
|
|
13
|
+
darwin: ".dylib",
|
|
14
|
+
linux: ".so",
|
|
15
|
+
win32: ".dll"
|
|
16
|
+
};
|
|
17
|
+
function isMusl() {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
if (platform() !== "linux") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const muslFiles = [
|
|
23
|
+
"/lib/ld-musl-x86_64.so.1",
|
|
24
|
+
"/lib/ld-musl-aarch64.so.1",
|
|
25
|
+
"/lib/ld-musl-armhf.so.1"
|
|
26
|
+
];
|
|
27
|
+
for (const file of muslFiles) {
|
|
28
|
+
if (existsSync(file)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const lddVersion = execSync("ldd --version 2>&1", {
|
|
34
|
+
encoding: "utf-8",
|
|
35
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
36
|
+
});
|
|
37
|
+
if (lddVersion.includes("musl")) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
if (existsSync("/etc/os-release")) {
|
|
44
|
+
const osRelease = readFileSync("/etc/os-release", "utf-8");
|
|
45
|
+
if (osRelease.includes("Alpine") || osRelease.includes("musl")) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const report = (_b = (_a = process.report) == null ? void 0 : _a.getReport) == null ? void 0 : _b.call(_a);
|
|
53
|
+
if (((_c = report == null ? void 0 : report.header) == null ? void 0 : _c.glibcVersionRuntime) === "") {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function getCurrentPlatform() {
|
|
61
|
+
const platformName = platform();
|
|
62
|
+
const archName = arch();
|
|
63
|
+
if (platformName === "darwin") {
|
|
64
|
+
if (archName === "arm64") return "darwin-arm64";
|
|
65
|
+
if (archName === "x64" || archName === "ia32") return "darwin-x86_64";
|
|
66
|
+
}
|
|
67
|
+
if (platformName === "linux") {
|
|
68
|
+
const muslSuffix = isMusl() ? "-musl" : "";
|
|
69
|
+
if (archName === "arm64") {
|
|
70
|
+
return `linux-arm64${muslSuffix}`;
|
|
71
|
+
}
|
|
72
|
+
if (archName === "x64" || archName === "ia32") {
|
|
73
|
+
return `linux-x86_64${muslSuffix}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (platformName === "win32") {
|
|
77
|
+
if (archName === "x64" || archName === "ia32") return "win32-x86_64";
|
|
78
|
+
}
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Unsupported platform: ${platformName}-${archName}. Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 (with glibc or musl support for Linux)`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function getPlatformPackageName() {
|
|
84
|
+
const currentPlatform = getCurrentPlatform();
|
|
85
|
+
return `@sqliteai/sqlite-vector-${currentPlatform}`;
|
|
86
|
+
}
|
|
87
|
+
function getBinaryName() {
|
|
88
|
+
const platformName = platform();
|
|
89
|
+
const extension = PLATFORM_EXTENSIONS[platformName];
|
|
90
|
+
if (!extension) {
|
|
91
|
+
throw new Error(`Unknown platform: ${platformName}`);
|
|
92
|
+
}
|
|
93
|
+
return `vector${extension}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/index.ts
|
|
97
|
+
var ExtensionNotFoundError = class extends Error {
|
|
98
|
+
constructor(message) {
|
|
99
|
+
super(message);
|
|
100
|
+
this.name = "ExtensionNotFoundError";
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
function tryLoadPlatformPackage() {
|
|
104
|
+
try {
|
|
105
|
+
const packageName = getPlatformPackageName();
|
|
106
|
+
const platformPackage = __require(packageName);
|
|
107
|
+
if ((platformPackage == null ? void 0 : platformPackage.path) && typeof platformPackage.path === "string") {
|
|
108
|
+
if (existsSync(platformPackage.path)) {
|
|
109
|
+
return platformPackage.path;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function getExtensionPath() {
|
|
117
|
+
const platformPath = tryLoadPlatformPackage();
|
|
118
|
+
if (platformPath) {
|
|
119
|
+
return resolve(platformPath);
|
|
120
|
+
}
|
|
121
|
+
const currentPlatform = getCurrentPlatform();
|
|
122
|
+
const packageName = getPlatformPackageName();
|
|
123
|
+
throw new ExtensionNotFoundError(
|
|
124
|
+
`SQLite Vector extension not found for platform: ${currentPlatform}
|
|
125
|
+
|
|
126
|
+
The platform-specific package "${packageName}" is not installed.
|
|
127
|
+
This usually happens when:
|
|
128
|
+
1. Your platform is not supported
|
|
129
|
+
2. npm failed to install optional dependencies
|
|
130
|
+
3. You're installing with --no-optional flag
|
|
131
|
+
|
|
132
|
+
Try running: npm install --force`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function getExtensionInfo() {
|
|
136
|
+
return {
|
|
137
|
+
platform: getCurrentPlatform(),
|
|
138
|
+
packageName: getPlatformPackageName(),
|
|
139
|
+
binaryName: getBinaryName(),
|
|
140
|
+
path: getExtensionPath()
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var index_default = {
|
|
144
|
+
getExtensionPath,
|
|
145
|
+
getExtensionInfo,
|
|
146
|
+
ExtensionNotFoundError
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export { ExtensionNotFoundError, index_default as default, getBinaryName, getCurrentPlatform, getExtensionInfo, getExtensionPath, getPlatformPackageName, isMusl };
|
|
150
|
+
//# sourceMappingURL=index.mjs.map
|
|
151
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platform.ts","../src/index.ts"],"names":["existsSync"],"mappings":";;;;;;;;;;;AAmBO,IAAM,mBAAA,GAA8C;AAAA,EACzD,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,KAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA;AAMO,SAAS,MAAA,GAAkB;AA7BlC,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,EAAA,IAAI,QAAA,OAAe,OAAA,EAAS;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,0BAAA;AAAA,IACA,2BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,QAAQ,SAAA,EAAW;AAC5B,IAAA,IAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACpB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI;AACF,IAAA,MAAM,UAAA,GAAa,SAAS,oBAAA,EAAsB;AAAA,MAChD,QAAA,EAAU,OAAA;AAAA,MACV,KAAA,EAAO,CAAC,MAAA,EAAQ,MAAA,EAAQ,MAAM;AAAA,KAC/B,CAAA;AAED,IAAA,IAAI,UAAA,CAAW,QAAA,CAAS,MAAM,CAAA,EAAG;AAC/B,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAGA,EAAA,IAAI;AACF,IAAA,IAAI,UAAA,CAAW,iBAAiB,CAAA,EAAG;AACjC,MAAA,MAAM,SAAA,GAAY,YAAA,CAAa,iBAAA,EAAmB,OAAO,CAAA;AACzD,MAAA,IAAI,UAAU,QAAA,CAAS,QAAQ,KAAK,SAAA,CAAU,QAAA,CAAS,MAAM,CAAA,EAAG;AAC9D,Q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;AAAA,EAGhB;AAEA,EAAA,OAAO,IAAA;AACT;AAgBO,SAAS,gBAAA,GAA2B;AAEzC,EAAA,MAAM,eAAe,sBAAA,EAAuB;AAC5C,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAO,QAAQ,YAAY,CAAA;AAAA,EAC7B;AAGA,EAAA,MAAM,kBAAkB,kBAAA,EAAmB;AAC3C,EAAA,MAAM,cAAc,sBAAA,EAAuB;AAE3C,EAAA,MAAM,IAAI,sBAAA;AAAA,IACR,mDAAmD,eAAe;;AAAA,+BAAA,EAChC,WAAW,CAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,gCAAA;AAAA,GAM/C;AACF;AAmCO,SAAS,gBAAA,GAAkC;AAChD,EAAA,OAAO;AAAA,IACL,UAAU,kBAAA,EAAmB;AAAA,IAC7B,aAAa,sBAAA,EAAuB;AAAA,IACpC,YAAY,aAAA,EAAc;AAAA,IAC1B,MAAM,gBAAA;AAAiB,GACzB;AACF;AAGA,IAAO,aAAA,GAAQ;AAAA,EACb,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF","file":"index.mjs","sourcesContent":["import { platform, arch } from 'node:os';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\n\n/**\n * Supported platform identifiers\n */\nexport type Platform =\n | 'darwin-arm64'\n | 'darwin-x86_64'\n | 'linux-arm64'\n | 'linux-arm64-musl'\n | 'linux-x86_64'\n | 'linux-x86_64-musl'\n | 'win32-x86_64';\n\n/**\n * Binary extension for each platform\n */\nexport const PLATFORM_EXTENSIONS: Record<string, string> = {\n darwin: '.dylib',\n linux: '.so',\n win32: '.dll',\n} as const;\n\n/**\n * Detects if the system uses musl libc (Alpine Linux, etc.)\n * Uses multiple detection strategies for reliability\n */\nexport function isMusl(): boolean {\n // Only relevant for Linux\n if (platform() !== 'linux') {\n return false;\n }\n\n // Strategy 1: Check for musl-specific files\n const muslFiles = [\n '/lib/ld-musl-x86_64.so.1',\n '/lib/ld-musl-aarch64.so.1',\n '/lib/ld-musl-armhf.so.1',\n ];\n\n for (const file of muslFiles) {\n if (existsSync(file)) {\n return true;\n }\n }\n\n // Strategy 2: Check ldd version output\n try {\n const lddVersion = execSync('ldd --version 2>&1', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n if (lddVersion.includes('musl')) {\n return true;\n }\n } catch {\n // ldd command failed, continue to next strategy\n }\n\n // Strategy 3: Check /etc/os-release for Alpine\n try {\n if (existsSync('/etc/os-release')) {\n const osRelease = readFileSync('/etc/os-release', 'utf-8');\n if (osRelease.includes('Alpine') || osRelease.includes('musl')) {\n return true;\n }\n }\n } catch {\n // File read failed, continue to next strategy\n }\n\n // Strategy 4: Check process.report.getReport() for musl\n try {\n const report = (process as any).report?.getReport?.();\n if (report?.header?.glibcVersionRuntime === '') {\n // Empty glibc version often indicates musl\n return true;\n }\n } catch {\n // Report not available\n }\n\n return false;\n}\n\n/**\n * Gets the current platform identifier\n * @throws {Error} If the platform is unsupported\n */\nexport function getCurrentPlatform(): Platform {\n const platformName = platform();\n const archName = arch();\n\n // macOS\n if (platformName === 'darwin') {\n if (archName === 'arm64') return 'darwin-arm64';\n if (archName === 'x64' || archName === 'ia32') return 'darwin-x86_64';\n }\n\n // Linux (with musl detection)\n if (platformName === 'linux') {\n const muslSuffix = isMusl() ? '-musl' : '';\n\n if (archName === 'arm64') {\n return `linux-arm64${muslSuffix}` as Platform;\n }\n if (archName === 'x64' || archName === 'ia32') {\n return `linux-x86_64${muslSuffix}` as Platform;\n }\n }\n\n // Windows\n if (platformName === 'win32') {\n if (archName === 'x64' || archName === 'ia32') return 'win32-x86_64';\n }\n\n // Unsupported platform\n throw new Error(\n `Unsupported platform: ${platformName}-${archName}. ` +\n `Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 ` +\n `(with glibc or musl support for Linux)`\n );\n}\n\n/**\n * Gets the package name for the current platform\n */\nexport function getPlatformPackageName(): string {\n const currentPlatform = getCurrentPlatform();\n return `@sqliteai/sqlite-vector-${currentPlatform}`;\n}\n\n/**\n * Gets the binary filename for the current platform\n */\nexport function getBinaryName(): string {\n const platformName = platform();\n const extension = PLATFORM_EXTENSIONS[platformName];\n\n if (!extension) {\n throw new Error(`Unknown platform: ${platformName}`);\n }\n\n return `vector${extension}`;\n}\n","import { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport {\n getCurrentPlatform,\n getPlatformPackageName,\n getBinaryName,\n type Platform\n} from './platform.js';\n\n/**\n * Error thrown when the SQLite Vector extension cannot be found\n */\nexport class ExtensionNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ExtensionNotFoundError';\n }\n}\n\n/**\n * Attempts to load the platform-specific package\n * @returns The path to the extension binary, or null if not found\n */\nfunction tryLoadPlatformPackage(): string | null {\n try {\n const packageName = getPlatformPackageName();\n\n // Try to dynamically import the platform package\n // This works in both CommonJS and ESM\n const platformPackage = require(packageName);\n\n if (platformPackage?.path && typeof platformPackage.path === 'string') {\n if (existsSync(platformPackage.path)) {\n return platformPackage.path;\n }\n }\n } catch (error) {\n // Platform package not installed or failed to load\n // This is expected when optionalDependencies fail\n }\n\n return null;\n}\n\n/**\n * Gets the absolute path to the SQLite Vector extension binary for the current platform\n *\n * @returns Absolute path to the extension binary (.so, .dylib, or .dll)\n * @throws {ExtensionNotFoundError} If the extension binary cannot be found\n *\n * @example\n * ```typescript\n * import { getExtensionPath } from '@sqliteai/sqlite-vector';\n *\n * const extensionPath = getExtensionPath();\n * // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib\n * ```\n */\nexport function getExtensionPath(): string {\n // Try to load from platform-specific package\n const platformPath = tryLoadPlatformPackage();\n if (platformPath) {\n return resolve(platformPath);\n }\n\n // If we reach here, the platform package wasn't installed\n const currentPlatform = getCurrentPlatform();\n const packageName = getPlatformPackageName();\n\n throw new ExtensionNotFoundError(\n `SQLite Vector extension not found for platform: ${currentPlatform}\\n\\n` +\n `The platform-specific package \"${packageName}\" is not installed.\\n` +\n `This usually happens when:\\n` +\n ` 1. Your platform is not supported\\n` +\n ` 2. npm failed to install optional dependencies\\n` +\n ` 3. You're installing with --no-optional flag\\n\\n` +\n `Try running: npm install --force`\n );\n}\n\n/**\n * Information about the current platform and extension\n */\nexport interface ExtensionInfo {\n /** Current platform identifier (e.g., 'darwin-arm64') */\n platform: Platform;\n /** Name of the platform-specific npm package */\n packageName: string;\n /** Filename of the binary (e.g., 'vector.dylib') */\n binaryName: string;\n /** Full path to the extension binary */\n path: string;\n}\n\n/**\n * Gets detailed information about the SQLite Vector extension\n *\n * @returns Extension information object\n *\n * @example\n * ```typescript\n * import { getExtensionInfo } from '@sqliteai/sqlite-vector';\n *\n * const info = getExtensionInfo();\n * console.log(info);\n * // {\n * // platform: 'darwin-arm64',\n * // packageName: '@sqliteai/sqlite-vector-darwin-arm64',\n * // binaryName: 'vector.dylib',\n * // path: '/path/to/vector.dylib'\n * // }\n * ```\n */\nexport function getExtensionInfo(): ExtensionInfo {\n return {\n platform: getCurrentPlatform(),\n packageName: getPlatformPackageName(),\n binaryName: getBinaryName(),\n path: getExtensionPath(),\n };\n}\n\n// Default export for CommonJS compatibility\nexport default {\n getExtensionPath,\n getExtensionInfo,\n ExtensionNotFoundError,\n};\n\n// Re-export platform utilities\nexport { getCurrentPlatform, getPlatformPackageName, getBinaryName, isMusl } from './platform.js';\nexport type { Platform } from './platform.js';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sqliteai/sqlite-vector",
|
|
3
|
+
"version": "0.9.45",
|
|
4
|
+
"description": "SQLite vector search extension for Node.js - Cross-platform vector embeddings and similarity search",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"test": "vitest",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"generate-platforms": "node generate-platform-packages.js"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"sqlite",
|
|
34
|
+
"vector",
|
|
35
|
+
"embedding",
|
|
36
|
+
"ai",
|
|
37
|
+
"machine-learning",
|
|
38
|
+
"similarity-search",
|
|
39
|
+
"semantic-search",
|
|
40
|
+
"vector-database",
|
|
41
|
+
"sqlite-extension"
|
|
42
|
+
],
|
|
43
|
+
"author": "Gioele Cantoni (gioele@sqlitecloud.io)",
|
|
44
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/sqliteai/sqlite-vector.git",
|
|
48
|
+
"directory": "packages/node"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/sqliteai/sqlite-vector#readme",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/sqliteai/sqlite-vector/issues"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=16.0.0"
|
|
56
|
+
},
|
|
57
|
+
"optionalDependencies": {
|
|
58
|
+
"@sqliteai/sqlite-vector-darwin-arm64": "0.9.45",
|
|
59
|
+
"@sqliteai/sqlite-vector-darwin-x86_64": "0.9.45",
|
|
60
|
+
"@sqliteai/sqlite-vector-linux-arm64": "0.9.45",
|
|
61
|
+
"@sqliteai/sqlite-vector-linux-arm64-musl": "0.9.45",
|
|
62
|
+
"@sqliteai/sqlite-vector-linux-x86_64": "0.9.45",
|
|
63
|
+
"@sqliteai/sqlite-vector-linux-x86_64-musl": "0.9.45",
|
|
64
|
+
"@sqliteai/sqlite-vector-win32-x86_64": "0.9.45"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^20.0.0",
|
|
68
|
+
"tsup": "^8.0.0",
|
|
69
|
+
"typescript": "^5.3.0",
|
|
70
|
+
"vitest": "^3.2.4"
|
|
71
|
+
}
|
|
72
|
+
}
|