Skip to documentation
OriginChainDB Docs
Ask AI
Queries
examples · vector

Vector examples

← All examples

Vectors on OriginChainDB live on the runtime endpoint POST /v1/tenants/:t/vector/:table/put - they are not declared on the row schema. The id field is what links a vector back to a row, so use the row's primary key.

13 examples, each on its own page. The first seven cover the write and the query: insert embeddings, search by cosine, L2 or dot product, switch between fast and high-recall mode, and restrict a search with a metadata filter. The rest cover the parts you cannot guess - deleting vectors, installing and retraining an IVF index, checking what the index actually covers, diagnosing and rebuilding an HNSW graph, building a compressed index, and fusing a sparse and a dense search into one call. Every page carries the request in cURL + Python + TypeScript + Go, the response shape, how it works, and common mistakes.

1
Insert a single embedding

Save one vector under an ID. The simplest write.

→
2
Insert with metadata

Attach arbitrary tags to each vector so you can later filter searches on them.

→
3
Top-k - cosine similarity

The default metric for text embeddings (OpenAI, Cohere, BGE, E5).

→
4
Top-k - L2 distance

Euclidean distance. Use when the absolute magnitude of vectors carries signal.

→
5
Top-k - dot product

Inner product. Use when your embeddings are already unit-normalised.

→
6
fast mode - lower latency, slightly lower recall

Trade some recall for ~3x faster results. Useful when latency matters more than perfect ranking.

→
7
Filtered top-k - metadata predicate

Restrict the search to vectors whose metadata matches a filter. Applied during search, not after.

→
8
Delete a vector

Remove one embedding by id, or up to 10,000 in one bulk call. Both are idempotent.

→
9
Train and install IVF centroids

Bootstrap an IVF index: train k-means over the stored corpus, install it, and read back what is installed.

→
10
IVF coverage and cell skew

How much of the table the index actually covers, how lopsided the cells are, and whether to retrain.

→
11
HNSW health, and rebuilding a damaged index

Find out whether the graph can still be walked, prove which metric it was built for, then rebuild it in place.

→
12
Build a compressed IVF-PQ index

A product-quantized IVF index from a named preset - what it resolves to, and what it keeps on disk.

→
13
Hybrid top-k - sparse and dense, fused

One call that runs both searches and fuses the two rankings server-side.

→