Vector Search API

REST API endpoints for vector index management and similarity search.

Vector Index Management

POST /_api/database/:db/vector/:collection

Create a new vector index for similarity search on an embedding field.

Request Body

Field Type Description Required
name string Unique name for the vector index. Yes
field string Document field containing embedding vectors. Yes
dimension integer Vector dimension (e.g., 1536 for OpenAI embeddings). Yes
metric string Distance metric: cosine (default), euclidean, dot. No
quantization string Compression method: none (default), scalar (4x memory reduction). No

Example Request

{ "name": "embedding_idx", "field": "embedding", "dimension": 1536, "metric": "cosine", "quantization": "scalar" }

Response

201 Created
{ "name": "embedding_idx", "field": "embedding", "dimension": 1536, "metric": "cosine", "quantization": "scalar", "indexed_vectors": 0, "memory_bytes": 0, "compression_ratio": 4.0 }
GET /_api/database/:db/vector/:collection

List all vector indexes for a collection.

Response

200 OK
{ "indexes": [ { "name": "embedding_idx", "field": "embedding", "dimension": 1536, "metric": "Cosine", "indexed_vectors": 15420 } ] }
DELETE /_api/database/:db/vector/:collection/:name

Delete a vector index.

Path Parameters

Parameter Description
db Database name
collection Collection name
name Vector index name to delete

Response

200 OK
{ "deleted": true, "name": "embedding_idx" }

Vector Quantization

POST /_api/database/:db/vector/:collection/:index/quantize

Apply scalar quantization to an existing vector index for 4x memory reduction. Vectors are compressed from f32 (4 bytes/dim) to u8 (1 byte/dim).

Path Parameters

Parameter Description
db Database name
collection Collection name
index Vector index name to quantize

Example Request

curl -X POST \ http://localhost:6745/_api/database/mydb/vector/articles/embedding_idx/quantize

Response

200 OK
{ "name": "embedding_idx", "vectors_quantized": 15420, "memory_before": 94494720, "memory_after": 23623680, "compression_ratio": 4.0, "status": "quantized" }

Asymmetric Search

After quantization, searches use asymmetric distance computation: query vectors remain at full f32 precision while database vectors are stored as u8. This maintains ~98% recall while achieving 4x compression.

POST /_api/database/:db/vector/:collection/:index/dequantize

Remove quantization from a vector index, reverting to full f32 precision search.

Example Request

curl -X POST \ http://localhost:6745/_api/database/mydb/vector/articles/embedding_idx/dequantize

Response

200 OK
{ "name": "embedding_idx", "status": "dequantized" }

Complete Example

A full workflow for setting up and using vector search:

1. Create a collection and add documents with embeddings

# Create collection curl -X POST http://localhost:6745/_api/database/mydb/collection \ -H "Content-Type: application/json" \ -d '{"name": "articles"}' # Insert documents with embeddings curl -X POST http://localhost:6745/_api/database/mydb/document/articles \ -H "Content-Type: application/json" \ -d '{ "_key": "article_001", "title": "Introduction to Machine Learning", "embedding": [0.0123, -0.0456, 0.0789, ...] }'

2. Create a vector index

curl -X POST http://localhost:6745/_api/database/mydb/vector/articles \ -H "Content-Type: application/json" \ -d '{ "name": "embedding_idx", "field": "embedding", "dimension": 1536, "metric": "cosine" }'

3. Search for similar documents

curl -X POST http://localhost:6745/_api/database/mydb/vector/articles/embedding_idx/search \ -H "Content-Type: application/json" \ -d '{ "vector": [0.0111, -0.0222, 0.0333, ...], "limit": 5 }'

4. Or use SDBQL for more complex queries

curl -X POST http://localhost:6745/_api/database/mydb/query \ -H "Content-Type: application/json" \ -d '{ "query": "FOR doc IN articles LET sim = VECTOR_SIMILARITY(doc.embedding, @vec) FILTER sim > 0.8 SORT sim DESC LIMIT 10 RETURN {title: doc.title, score: sim}", "bindVars": { "vec": [0.0111, -0.0222, 0.0333, ...] } }'