omendb 0.0.1

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 ADDED
@@ -0,0 +1,82 @@
1
+ # omendb
2
+
3
+ Fast embedded vector database with HNSW indexing for Node.js and Bun.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install omendb
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { open } from "omendb";
15
+
16
+ // Open or create a database
17
+ const db = open("./vectors", { dimensions: 384 });
18
+
19
+ // Insert vectors
20
+ db.set([
21
+ {
22
+ id: "doc1",
23
+ embedding: new Float32Array(384).fill(0.1),
24
+ metadata: { title: "Hello" },
25
+ },
26
+ {
27
+ id: "doc2",
28
+ embedding: new Float32Array(384).fill(0.2),
29
+ metadata: { title: "World" },
30
+ },
31
+ ]);
32
+
33
+ // Search
34
+ const results = db.search(new Float32Array(384).fill(0.15), { k: 5 });
35
+ console.log(results);
36
+ // [{ id: 'doc1', distance: 0.05, metadata: { title: 'Hello' } }, ...]
37
+
38
+ // Batch search (async, parallel)
39
+ const batchResults = await db.searchBatch(queries, { k: 10 });
40
+ ```
41
+
42
+ ## Features
43
+
44
+ - HNSW indexing for fast approximate nearest neighbor search
45
+ - ACORN-1 filtered search
46
+ - RaBitQ compression (2/4/8-bit quantization)
47
+ - Collections for multi-tenancy
48
+ - Persistent storage with auto-save
49
+ - Works with Node.js 18+ and Bun
50
+
51
+ ## API
52
+
53
+ ### `open(path, options?)`
54
+
55
+ Open or create a vector database.
56
+
57
+ - `path`: Database directory path
58
+ - `options.dimensions`: Vector dimensionality (default: 128)
59
+
60
+ ### `db.set(items)`
61
+
62
+ Insert or update vectors.
63
+
64
+ ### `db.search(query, options)`
65
+
66
+ Search for k nearest neighbors (sync).
67
+
68
+ ### `db.searchBatch(queries, options)`
69
+
70
+ Batch search with parallel execution (async).
71
+
72
+ ### `db.get(id)`
73
+
74
+ Get a vector by ID.
75
+
76
+ ### `db.delete(ids)`
77
+
78
+ Delete vectors by ID.
79
+
80
+ ## License
81
+
82
+ Apache-2.0
package/index.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare class VectorDatabase {
4
+ /**
5
+ * Insert or update vectors.
6
+ *
7
+ * Accepts an array of items with id, embedding, and optional metadata.
8
+ */
9
+ set(items: Array<VectorItem>): Array<number>
10
+ /**
11
+ * Search for k nearest neighbors.
12
+ *
13
+ * @param query - Query vector (number[] or Float32Array)
14
+ * @param k - Number of results to return
15
+ * @param ef - Optional search width override
16
+ * @returns Array of {id, distance, metadata}
17
+ */
18
+ search(query: Array<number> | Float32Array, k: number, ef?: number | undefined | null): Array<SearchResult>
19
+ /**
20
+ * Batch search with parallel execution (async).
21
+ *
22
+ * Runs searches in parallel using rayon, returns Promise.
23
+ */
24
+ searchBatch(queries: Array<Array<number> | Float32Array>, k: number, ef?: number | undefined | null): Promise<Array<Array<SearchResult>>>
25
+ /** Get a vector by ID. */
26
+ get(id: string): GetResult | null
27
+ /**
28
+ * Delete vectors by ID.
29
+ *
30
+ * @returns Number of vectors deleted
31
+ */
32
+ delete(ids: Array<string>): number
33
+ /** Update a vector's embedding and/or metadata. */
34
+ update(id: string, embedding: Array<number> | Float32Array, metadata?: Record<string, unknown> | undefined): void
35
+ /** Save database to disk. */
36
+ save(): void
37
+ /** Get number of vectors in database. */
38
+ get count(): number
39
+ /** Get current ef_search value. */
40
+ get efSearch(): number | null
41
+ /** Set ef_search value. */
42
+ set efSearch(efSearch: number)
43
+ /** Get or create a named collection. */
44
+ collection(name: string): VectorDatabase
45
+ /** List all collections. */
46
+ collections(): Array<string>
47
+ /** Delete a collection. */
48
+ deleteCollection(name: string): void
49
+ /** Merge another database into this one. */
50
+ mergeFrom(other: VectorDatabase): number
51
+ }
52
+
53
+ export interface GetResult {
54
+ id: string
55
+ embedding: Array<number>
56
+ metadata: Record<string, unknown>
57
+ }
58
+
59
+ /**
60
+ * Open or create a vector database.
61
+ *
62
+ * @param path - Database directory path (use ":memory:" for in-memory)
63
+ * @param options - Optional configuration
64
+ * @returns VectorDatabase instance
65
+ */
66
+ export declare function open(path: string, options?: OpenOptions | undefined | null): VectorDatabase
67
+
68
+ export interface OpenOptions {
69
+ dimensions?: number
70
+ m?: number
71
+ efConstruction?: number
72
+ }
73
+
74
+ export interface SearchResult {
75
+ id: string
76
+ distance: number
77
+ /** Metadata as JSON (using serde-json feature) */
78
+ metadata: Record<string, unknown>
79
+ }
80
+
81
+ export interface VectorItem {
82
+ id: string
83
+ /** Embedding as array of numbers */
84
+ embedding: Array<number>
85
+ /** Optional metadata */
86
+ metadata?: Record<string, unknown> | undefined
87
+ /** Optional document text (stored in metadata.document) */
88
+ document?: string
89
+ }
package/index.js ADDED
@@ -0,0 +1,107 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ const { existsSync, readFileSync } = require("fs");
6
+ const { join } = require("path");
7
+
8
+ const { platform, arch } = process;
9
+
10
+ let nativeBinding = null;
11
+ let localFileExisted = false;
12
+ let loadError = null;
13
+
14
+ function isMusl() {
15
+ // For Node 10
16
+ if (!process.report || typeof process.report.getReport !== "function") {
17
+ try {
18
+ const lddPath = require("child_process")
19
+ .execSync("which ldd")
20
+ .toString()
21
+ .trim();
22
+ return readFileSync(lddPath, "utf8").includes("musl");
23
+ } catch {
24
+ return true;
25
+ }
26
+ } else {
27
+ const { glibcVersionRuntime } = process.report.getReport().header;
28
+ return !glibcVersionRuntime;
29
+ }
30
+ }
31
+
32
+ switch (platform) {
33
+ case "darwin":
34
+ localFileExisted = existsSync(join(__dirname, "omendb.node"));
35
+ try {
36
+ if (localFileExisted) {
37
+ nativeBinding = require("./omendb.node");
38
+ } else {
39
+ if (arch === "x64") {
40
+ nativeBinding = require("@omendb/darwin-x64");
41
+ } else if (arch === "arm64") {
42
+ nativeBinding = require("@omendb/darwin-arm64");
43
+ } else {
44
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
45
+ }
46
+ }
47
+ } catch (e) {
48
+ loadError = e;
49
+ }
50
+ break;
51
+ case "linux":
52
+ localFileExisted = existsSync(join(__dirname, "omendb.node"));
53
+ try {
54
+ if (localFileExisted) {
55
+ nativeBinding = require("./omendb.node");
56
+ } else if (isMusl()) {
57
+ if (arch === "x64") {
58
+ nativeBinding = require("@omendb/linux-x64-musl");
59
+ } else if (arch === "arm64") {
60
+ nativeBinding = require("@omendb/linux-arm64-musl");
61
+ } else {
62
+ throw new Error(`Unsupported architecture on Linux musl: ${arch}`);
63
+ }
64
+ } else {
65
+ if (arch === "x64") {
66
+ nativeBinding = require("@omendb/linux-x64-gnu");
67
+ } else if (arch === "arm64") {
68
+ nativeBinding = require("@omendb/linux-arm64-gnu");
69
+ } else {
70
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
71
+ }
72
+ }
73
+ } catch (e) {
74
+ loadError = e;
75
+ }
76
+ break;
77
+ case "win32":
78
+ localFileExisted = existsSync(join(__dirname, "omendb.node"));
79
+ try {
80
+ if (localFileExisted) {
81
+ nativeBinding = require("./omendb.node");
82
+ } else {
83
+ if (arch === "x64") {
84
+ nativeBinding = require("@omendb/win32-x64-msvc");
85
+ } else {
86
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
87
+ }
88
+ }
89
+ } catch (e) {
90
+ loadError = e;
91
+ }
92
+ break;
93
+ default:
94
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
95
+ }
96
+
97
+ if (!nativeBinding) {
98
+ if (loadError) {
99
+ throw loadError;
100
+ }
101
+ throw new Error(`Failed to load native binding`);
102
+ }
103
+
104
+ const { VectorDatabase, open } = nativeBinding;
105
+
106
+ module.exports.VectorDatabase = VectorDatabase;
107
+ module.exports.open = open;
package/omendb.node ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "omendb",
3
+ "version": "0.0.1",
4
+ "description": "Fast embedded vector database with HNSW indexing",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/nijaru/omendb"
10
+ },
11
+ "keywords": [
12
+ "vector",
13
+ "database",
14
+ "embeddings",
15
+ "hnsw",
16
+ "similarity-search",
17
+ "ai",
18
+ "machine-learning",
19
+ "napi-rs",
20
+ "rust"
21
+ ],
22
+ "author": "Nick Jaru",
23
+ "license": "Apache-2.0",
24
+ "engines": {
25
+ "node": ">= 18"
26
+ },
27
+ "napi": {
28
+ "binaryName": "omendb",
29
+ "targets": [
30
+ "x86_64-apple-darwin",
31
+ "aarch64-apple-darwin",
32
+ "x86_64-unknown-linux-gnu",
33
+ "aarch64-unknown-linux-gnu",
34
+ "x86_64-pc-windows-msvc"
35
+ ]
36
+ },
37
+ "scripts": {
38
+ "build": "napi build --release",
39
+ "build:debug": "napi build",
40
+ "test": "vitest run",
41
+ "prepublishOnly": "napi prepublish -t npm"
42
+ },
43
+ "devDependencies": {
44
+ "@napi-rs/cli": "^3.0.0-alpha.65",
45
+ "vitest": "^2.1.0"
46
+ },
47
+ "files": [
48
+ "index.js",
49
+ "index.d.ts",
50
+ "omendb.node"
51
+ ],
52
+ "optionalDependencies": {
53
+ "omendb-darwin-x64": "0.0.1",
54
+ "omendb-darwin-arm64": "0.0.1",
55
+ "omendb-linux-x64-gnu": "0.0.1",
56
+ "omendb-linux-arm64-gnu": "0.0.1",
57
+ "omendb-win32-x64-msvc": "0.0.1"
58
+ }
59
+ }