# Getting Started ## Installation ```bash npm install vecdb-wasm ``` The package includes: - ESM and CJS bundles with full TypeScript declarations - A background Web Worker for ONNX embedding inference - The compiled WASM binary (~172 KB) for HNSW vector search ### Browser Requirements VecDB-WASM runs entirely in the browser. It requires: | Feature | Used For | Support | |---------|----------|---------| | [WebAssembly](https://caniuse.com/wasm) | HNSW vector search engine | All modern browsers | | [Web Workers](https://caniuse.com/webworkers) | Background embedding inference | All modern browsers | | [OPFS](https://caniuse.com/native-filesystem-api) | Persistent vROM cache | Chrome 86+, Firefox 111+, Safari 15.2+ | | [ES Modules in Workers](https://caniuse.com/mdn-api_worker_worker_ecmascript_modules) | Worker `type: 'module'` | Chrome 80+, Firefox 114+, Safari 15+ | > **Note:** The embedding worker loads [transformers.js](https://huggingface.co/docs/transformers.js) from CDN at runtime. The first model load requires an internet connection; subsequent loads use the browser's Cache API. ## Quick Start ```typescript import { AgentMemory } from 'vecdb-wasm'; // 1. Create and initialize const memory = new AgentMemory(); await memory.init(); // 2. Mount a pre-built knowledge base await memory.mount('hf-transformers-docs'); // 3. Search with natural language const results = await memory.search('how to fine-tune a model'); // 4. Format for LLM context injection const context = memory.formatContext(results, { maxTokens: 2000 }); // 5. Clean up when done memory.destroy(); ``` That's it. Five lines of meaningful code to go from zero to a searchable knowledge base with semantic search. ## What Happens Under the Hood When you run the code above, VecDB-WASM: 1. **`init()`** — Loads the 172 KB WASM binary (HNSW engine) and spawns a background Web Worker for embedding inference. 2. **`mount('hf-transformers-docs')`** — Does four things: - Checks the [vROM Registry](https://huggingface.co/datasets/philipp-zettl/vrom-registry) for the requested knowledge base - Downloads the pre-computed HNSW index (~12 MB) from Hugging Face CDN, or loads it from the OPFS cache if already downloaded - Deserializes the index into the WASM engine via `VectorDB.load()` - Loads the required embedding model (`all-MiniLM-L6-v2`, ~22 MB q8) in the background worker, or skips this if the same model is already loaded 3. **`search('how to fine-tune a model')`** — Embeds the query text in the background worker (~50ms), then runs HNSW approximate nearest neighbor search in WASM (<1ms). 4. **`formatContext(results)`** — Concatenates result texts with source URLs into a string ready for LLM system/user prompt injection. ## 5-Minute Tutorial ### Step 1: Set Up a Project ```bash mkdir my-rag-app && cd my-rag-app npm init -y npm install vecdb-wasm ``` ### Step 2: Create the App Create `index.html`: ```html