• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
kamenxrider

kamenxrider

slimarmor

Semantic vector DB on Val Town SQLite — DiskANN, hybrid search
Public
Like
slimarmor
Home
Code
3
README.md
H
api.ts
vectordb.ts
Environment variables
4
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
2/2/2026
Viewing readonly version of main branch: v33
View latest version
README.md

🛡️ SlimArmor - Mini Vector DB for Val Town

A lightweight, optimized vector database built on Val Town's SQLite (powered by Turso/libSQL) with Nebius Qwen3-Embedding-8B embeddings.

Features

  • 4096-dimensional embeddings via Nebius Qwen3-Embedding-8B
  • Semantic search with cosine similarity
  • Distance scores in search results (0 = identical, 1 = orthogonal, 2 = opposite)
  • Smart re-embedding - only re-embeds when text changes (content hash check)
  • Optimized index for storage efficiency
  • Scale testing tools - seed data, calibrate thresholds, detailed stats

Index Optimizations

OptimizationBenefit
compress_neighbors=float875% less index storage
max_neighbors=6466% fewer neighbors vs default
Distance filteringFilter out low-relevance results

Storage Estimate

~22KB per record → ~45,000 records per 1GB

API Endpoints

Core API

MethodEndpointDescription
POST/upsertInsert/update record {id, text, meta?}
POST/searchSearch {query, k?, maxDistance?}
POST/deleteDelete record {id}
GET/get?id=...Get single record
GET/list?limit=...List record IDs

Admin / Testing

MethodEndpointDescription
GET/Info + all endpoints
GET/pingHealth check
GET/statsDetailed storage stats
GET/testSmoke test with 5 demo records
GET/seed?n=100Seed N synthetic records (max 1000)
GET/calibrate?q=...Suggest distance thresholds for a query
POST/reindexRecreate index with optimized settings
POST/clear?confirm=yesDelete ALL records (dangerous!)

Usage Examples

Upsert a record

curl -X POST https://YOUR_ENDPOINT/upsert \ -H "Content-Type: application/json" \ -d '{"id": "doc-1", "text": "Dogs are loyal pets", "meta": {"category": "animals"}}'

Search

curl -X POST https://YOUR_ENDPOINT/search \ -H "Content-Type: application/json" \ -d '{"query": "furry pets", "k": 5}'

Search with distance filter

Only return results with distance ≤ 0.5 (more relevant):

curl -X POST https://YOUR_ENDPOINT/search \ -H "Content-Type: application/json" \ -d '{"query": "furry pets", "k": 10, "maxDistance": 0.5}'

Seed test data

curl https://YOUR_ENDPOINT/seed?n=100

Calibrate distance threshold

curl "https://YOUR_ENDPOINT/calibrate?q=machine+learning"

Returns suggested thresholds:

  • tight (top 3 only)
  • balanced (top 10, recommended default)
  • loose (all retrieved)

Understanding Distance Scores

The distance field uses cosine distance:

DistanceMeaning
0.0 - 0.3Very similar
0.3 - 0.5Related
0.5 - 0.7Somewhat related
0.7+Likely unrelated

Tip: Use /calibrate?q=... to find the right threshold for your data.

Scale Testing

To test how the system performs at scale:

  1. Seed data: GET /seed?n=1000
  2. Check stats: GET /stats
  3. Run queries: POST /search
  4. Calibrate: GET /calibrate?q=your+query

Recommended test sizes: 100 → 1,000 → 5,000 records

Import as a Module

You can import vectordb.ts directly in other Val Town projects:

import * as db from "https://esm.town/v/kamenxrider/slimarmor/vectordb.ts"; // Setup (creates table + index if not exists) await db.setup(); // Upsert await db.upsert("my-doc", "Some text to embed", { category: "notes" }); // Search const results = await db.search("search query", 10, 0.5); // Returns: [{ id, text, meta, distance }, ...] // Delete await db.remove("my-doc"); // Stats const stats = await db.stats(); // Returns: { count: 5, estimated_storage_mb: 0.11 }

Environment Variables

VariableDescription
NEBIUS_API_KEYYour Nebius API key for embeddings

Files

FileDescription
vectordb.tsCore vector DB library (importable)
api.tsHTTP API endpoints
README.mdThis file

Tech Stack

  • Runtime: Val Town (Deno)
  • Database: Val Town SQLite (Turso/libSQL)
  • Embeddings: Nebius Qwen3-Embedding-8B (4096 dims)
  • Vector Index: DiskANN with cosine similarity

License

MIT

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.