A minimal Express + TypeScript backend that talks to a VelesDB
server through the @wiscale/velesdb-sdk Node.js client.
Three endpoints:
| Method | Path | Body |
|---|---|---|
POST |
/ingest |
{ "id"?, "text", "metadata"? } — embeds text and upserts into the collection |
POST |
/search |
{ "query", "k"? } — embeds query and returns the top-K hits |
GET |
/health |
— — returns { status, collection, velesdb } |
cd examples/node-express-rag
docker compose up --buildThis starts:
velesdb-server(built from the repo rootDockerfile) on:8080with persistent volumevelesdb-datanode-express-rag(this app) on:3000, configured viaVELESDB_URL=http://velesdb:8080
The app waits for the VelesDB healthcheck to go green before accepting traffic.
First build is slow:
docker compose up --buildcompiles the full Rust workspace (~5–15 minutes cold). Subsequent runs use the cached image. If you already builtvelesdb/velesdb:latestfrom the repo root, change thevelesdbservice indocker-compose.ymltoimage: velesdb/velesdb:latest(drop thebuild:block) to skip the rebuild. The named volumevelesdb-datasurvivesdocker compose downbut is wiped bydocker compose down -v.
# Ingest a few documents
curl -X POST http://localhost:3000/ingest \
-H "content-type: application/json" \
-d '{"id":"1","text":"VelesDB is a single-binary embedded vector + graph database in Rust."}'
curl -X POST http://localhost:3000/ingest \
-H "content-type: application/json" \
-d '{"id":"2","text":"Express is a minimal Node.js web framework for building HTTP APIs."}'
curl -X POST http://localhost:3000/ingest \
-H "content-type: application/json" \
-d '{"id":"3","text":"Cosine similarity ranks documents by the angle between their embedding vectors."}'
# Search
curl -X POST http://localhost:3000/search \
-H "content-type: application/json" \
-d '{"query":"how does similarity search work","k":3}'
# Health
curl http://localhost:3000/healthIf you have a velesdb-server process running on the host (cargo run --bin velesdb-server):
cd examples/node-express-rag
cp .env.example .env # adjust PORT / VELESDB_URL if needed
npm install
npm run dev # tsx watch modesrc/embed.ts ships a deterministic 384-D hashing-trick projection (the
same trick used by examples/react-wasm-search/). It is intentionally a
placeholder so the example is self-contained — no model download, no
external API key — but it only captures lexical overlap, not semantics.
Production-ready alternatives:
- In-process:
@xenova/transformers(ONNX runtime) - Remote: any embeddings API that returns a fixed-size vector
Swap the embed() function and bump EMBEDDING_DIM to your model's output size; the rest of the pipeline is unchanged.
| Path | Purpose |
|---|---|
src/server.ts |
Express app — routes, validation (zod), error handler. |
src/velesdb.ts |
SDK init wrapper — opens the REST connection, creates the documents collection if missing. |
src/embed.ts |
Hashing-trick embedder used by both /ingest and /search. |
Dockerfile |
Multi-stage Node 20 alpine build for the app. |
docker-compose.yml |
Runs velesdb-server + this app together. |