An ultra-low latency embedded vector search engine built from scratch in C++ and bound natively to the Node.js V8 runtime. Designed to perform high-dimensional semantic search with zero-copy memory translation and zero network overhead.
- Native C++17 HNSW implementation for approximate nearest neighbor search.
- Zero-copy memory transfer between JavaScript and C++ using Node-API (N-API).
- Embedded in-memory architecture with no external vector database.
- Sub-millisecond query latency.
- Local text embeddings generated using Transformers.js.
- React dashboard for interactive semantic search.
HNSW (Hierarchical Navigable Small World) is a graph-based algorithm used for fast Approximate Nearest Neighbor (ANN) search in high-dimensional vector spaces.
Instead of performing a brute-force scan with O(N) complexity, HNSW organizes vectors into multiple graph layers, reducing search complexity to approximately O(log N).
The search engine core was implemented entirely in C++ to bypass the overhead introduced by the Node.js V8 garbage collector. Memory pointers and cache-friendly data structures provide significantly lower latency during intensive mathematical computations.
HTTP Request
┌─────────────────┐
│ React Frontend │
│ (Dashboard UI) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Express.js API │
└────────┬────────┘
│
▼
┌──────────────────────────────┐
│ Transformers.js │
│ Local Embedding Model │
│ all-mpnet-base-v2 (768D) │
└────────┬─────────────────────┘
│ Float32Array
▼
┌──────────────────────────────┐
│ Node-API (N-API) Bridge │
│ Zero-Copy Pointer Extraction │
└────────┬─────────────────────┘
│
▼
┌──────────────────────────────┐
│ Native C++ HNSW Engine │
│ Graph Traversal │
│ Top-K Nearest Search │
└────────┬─────────────────────┘
│
▼
Match IDs
The primary bottleneck in multi-language systems is data transfer between runtimes.
Instead of copying the 768-dimensional embedding from JavaScript into C++, the engine extracts a direct pointer to the underlying Float32Array memory block using Node-API, eliminating unnecessary memory copies.
// addon.cpp
napi_value SearchVector(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
napi_typedarray_type type;
size_t length;
void* data;
napi_value arraybuffer;
size_t byte_offset;
// Extract raw pointer from the V8 heap
napi_get_typedarray_info(
env,
args[0],
&type,
&length,
&data,
&arraybuffer,
&byte_offset
);
// Cast directly to float*
float* query_vector = static_cast<float*>(data);
// Execute HNSW search
int top_match_id = hnsw_db->search(query_vector);
napi_value result;
napi_create_int32(env, top_match_id, &result);
return result;
}| Metric | Result |
|---|---|
| Dataset Size | 10,000 vectors |
| Index Build Time | 221 ms |
| Brute-Force Search | 4.00 ms |
| HNSW Query Latency | < 0.99 ms |
| Typical Query Time | ~0.02 ms |
- C++17
- HNSW Algorithm
- Node-API (N-API)
- node-gyp
- MSVC / GCC
- Node.js
- Express.js
- Transformers.js
- Hugging Face
all-mpnet-base-v2(768-dimensional embeddings)
- React
- Vite
- CSS Glassmorphism
AI-Vector-Engine/
│
├── vector-database-backend/
│ ├── addon.cpp # Node-API bindings
│ ├── main.cpp # Core vector engine
│ ├── HNSWDB.h # HNSW graph implementation
│ ├── FlatDB.h # Brute-force search implementation
│ ├── VectorMath.h # Similarity calculations
│ ├── binding.gyp
│ ├── index.js
│ ├── server.js # Express API server
│ └── package.json
│
├── vectordb-dashboard/
│ ├── src/
│ ├── public/
│ ├── index.html
│ ├── vite.config.js
│ └── package.json
│
└── README.md
git clone https://github.com/Crystlfly/AI-Vector-Engine.git
cd AI-Vector-Enginenpm installRequires Visual Studio C++ Build Tools (Windows) or GCC (Linux).
npx node-gyp configure buildnode server.jsnpm run dev- User submits a natural language query.
- Transformers.js converts the text into a 768-dimensional embedding.
- Node-API extracts a pointer to the underlying
Float32Array. - The C++ HNSW engine performs graph traversal.
- The nearest vector IDs are returned to Node.js.
- Results are displayed in the React dashboard.
- Top-K nearest neighbor retrieval.
- Persistent disk storage.
- Dynamic insertions and deletions.
- Product Quantization (PQ).
- SIMD vector optimization.
- Multi-threaded indexing.
- Distributed sharding.
MIT License.