native-vector-store 0.1.0
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/LICENSE +201 -0
- package/README.md +223 -0
- package/binding.gyp +45 -0
- package/index.js +3 -0
- package/lib/index.d.ts +60 -0
- package/native-vector-store-0.1.0.tgz +0 -0
- package/package.json +52 -0
- package/prebuilds/darwin-arm64/native-vector-store.node +0 -0
- package/scripts/build-prebuilds.sh +23 -0
- package/src/atomic_queue.h +646 -0
- package/src/binding.cc +151 -0
- package/src/defs.h +107 -0
- package/src/mmap_file.h +159 -0
- package/src/vector_store.h +401 -0
- package/src/vector_store_loader.cpp +176 -0
- package/src/vector_store_loader.h +19 -0
- package/src/vector_store_loader_adaptive.cpp +220 -0
- package/src/vector_store_loader_mmap.cpp +154 -0
package/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
# native-vector-store
|
2
|
+
|
3
|
+
High-performance vector store with SIMD optimization for MCP servers and local RAG applications.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **🚀 High Performance**: C++ implementation with OpenMP SIMD optimization
|
8
|
+
- **📦 Arena Allocation**: Memory-efficient storage with 64MB chunks
|
9
|
+
- **⚡ Fast Search**: Sub-10ms similarity search for large document collections
|
10
|
+
- **🔧 MCP Integration**: Built for Model Context Protocol servers
|
11
|
+
- **🌐 Cross-Platform**: Works on Linux, macOS, and Windows
|
12
|
+
- **📊 TypeScript Support**: Full type definitions included
|
13
|
+
- **🔄 Producer-Consumer Loading**: Parallel document loading at 178k+ docs/sec
|
14
|
+
|
15
|
+
## Performance Targets
|
16
|
+
|
17
|
+
- **Load Time**: <1 second for 100,000 documents (achieved: ~560ms)
|
18
|
+
- **Search Latency**: <10ms for top-k similarity search (achieved: 1-2ms)
|
19
|
+
- **Memory Efficiency**: Minimal fragmentation via arena allocation
|
20
|
+
- **Scalability**: Designed for <1M embeddings
|
21
|
+
- **Throughput**: 178k+ documents per second with parallel loading
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
```bash
|
26
|
+
npm install native-vector-store
|
27
|
+
```
|
28
|
+
|
29
|
+
### Prerequisites
|
30
|
+
|
31
|
+
For most users, **no prerequisites are needed** - prebuilt binaries are included for:
|
32
|
+
- Linux (x64, arm64)
|
33
|
+
- macOS (x64, arm64/Apple Silicon)
|
34
|
+
- Windows (x64)
|
35
|
+
|
36
|
+
If building from source, you'll need:
|
37
|
+
- Node.js ≥14.0.0
|
38
|
+
- C++ compiler with OpenMP support
|
39
|
+
- simdjson library (automatically handled by node-gyp)
|
40
|
+
|
41
|
+
## Quick Start
|
42
|
+
|
43
|
+
```javascript
|
44
|
+
const { VectorStore } = require('native-vector-store');
|
45
|
+
|
46
|
+
// Initialize with embedding dimensions (e.g., 1536 for OpenAI)
|
47
|
+
const store = new VectorStore(1536);
|
48
|
+
|
49
|
+
// Load documents from directory
|
50
|
+
store.loadDir('./documents'); // Automatically finalizes after loading
|
51
|
+
|
52
|
+
// Or add documents manually then finalize
|
53
|
+
const document = {
|
54
|
+
id: 'doc-1',
|
55
|
+
text: 'Example document text',
|
56
|
+
metadata: {
|
57
|
+
embedding: new Array(1536).fill(0).map(() => Math.random()),
|
58
|
+
category: 'example'
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
store.addDocument(document);
|
63
|
+
store.finalize(); // Must call before searching!
|
64
|
+
|
65
|
+
// Search for similar documents
|
66
|
+
const queryEmbedding = new Float32Array(1536);
|
67
|
+
const results = store.search(queryEmbedding, 5); // Top 5 results
|
68
|
+
|
69
|
+
console.log(results[0]); // { score: 0.95, id: 'doc-1', text: '...', metadata_json: '...' }
|
70
|
+
```
|
71
|
+
|
72
|
+
## MCP Server Integration
|
73
|
+
|
74
|
+
Perfect for building local RAG capabilities in MCP servers:
|
75
|
+
|
76
|
+
```javascript
|
77
|
+
const { MCPVectorServer } = require('native-vector-store/examples/mcp-server');
|
78
|
+
|
79
|
+
const server = new MCPVectorServer(1536);
|
80
|
+
|
81
|
+
// Load document corpus
|
82
|
+
await server.loadDocuments('./documents');
|
83
|
+
|
84
|
+
// Handle MCP requests
|
85
|
+
const response = await server.handleMCPRequest('vector_search', {
|
86
|
+
query: queryEmbedding,
|
87
|
+
k: 5,
|
88
|
+
threshold: 0.7
|
89
|
+
});
|
90
|
+
```
|
91
|
+
|
92
|
+
## API Reference
|
93
|
+
|
94
|
+
### `VectorStore`
|
95
|
+
|
96
|
+
#### Constructor
|
97
|
+
```typescript
|
98
|
+
new VectorStore(dimensions: number)
|
99
|
+
```
|
100
|
+
|
101
|
+
#### Methods
|
102
|
+
|
103
|
+
##### `loadDir(path: string): void`
|
104
|
+
Load all JSON documents from a directory and automatically finalize the store. Files should contain document objects with embeddings.
|
105
|
+
|
106
|
+
##### `addDocument(doc: Document): void`
|
107
|
+
Add a single document to the store. Only works during loading phase (before finalization).
|
108
|
+
|
109
|
+
```typescript
|
110
|
+
interface Document {
|
111
|
+
id: string;
|
112
|
+
text: string;
|
113
|
+
metadata: {
|
114
|
+
embedding: number[];
|
115
|
+
[key: string]: any;
|
116
|
+
};
|
117
|
+
}
|
118
|
+
```
|
119
|
+
|
120
|
+
##### `search(query: Float32Array, k: number, normalizeQuery?: boolean): SearchResult[]`
|
121
|
+
Search for k most similar documents.
|
122
|
+
|
123
|
+
```typescript
|
124
|
+
interface SearchResult {
|
125
|
+
score: number;
|
126
|
+
id: string;
|
127
|
+
text: string;
|
128
|
+
metadata_json: string;
|
129
|
+
}
|
130
|
+
```
|
131
|
+
|
132
|
+
##### `finalize(): void`
|
133
|
+
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 `loadDir()`.
|
134
|
+
|
135
|
+
##### `isFinalized(): boolean`
|
136
|
+
Check if the store has been finalized and is ready for searching.
|
137
|
+
|
138
|
+
##### `normalize(): void`
|
139
|
+
**Deprecated**: Use `finalize()` instead.
|
140
|
+
|
141
|
+
##### `size(): number`
|
142
|
+
Get the number of documents in the store.
|
143
|
+
|
144
|
+
## Building from Source
|
145
|
+
|
146
|
+
```bash
|
147
|
+
# Install dependencies
|
148
|
+
npm install
|
149
|
+
|
150
|
+
# Build native module
|
151
|
+
npm run build
|
152
|
+
|
153
|
+
# Run tests
|
154
|
+
npm test
|
155
|
+
|
156
|
+
# Run performance benchmarks
|
157
|
+
npm run benchmark
|
158
|
+
|
159
|
+
# Try MCP server example
|
160
|
+
npm run example
|
161
|
+
```
|
162
|
+
|
163
|
+
## Architecture
|
164
|
+
|
165
|
+
### Memory Layout
|
166
|
+
- **Arena Allocator**: 64MB chunks for cache-friendly access
|
167
|
+
- **Contiguous Storage**: Embeddings, strings, and metadata in single allocations
|
168
|
+
- **Zero-Copy Design**: Direct memory access without serialization overhead
|
169
|
+
|
170
|
+
### SIMD Optimization
|
171
|
+
- **OpenMP Pragmas**: Vectorized dot product operations
|
172
|
+
- **Parallel Processing**: Multi-threaded JSON loading and search
|
173
|
+
- **Cache-Friendly**: Aligned memory access patterns
|
174
|
+
|
175
|
+
### Performance Characteristics
|
176
|
+
- **Load Performance**: O(n) with parallel JSON parsing
|
177
|
+
- **Search Performance**: O(n⋅d) with SIMD acceleration
|
178
|
+
- **Memory Usage**: ~(d⋅4 + text_size) bytes per document
|
179
|
+
|
180
|
+
## Use Cases
|
181
|
+
|
182
|
+
### MCP Servers
|
183
|
+
Ideal for building local RAG (Retrieval-Augmented Generation) capabilities:
|
184
|
+
- Fast document loading from knowledge bases
|
185
|
+
- Low-latency similarity search for context retrieval
|
186
|
+
- Memory-efficient storage for large document collections
|
187
|
+
|
188
|
+
### Knowledge Management
|
189
|
+
Perfect for personal knowledge management systems:
|
190
|
+
- Index personal documents and notes
|
191
|
+
- Fast semantic search across content
|
192
|
+
- Offline operation without external dependencies
|
193
|
+
|
194
|
+
### Research Applications
|
195
|
+
Suitable for academic and research projects:
|
196
|
+
- Literature review and citation analysis
|
197
|
+
- Semantic clustering of research papers
|
198
|
+
- Cross-reference discovery in document collections
|
199
|
+
|
200
|
+
## Contributing
|
201
|
+
|
202
|
+
1. Fork the repository
|
203
|
+
2. Create a feature branch
|
204
|
+
3. Make your changes
|
205
|
+
4. Add tests for new functionality
|
206
|
+
5. Ensure all tests pass
|
207
|
+
6. Submit a pull request
|
208
|
+
|
209
|
+
## License
|
210
|
+
|
211
|
+
MIT License - see LICENSE file for details.
|
212
|
+
|
213
|
+
## Benchmarks
|
214
|
+
|
215
|
+
Performance on M1 MacBook Pro with 1536-dimensional embeddings:
|
216
|
+
|
217
|
+
| Operation | Document Count | Time | Rate |
|
218
|
+
|-----------|---------------|------|------|
|
219
|
+
| Load | 10,000 | 245ms | 40.8k docs/sec |
|
220
|
+
| Search | 10,000 | 3.2ms | 3.1M docs/sec |
|
221
|
+
| Normalize | 10,000 | 12ms | 833k docs/sec |
|
222
|
+
|
223
|
+
*Results may vary based on hardware and document characteristics.*
|
package/binding.gyp
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
{
|
2
|
+
"targets": [
|
3
|
+
{
|
4
|
+
"target_name": "vector_store",
|
5
|
+
"sources": ["src/binding.cc", "src/vector_store_loader.cpp", "src/vector_store_loader_mmap.cpp", "src/vector_store_loader_adaptive.cpp"],
|
6
|
+
"include_dirs": [
|
7
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
8
|
+
"src"
|
9
|
+
],
|
10
|
+
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
11
|
+
"cflags_cc": [
|
12
|
+
"-std=c++17",
|
13
|
+
"-O3",
|
14
|
+
"-march=native",
|
15
|
+
"-fno-exceptions"
|
16
|
+
],
|
17
|
+
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
18
|
+
"conditions": [
|
19
|
+
["OS=='mac'", {
|
20
|
+
"include_dirs": ["/opt/homebrew/opt/libomp/include", "/opt/homebrew/include"],
|
21
|
+
"xcode_settings": {
|
22
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "NO",
|
23
|
+
"OTHER_CFLAGS": ["-Xpreprocessor", "-fopenmp"],
|
24
|
+
"OTHER_CPLUSPLUSFLAGS": ["-Xpreprocessor", "-fopenmp"],
|
25
|
+
"OTHER_LDFLAGS": ["-L/opt/homebrew/opt/libomp/lib", "-lomp"]
|
26
|
+
},
|
27
|
+
"libraries": ["-L/opt/homebrew/opt/libomp/lib", "-lomp", "-L/opt/homebrew/lib", "-lsimdjson"]
|
28
|
+
}],
|
29
|
+
["OS=='linux'", {
|
30
|
+
"cflags_cc": ["-fopenmp"],
|
31
|
+
"libraries": ["-lgomp", "-lsimdjson"]
|
32
|
+
}],
|
33
|
+
["OS=='win'", {
|
34
|
+
"msvs_settings": {
|
35
|
+
"VCCLCompilerTool": {
|
36
|
+
"ExceptionHandling": 0,
|
37
|
+
"OpenMP": "true"
|
38
|
+
}
|
39
|
+
},
|
40
|
+
"libraries": ["simdjson.lib"]
|
41
|
+
}]
|
42
|
+
]
|
43
|
+
}
|
44
|
+
]
|
45
|
+
}
|
package/index.js
ADDED
package/lib/index.d.ts
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
export interface Document {
|
2
|
+
id: string;
|
3
|
+
text: string;
|
4
|
+
metadata: {
|
5
|
+
embedding?: number[];
|
6
|
+
[key: string]: any;
|
7
|
+
};
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface SearchResult {
|
11
|
+
score: number;
|
12
|
+
id: string;
|
13
|
+
text: string;
|
14
|
+
metadata_json: string;
|
15
|
+
}
|
16
|
+
|
17
|
+
export class VectorStore {
|
18
|
+
constructor(dimensions: number);
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Load all JSON documents from a directory
|
22
|
+
* Files should contain Document objects with embeddings in metadata
|
23
|
+
*/
|
24
|
+
loadDir(path: string): void;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Add a single document
|
28
|
+
*/
|
29
|
+
addDocument(doc: Document): void;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Search for k most similar documents
|
33
|
+
* @param query - Query embedding vector
|
34
|
+
* @param k - Number of results to return
|
35
|
+
* @param normalizeQuery - Whether to L2 normalize the query (default: true)
|
36
|
+
*/
|
37
|
+
search(query: Float32Array, k: number, normalizeQuery?: boolean): SearchResult[];
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Normalize all stored embeddings
|
41
|
+
* @deprecated Use finalize() instead
|
42
|
+
*/
|
43
|
+
normalize(): void;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Finalize the store: normalize embeddings and switch to serving mode
|
47
|
+
* After calling this, no more documents can be added
|
48
|
+
*/
|
49
|
+
finalize(): void;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Check if the store has been finalized
|
53
|
+
*/
|
54
|
+
isFinalized(): boolean;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Get the number of documents in the store
|
58
|
+
*/
|
59
|
+
size(): number;
|
60
|
+
}
|
Binary file
|
package/package.json
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"name": "native-vector-store",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "High-performance local vector store with SIMD optimization for MCP servers",
|
5
|
+
"main": "index.js",
|
6
|
+
"types": "lib/index.d.ts",
|
7
|
+
"author": "Martin Boros <mboros04@gmail.com>",
|
8
|
+
"license": "Apache 2.0",
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "git+https://github.com/mboros1/native-vector-store.git"
|
12
|
+
},
|
13
|
+
"bugs": {
|
14
|
+
"url": "https://github.com/mboros1/native-vector-store/issues"
|
15
|
+
},
|
16
|
+
"homepage": "https://github.com/mboros1/native-vector-store#readme",
|
17
|
+
"scripts": {
|
18
|
+
"build": "node-gyp rebuild",
|
19
|
+
"clean": "node-gyp clean",
|
20
|
+
"test": "node test/test.js",
|
21
|
+
"install": "node-gyp-build",
|
22
|
+
"prebuildify": "prebuildify --napi --strip",
|
23
|
+
"prebuildify-cross": "prebuildify-cross -i centos7-devtoolset7 -i alpine -i linux-arm64 -i darwin-arm64 -i darwin-x64+arm64",
|
24
|
+
"benchmark": "node test/test.js",
|
25
|
+
"example": "node examples/mcp-server.js demo",
|
26
|
+
"embed": "node embed_dir.js"
|
27
|
+
},
|
28
|
+
"keywords": [
|
29
|
+
"vector",
|
30
|
+
"embedding",
|
31
|
+
"similarity",
|
32
|
+
"search",
|
33
|
+
"simd",
|
34
|
+
"mcp"
|
35
|
+
],
|
36
|
+
"dependencies": {
|
37
|
+
"dotenv": "^17.2.0",
|
38
|
+
"node-addon-api": "^7.0.0",
|
39
|
+
"node-gyp-build": "^4.8.0",
|
40
|
+
"openai": "^5.8.3"
|
41
|
+
},
|
42
|
+
"devDependencies": {
|
43
|
+
"node-gyp": "^10.0.0",
|
44
|
+
"prebuildify": "^6.0.0"
|
45
|
+
},
|
46
|
+
"os": ["darwin", "linux", "win32"],
|
47
|
+
"cpu": ["x64", "arm64"],
|
48
|
+
"engines": {
|
49
|
+
"node": ">=14.0.0"
|
50
|
+
},
|
51
|
+
"gypfile": true
|
52
|
+
}
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Build prebuilds for current platform
|
4
|
+
echo "Building prebuilds for native-vector-store..."
|
5
|
+
|
6
|
+
# Clean previous builds
|
7
|
+
rm -rf prebuilds/
|
8
|
+
|
9
|
+
# Build for current platform and architecture
|
10
|
+
echo "Building for current platform..."
|
11
|
+
npx prebuildify --napi --strip
|
12
|
+
|
13
|
+
# For local testing on macOS, build both architectures if on Apple Silicon
|
14
|
+
if [[ "$OSTYPE" == "darwin"* ]] && [[ "$(uname -m)" == "arm64" ]]; then
|
15
|
+
echo "Building universal binary for macOS..."
|
16
|
+
npx prebuildify --napi --strip --arch x64
|
17
|
+
npx prebuildify --napi --strip --arch arm64
|
18
|
+
fi
|
19
|
+
|
20
|
+
echo "Prebuilds created:"
|
21
|
+
find prebuilds -type f -name "*.node" | sort
|
22
|
+
|
23
|
+
echo "Done!"
|