native-vector-store 0.3.4 → 0.3.6

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 CHANGED
@@ -33,6 +33,8 @@ This design eliminates complex state management, ensures consistent performance,
33
33
  - **Scalability**: Designed for focused corpora (<100k documents optimal, <1M maximum)
34
34
  - **Throughput**: 178k+ documents per second with parallel loading
35
35
 
36
+ 📊 **[Production Case Study](docs/PRODUCTION_CASE_STUDY.md)**: Real-world deployment with 65k documents (1.5GB) on AWS Lambda achieving 15-20s cold start and 40-45ms search latency.
37
+
36
38
  ## Installation
37
39
 
38
40
  ```bash
@@ -49,7 +51,7 @@ npm install native-vector-store
49
51
  - **Windows**: Included with Visual C++ runtime
50
52
 
51
53
  Prebuilt binaries are included for:
52
- - Linux (x64, arm64, musl/Alpine)
54
+ - Linux (x64, arm64, musl/Alpine) - x64 builds are AWS Lambda compatible (no AVX-512)
53
55
  - macOS (x64, arm64/Apple Silicon)
54
56
  - Windows (x64)
55
57
 
@@ -86,7 +88,23 @@ store.finalize(); // Must call before searching!
86
88
  const queryEmbedding = new Float32Array(1536);
87
89
  const results = store.search(queryEmbedding, 5); // Top 5 results
88
90
 
89
- console.log(results[0]); // { score: 0.95, id: 'doc-1', text: '...', metadata_json: '...' }
91
+ // Results format - array of SearchResult objects, sorted by score (highest first):
92
+ console.log(results);
93
+ // [
94
+ // {
95
+ // score: 0.987654, // Similarity score (0-1, higher = more similar)
96
+ // id: "doc-1", // Your document ID
97
+ // text: "Example document...", // Full document text
98
+ // metadata_json: "{\"embedding\":[0.1,0.2,...],\"category\":\"example\"}" // JSON string
99
+ // },
100
+ // { score: 0.943210, id: "doc-7", text: "Another doc...", metadata_json: "..." },
101
+ // // ... up to 5 results
102
+ // ]
103
+
104
+ // Parse metadata from the top result
105
+ const topResult = results[0];
106
+ const metadata = JSON.parse(topResult.metadata_json);
107
+ console.log(metadata.category); // "example"
90
108
  ```
91
109
 
92
110
  ## Usage Patterns
@@ -314,15 +332,32 @@ interface Document {
314
332
  ```
315
333
 
316
334
  ##### `search(query: Float32Array, k: number, normalizeQuery?: boolean): SearchResult[]`
317
- Search for k most similar documents.
335
+ Search for k most similar documents. Returns an array sorted by score (highest first).
318
336
 
319
337
  ```typescript
320
338
  interface SearchResult {
321
- score: number;
322
- id: string;
323
- text: string;
324
- metadata_json: string;
339
+ score: number; // Cosine similarity (0-1, higher = more similar)
340
+ id: string; // Document ID
341
+ text: string; // Document text content
342
+ metadata_json: string; // JSON string with all metadata including embedding
325
343
  }
344
+
345
+ // Example return value:
346
+ [
347
+ {
348
+ score: 0.98765,
349
+ id: "doc-123",
350
+ text: "Introduction to machine learning...",
351
+ metadata_json: "{\"embedding\":[0.1,0.2,...],\"author\":\"Jane Doe\",\"tags\":[\"ML\",\"intro\"]}"
352
+ },
353
+ {
354
+ score: 0.94321,
355
+ id: "doc-456",
356
+ text: "Deep learning fundamentals...",
357
+ metadata_json: "{\"embedding\":[0.3,0.4,...],\"difficulty\":\"intermediate\"}"
358
+ }
359
+ // ... more results
360
+ ]
326
361
  ```
327
362
 
328
363
  ##### `finalize(): void`
@@ -356,7 +391,9 @@ Performance on typical hardware (M1 MacBook Pro):
356
391
  | Operation | Documents | Time | Throughput |
357
392
  |-----------|-----------|------|------------|
358
393
  | Loading (from disk) | 100,000 | ~560ms | 178k docs/sec |
394
+ | Loading (production) | 65,000 | 15-20s | 3.2-4.3k docs/sec |
359
395
  | Search (k=10) | 10,000 corpus | 1-2ms | 500-1000 queries/sec |
396
+ | Search (k=10) | 65,000 corpus | 40-45ms | 20-25 queries/sec |
360
397
  | Search (k=100) | 100,000 corpus | 8-12ms | 80-125 queries/sec |
361
398
  | Normalization | 100,000 | <100ms | 1M+ docs/sec |
362
399
 
package/binding.gyp CHANGED
@@ -13,7 +13,6 @@
13
13
  "cflags_cc": [
14
14
  "-std=c++17",
15
15
  "-O3",
16
- "-march=native",
17
16
  "-fno-exceptions"
18
17
  ],
19
18
  "defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
@@ -37,7 +36,16 @@
37
36
  ]
38
37
  }],
39
38
  ["OS=='linux'", {
40
- "cflags_cc": ["-fopenmp"],
39
+ "cflags_cc": [
40
+ "-fopenmp",
41
+ # AWS Lambda compatibility: target x86-64-v3 (up to AVX2) but no AVX-512
42
+ "-march=x86-64-v3",
43
+ "-mno-avx512f",
44
+ "-mno-avx512cd",
45
+ "-mno-avx512bw",
46
+ "-mno-avx512dq",
47
+ "-mno-avx512vl"
48
+ ],
41
49
  "libraries": ["-lgomp"]
42
50
  }],
43
51
  ["OS=='win'", {
package/docs/index.html CHANGED
@@ -73,6 +73,7 @@
73
73
  <li><strong>Scalability</strong>: Designed for focused corpora (&lt;100k documents optimal, &lt;1M maximum)</li>
74
74
  <li><strong>Throughput</strong>: 178k+ documents per second with parallel loading</li>
75
75
  </ul>
76
+ <p>📊 <strong><a href="docs/PRODUCTION_CASE_STUDY.md">Production Case Study</a></strong>: Real-world deployment with 65k documents (1.5GB) on AWS Lambda achieving 15-20s cold start and 40-45ms search latency.</p>
76
77
  <h2 id="installation">Installation</h2>
77
78
  <pre class="prettyprint source lang-bash"><code>npm install native-vector-store
78
79
  </code></pre>
@@ -90,7 +91,7 @@
90
91
  </ul>
91
92
  <p>Prebuilt binaries are included for:</p>
92
93
  <ul>
93
- <li>Linux (x64, arm64, musl/Alpine)</li>
94
+ <li>Linux (x64, arm64, musl/Alpine) - x64 builds are AWS Lambda compatible (no AVX-512)</li>
94
95
  <li>macOS (x64, arm64/Apple Silicon)</li>
95
96
  <li>Windows (x64)</li>
96
97
  </ul>
@@ -126,7 +127,23 @@ store.finalize(); // Must call before searching!
126
127
  const queryEmbedding = new Float32Array(1536);
127
128
  const results = store.search(queryEmbedding, 5); // Top 5 results
128
129
 
129
- console.log(results[0]); // { score: 0.95, id: 'doc-1', text: '...', metadata_json: '...' }
130
+ // Results format - array of SearchResult objects, sorted by score (highest first):
131
+ console.log(results);
132
+ // [
133
+ // {
134
+ // score: 0.987654, // Similarity score (0-1, higher = more similar)
135
+ // id: &quot;doc-1&quot;, // Your document ID
136
+ // text: &quot;Example document...&quot;, // Full document text
137
+ // metadata_json: &quot;{\&quot;embedding\&quot;:[0.1,0.2,...],\&quot;category\&quot;:\&quot;example\&quot;}&quot; // JSON string
138
+ // },
139
+ // { score: 0.943210, id: &quot;doc-7&quot;, text: &quot;Another doc...&quot;, metadata_json: &quot;...&quot; },
140
+ // // ... up to 5 results
141
+ // ]
142
+
143
+ // Parse metadata from the top result
144
+ const topResult = results[0];
145
+ const metadata = JSON.parse(topResult.metadata_json);
146
+ console.log(metadata.category); // &quot;example&quot;
130
147
  </code></pre>
131
148
  <h2 id="usage-patterns">Usage Patterns</h2>
132
149
  <h3 id="serverless-deployment-(aws-lambda%2C-vercel)">Serverless Deployment (AWS Lambda, Vercel)</h3>
@@ -309,13 +326,30 @@ const response = await server.handleMCPRequest('vector_search', {
309
326
  }
310
327
  </code></pre>
311
328
  <h5 id="search(query%3A-float32array%2C-k%3A-number%2C-normalizequery%3F%3A-boolean)%3A-searchresult%5B%5D"><code>search(query: Float32Array, k: number, normalizeQuery?: boolean): SearchResult[]</code></h5>
312
- <p>Search for k most similar documents.</p>
329
+ <p>Search for k most similar documents. Returns an array sorted by score (highest first).</p>
313
330
  <pre class="prettyprint source lang-typescript"><code>interface SearchResult {
314
- score: number;
315
- id: string;
316
- text: string;
317
- metadata_json: string;
331
+ score: number; // Cosine similarity (0-1, higher = more similar)
332
+ id: string; // Document ID
333
+ text: string; // Document text content
334
+ metadata_json: string; // JSON string with all metadata including embedding
318
335
  }
336
+
337
+ // Example return value:
338
+ [
339
+ {
340
+ score: 0.98765,
341
+ id: &quot;doc-123&quot;,
342
+ text: &quot;Introduction to machine learning...&quot;,
343
+ metadata_json: &quot;{\&quot;embedding\&quot;:[0.1,0.2,...],\&quot;author\&quot;:\&quot;Jane Doe\&quot;,\&quot;tags\&quot;:[\&quot;ML\&quot;,\&quot;intro\&quot;]}&quot;
344
+ },
345
+ {
346
+ score: 0.94321,
347
+ id: &quot;doc-456&quot;,
348
+ text: &quot;Deep learning fundamentals...&quot;,
349
+ metadata_json: &quot;{\&quot;embedding\&quot;:[0.3,0.4,...],\&quot;difficulty\&quot;:\&quot;intermediate\&quot;}&quot;
350
+ }
351
+ // ... more results
352
+ ]
319
353
  </code></pre>
320
354
  <h5 id="finalize()%3A-void"><code>finalize(): void</code></h5>
321
355
  <p>Finalize the store: normalize all embeddings and switch to serving mode. After this, no more documents can be added but searches become available. This is automatically called by <code>loadDir()</code>.</p>
@@ -354,12 +388,24 @@ const response = await server.handleMCPRequest('vector_search', {
354
388
  <td>178k docs/sec</td>
355
389
  </tr>
356
390
  <tr>
391
+ <td>Loading (production)</td>
392
+ <td>65,000</td>
393
+ <td>15-20s</td>
394
+ <td>3.2-4.3k docs/sec</td>
395
+ </tr>
396
+ <tr>
357
397
  <td>Search (k=10)</td>
358
398
  <td>10,000 corpus</td>
359
399
  <td>1-2ms</td>
360
400
  <td>500-1000 queries/sec</td>
361
401
  </tr>
362
402
  <tr>
403
+ <td>Search (k=10)</td>
404
+ <td>65,000 corpus</td>
405
+ <td>40-45ms</td>
406
+ <td>20-25 queries/sec</td>
407
+ </tr>
408
+ <tr>
363
409
  <td>Search (k=100)</td>
364
410
  <td>100,000 corpus</td>
365
411
  <td>8-12ms</td>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-vector-store",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "High-performance local vector store with SIMD optimization for MCP servers",
5
5
  "main": "index.js",
6
6
  "types": "lib/index.d.ts",