HNSW-based approximate nearest neighbor search.
# Create a vector index
db.create_vector_index("items", "embedding", dimension=384, metric="cosine")
# Insert documents with embeddings
db.insert("items", {
"title": "Introduction to Rust",
"embedding": [0.1, 0.5, -0.3, ...] # 384-dim vector
})
# Search for similar items
results = db.vector_search("items", "embedding", query_vector, limit=10)
| Metric | Formula | Range |
|---|---|---|
cosine | 1 - cos(a, b) | [0, 2] |
euclidean | L2 distance | [0, inf) |
dot | -dot(a, b) | (-inf, inf) |
Results include document ID, raw distance, and a normalized similarity score in [0, 1].