Skip to content
VaultDBDocs

Vector search

Vector search returns the rows whose stored vector is most similar to a vector you send, by cosine similarity. It is available on the Starter plan and above, and needs the Databases permission.

Store vectors

Keep each row's vector in an ordinary column, as a JSON array of numbers. A TEXT column works:

curl -X POST https://api.vaultdb.io/api/databases/shop/tables \
  -H "Authorization: Bearer $VAULTDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "articles",
    "columns": [
      { "name": "id", "type": "INTEGER", "primaryKey": true },
      { "name": "title", "type": "TEXT" },
      { "name": "embedding", "type": "TEXT" }
    ]
  }'

curl -X POST https://api.vaultdb.io/api/databases/shop/tables/articles/data \
  -H "Authorization: Bearer $VAULTDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "data": { "title": "Getting started", "embedding": "[0.12, -0.03, 0.88]" } }'

VaultDB does not create embeddings. Generate them with the model of your choice and store the numbers.

curl -X POST https://api.vaultdb.io/api/databases/shop/tables/articles/search \
  -H "Authorization: Bearer $VAULTDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "vector": [0.1, 0, 0.9], "column": "embedding", "limit": 5, "threshold": 0.5 }'
Field Required Description
vector Yes A non-empty array of finite numbers.
column Yes The column that holds the stored vectors.
limit No Results to return. Default 10, at most 100.
threshold No The lowest similarity to include, from 0 to 1. Default 0.

Response:

{
  "table": "articles",
  "column": "embedding",
  "results": [
    { "id": 1, "title": "Getting started", "embedding": "[0.12, -0.03, 0.88]", "_similarity": 0.9934 }
  ],
  "count": 1
}

Each result is the whole row plus _similarity, rounded to four decimal places. Results are sorted from most to least similar.

Things to know

  • The search reads every row of the table. There is no vector index, so a search takes longer as the table grows.
  • A row whose column is empty, is not a JSON array of numbers, or has a different length from your vector is skipped or scores 0.
  • Vector search applies the table's select row-level policies: it ranks only the rows a read would return.