• 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
7
CHANGES.md
GUIDE.md
HANDOVER.md
README.md
H
api.ts
ui.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/3/2026
Viewing readonly version of main branch: v80
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). Supports any OpenAI-compatible embedding provider.

Features

  • ✅ Semantic search with cosine similarity + distance scores
  • ✅ Multi-provider support - Nebius, OpenAI, OpenRouter, or any OpenAI-compatible API
  • ✅ Smart re-embedding - only re-embeds when text changes (content hash)
  • ✅ Optimized storage - float8 compression, tuned DiskANN index
  • ✅ Scale testing tools - seed data, calibrate thresholds, detailed stats
  • ✅ Metadata filtering - filter by meta fields on search
  • ✅ Hybrid search - vector + keyword boosting
  • ✅ Batch upserts - submit many records in one call
  • ✅ Chunking helper - split long docs into chunks
  • ✅ Export/import - migrate data between providers

Supported Embedding Providers

ProviderEnv VarsDefault ModelDimensions
Nebius (default)NEBIUS_API_KEYQwen3-Embedding-8B4096
OpenAIEMBEDDING_PROVIDER=openai + OPENAI_API_KEYtext-embedding-3-small1536
OpenRouterEMBEDDING_PROVIDER=openrouter + OPENROUTER_API_KEYopenai/text-embedding-3-small1536
CustomSee below(configurable)(configurable)

Custom Provider Configuration

EMBEDDING_API_URL=https://your-api.com/v1/embeddings EMBEDDING_API_KEY=your-key EMBEDDING_MODEL=your-model-name EMBEDDING_DIM=1536

Quick Stats (Nebius/4096 dims)

MetricValue
Storage per record~22 KB
Max records per 1GB~47,500
Avg embedding time~460ms
Recommended maxDistance0.6 - 0.65

API Endpoints

Core API

MethodEndpointDescription
POST/upsertInsert/update {id, text, meta?}
POST/searchSearch {query, k?, maxDistance?}
POST/deleteDelete {id}
GET/get?id=...Get single record
GET/list?limit=...&offset=...&prefix=...List record IDs
POST/upsert_chunkedChunk + upsert {id, text, meta?, chunkSize?, overlap?}
GET/export?limit=...&offset=...Export records
POST/importImport records (batch upsert)

Admin / Testing

MethodEndpointDescription
GET/API info + current provider
GET/pingHealth check
GET/statsDetailed storage stats
GET/seed?n=100Seed N synthetic records
GET/calibrate?q=...Suggest distance thresholds
GET/validateSelf-checks (optional write tests)
POST/reindexRecreate optimized index
POST/clear?confirm=yesDelete ALL records

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, "maxDistance": 0.64}'

Search with filters + hybrid boost

curl -X POST https://YOUR_ENDPOINT/search \ -H "Content-Type: application/json" \ -d '{ "query": "machine learning", "k": 10, "filters": { "category": "tech" }, "hybrid": { "enabled": true, "alpha": 0.25 } }'

Pagination

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

Batch upsert

curl -X POST https://YOUR_ENDPOINT/upsert \ -H "Content-Type: application/json" \ -d '[ {"id":"doc-1","text":"A short note","meta":{"category":"notes"}}, {"id":"doc-2","text":"Another note","meta":{"category":"notes"}} ]'

Chunked upsert

curl -X POST https://YOUR_ENDPOINT/upsert_chunked \ -H "Content-Type: application/json" \ -d '{"id":"doc-long","text":"...long text...","chunkSize":800,"overlap":100}'

Export / Import

curl "https://YOUR_ENDPOINT/export?limit=200&offset=0"
curl -X POST https://YOUR_ENDPOINT/import \ -H "Content-Type: application/json" \ -d '{"records":[{"id":"doc-1","text":"hello"}]}'

Calibrate threshold

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

Distance Score Guide

DistanceMeaningRecommendation
0.0 - 0.4Very similarAlways include
0.4 - 0.6RelatedInclude (tight mode)
0.6 - 0.7Somewhat relatedInclude (balanced mode)
0.7+Likely unrelatedFilter out

Default: Use maxDistance: 0.64 for balanced results.

Import as Module

import * as db from "https://esm.town/v/kamenxrider/slimarmor/vectordb.ts"; // Check provider configuration console.log(db.getProviderInfo()); // → { provider: "nebius", model: "Qwen3-Embedding-8B", dimensions: 4096, ... } // Setup (creates table + index) await db.setup(); // Upsert await db.upsert("doc-1", "Your text here", { category: "notes" }); // Search const results = await db.search("search query", 10, 0.64); // → [{ id, text, meta, distance }, ...] // Delete await db.remove("doc-1"); // Stats const stats = await db.stats(); // → { count: 105, estimated_storage_mb: 2.26 }

Switching Providers

⚠️ Important: Embeddings from different providers/models are incompatible. If you switch:

  1. Export any data you need
  2. Clear the database: POST /clear?confirm=yes
  3. Update environment variables
  4. Re-insert your data

Tip: You can set EMBEDDING_DIM=auto to auto-detect dimensions on first setup.


Validation (Built-in Self-Checks)

Use the self-check endpoint to validate core behavior:

curl https://YOUR_ENDPOINT/validate

Optional write tests (require auth, embedding key, and ALLOW_WRITE_TESTS=1):

curl -H "Authorization: Bearer $ADMIN_TOKEN" \ "https://YOUR_ENDPOINT/validate?write=yes"

If you can’t send headers (embedded preview), temporarily set ALLOW_WRITE_TESTS_NOAUTH=1 and call:

curl "https://YOUR_ENDPOINT/validate?write=yes"

Latest validation run (2026-02-03):

  • Status: OK in 3597 ms
  • Provider: Nebius Qwen/Qwen3-Embedding-8B (4096 dims)
  • Tests: auth, stats, list, search passed; write tests passed (write_upsert, filter_search, hybrid_search, write_delete)

Index Optimizations

SlimArmor uses optimized DiskANN settings for storage efficiency:

SettingValueEffect
metriccosineCosine similarity
max_neighbors6466% fewer neighbors vs default
compress_neighborsfloat875% less index storage

Index Tuning (Optional)

INDEX_METRIC=cosine # cosine (default) or l2 INDEX_MAX_NEIGHBORS=64 # 8-256 INDEX_COMPRESS_NEIGHBORS=float8 # float8 (default), float16, floatb16, float32, float1bit, or none # DiskANN knobs (optional; omit to use libSQL defaults) INDEX_ALPHA=1.2 # >= 1; lower = sparser graph (faster, less accurate) INDEX_SEARCH_L=200 # query-time effort (higher = more accurate, slower) INDEX_INSERT_L=70 # insert-time effort (higher = better graph, slower inserts)

After changing index settings, rebuild the index:

curl -X POST -H "Authorization: Bearer $ADMIN_TOKEN" https://YOUR_ENDPOINT/reindex

Files

FileDescription
vectordb.tsCore library - import this in your vals
api.tsHTTP API endpoints
README.mdThis documentation
GUIDE.mdStep-by-step beginner guide
HANDOVER.mdTechnical handover notes

Tech Stack

  • Runtime: Val Town (Deno)
  • Database: Val Town SQLite (Turso/libSQL)
  • Vector Index: DiskANN with cosine similarity
  • Embeddings: Any OpenAI-compatible API

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.