SimpleVecDB provides async wrappers for use in async/await contexts. These are thin wrappers around the synchronous API using ThreadPoolExecutor.
Quick Start
import asyncio
from simplevecdb import AsyncVectorDB
async def main():
db = AsyncVectorDB("vectors.db")
collection = db.collection("docs")
# Add documents asynchronously
ids = await collection.add_texts(
["Hello world", "Async is great"],
embeddings=[[0.1] * 384, [0.2] * 384]
)
# Search asynchronously
results = await collection.similarity_search([0.1] * 384, k=5)
return results
results = asyncio.run(main())
Configuration
The async wrappers use a ThreadPoolExecutor for concurrent operations. You can configure the number of workers:
# Default: 4 workers
db = AsyncVectorDB("vectors.db")
# Custom worker count
db = AsyncVectorDB("vectors.db", max_workers=8)
Available Methods
AsyncVectorCollection provides async versions of all search and modification methods:
| Sync Method | Async Method |
|---|---|
add_texts() |
await collection.add_texts() |
similarity_search() |
await collection.similarity_search() |
similarity_search_batch() |
await collection.similarity_search_batch() |
keyword_search() |
await collection.keyword_search() |
hybrid_search() |
await collection.hybrid_search() |
max_marginal_relevance_search() |
await collection.max_marginal_relevance_search() |
delete_by_ids() |
await collection.delete_by_ids() |
remove_texts() |
await collection.remove_texts() |
Synchronous properties remain unchanged:
collection.name- Collection name
Concurrent Operations
Run multiple searches in parallel with asyncio.gather or use batch search for better performance:
async def concurrent_search():
db = AsyncVectorDB("vectors.db")
collection = db.collection("docs")
queries = [[0.1] * 384, [0.2] * 384, [0.3] * 384]
# Option 1: Batch search (recommended, ~10x faster)
results = await collection.similarity_search_batch(queries, k=5)
# Option 2: Concurrent individual searches
results = await asyncio.gather(*[
collection.similarity_search(q, k=5)
for q in queries
])
return results
When to Use
Use Async API when:
- Building async web servers (FastAPI, aiohttp)
- Running concurrent searches
- Integrating with async frameworks
Use Sync API when:
- Simple scripts and notebooks
- Single-threaded applications
- Maximum simplicity is needed
API Reference
simplevecdb.async_core.AsyncVectorDB
Async wrapper for VectorDB.
Creates a thread pool executor for running synchronous SQLite operations without blocking the async event loop.
Example
async def main(): ... db = AsyncVectorDB("my_vectors.db") ... collection = db.collection("documents") ... await collection.add_texts(["hello"], embeddings=[[0.1]384]) ... results = await collection.similarity_search([0.1]384) ... await db.close()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to SQLite database file. Use ":memory:" for in-memory DB. |
':memory:'
|
distance_strategy
|
DistanceStrategy
|
Distance metric (COSINE, L2, or L1). |
COSINE
|
quantization
|
Quantization
|
Vector quantization (FLOAT, INT8, or BIT). |
FLOAT
|
max_workers
|
int
|
Number of threads in executor pool. Default 4. |
4
|
**kwargs
|
Any
|
Additional arguments passed to VectorDB. |
{}
|
Source code in src/simplevecdb/async_core.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
collection(name='default', distance_strategy=None, quantization=None)
Get or create a named vector collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Collection name (alphanumeric + underscore only). |
'default'
|
distance_strategy
|
DistanceStrategy | None
|
Override database-level distance metric. |
None
|
quantization
|
Quantization | None
|
Override database-level quantization. |
None
|
Returns:
| Type | Description |
|---|---|
AsyncVectorCollection
|
AsyncVectorCollection instance. |
Source code in src/simplevecdb/async_core.py
list_collections()
search_collections(query, collections=None, k=10, filter=None, *, normalize_scores=True, parallel=True)
async
Search across multiple collections with merged, ranked results.
See VectorDB.search_collections for full documentation.
Source code in src/simplevecdb/async_core.py
vacuum(checkpoint_wal=True)
async
Reclaim disk space by rebuilding the database file.
Async wrapper for VectorDB.vacuum(). See sync version for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_wal
|
bool
|
If True (default), also truncate the WAL file. |
True
|
Source code in src/simplevecdb/async_core.py
close()
async
Close the database connection and shutdown executor.
Source code in src/simplevecdb/async_core.py
__aenter__()
async
simplevecdb.async_core.AsyncVectorCollection
Async wrapper for VectorCollection.
All methods are async versions of the synchronous VectorCollection methods, executed in a thread pool to avoid blocking the event loop.
Source code in src/simplevecdb/async_core.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
name
property
Collection name.
add_texts(texts, metadatas=None, embeddings=None, ids=None)
async
Add texts with optional embeddings and metadata.
See VectorCollection.add_texts for full documentation.
Source code in src/simplevecdb/async_core.py
similarity_search(query, k=5, filter=None, *, exact=None, threads=0)
async
Search for most similar vectors.
See VectorCollection.similarity_search for full documentation.
Source code in src/simplevecdb/async_core.py
similarity_search_batch(queries, k=5, filter=None, *, exact=None, threads=0)
async
Batch search for multiple query vectors.
See VectorCollection.similarity_search_batch for full documentation.
Source code in src/simplevecdb/async_core.py
keyword_search(query, k=5, filter=None)
async
Search using BM25 keyword ranking.
See VectorCollection.keyword_search for full documentation.
Source code in src/simplevecdb/async_core.py
hybrid_search(query, k=5, filter=None, *, query_vector=None, vector_k=None, keyword_k=None, rrf_k=60)
async
Combine keyword and vector search using Reciprocal Rank Fusion.
See VectorCollection.hybrid_search for full documentation.
Source code in src/simplevecdb/async_core.py
max_marginal_relevance_search(query, k=5, fetch_k=20, lambda_mult=0.5, filter=None)
async
Search with diversity using Max Marginal Relevance.
See VectorCollection.max_marginal_relevance_search for full documentation.
Source code in src/simplevecdb/async_core.py
delete_by_ids(ids)
async
Delete documents by their IDs.
See VectorCollection.delete_by_ids for full documentation.
Source code in src/simplevecdb/async_core.py
remove_texts(texts=None, filter=None)
async
Remove documents by text content or metadata filter.
See VectorCollection.remove_texts for full documentation.
Source code in src/simplevecdb/async_core.py
cluster(n_clusters=None, algorithm='minibatch_kmeans', *, filter=None, sample_size=None, min_cluster_size=5, random_state=None)
async
Cluster documents by their embeddings (async).
See VectorCollection.cluster for full documentation.
Source code in src/simplevecdb/async_core.py
auto_tag(cluster_result, *, method='keywords', n_keywords=5, custom_callback=None)
async
Generate descriptive tags for clusters (async).
See VectorCollection.auto_tag for full documentation.
Source code in src/simplevecdb/async_core.py
assign_cluster_metadata(cluster_result, tags=None, *, metadata_key='cluster', tag_key='cluster_tag')
async
Persist cluster assignments to metadata (async).
See VectorCollection.assign_cluster_metadata for full documentation.
Source code in src/simplevecdb/async_core.py
get_cluster_members(cluster_id, *, metadata_key='cluster')
async
Get all documents in a cluster (async).
See VectorCollection.get_cluster_members for full documentation.
Source code in src/simplevecdb/async_core.py
save_cluster(name, cluster_result, *, metadata=None)
async
Save cluster state for later assignment (async).
See VectorCollection.save_cluster for full documentation.
Source code in src/simplevecdb/async_core.py
load_cluster(name)
async
Load saved cluster state (async).
See VectorCollection.load_cluster for full documentation.
Source code in src/simplevecdb/async_core.py
list_clusters()
async
List all saved cluster configurations (async).
See VectorCollection.list_clusters for full documentation.
Source code in src/simplevecdb/async_core.py
delete_cluster(name)
async
Delete a saved cluster configuration (async).
See VectorCollection.delete_cluster for full documentation.
Source code in src/simplevecdb/async_core.py
assign_to_cluster(name, doc_ids, *, metadata_key='cluster')
async
Assign documents to a saved cluster (async).
See VectorCollection.assign_to_cluster for full documentation.