()
| 487 | |
| 488 | |
| 489 | def main(): |
| 490 | vector_db_name = "usv_test_db" |
| 491 | num_vectors = 1_000_000 |
| 492 | dimension = 20_000_000 |
| 493 | max_non_zero_dims = 100 |
| 494 | num_queries = 100 |
| 495 | batch_size = 100 |
| 496 | top_k = 10 |
| 497 | early_terminate_threshold = 0.5 |
| 498 | |
| 499 | Path("datasets/usv_dataset").mkdir(parents=True, exist_ok=True) |
| 500 | |
| 501 | # Generate or load dataset |
| 502 | vectors = generate_dataset(num_vectors, dimension, max_non_zero_dims) |
| 503 | |
| 504 | # Select query vectors |
| 505 | query_vectors = select_query_vectors(vectors, num_queries) |
| 506 | |
| 507 | # Compute brute force results |
| 508 | brute_force_results = compute_brute_force_results( |
| 509 | vectors, query_vectors, dimension, top_k |
| 510 | ) |
| 511 | |
| 512 | # Login to get access token |
| 513 | print("Logging in to server...") |
| 514 | create_session() |
| 515 | print("Session established") |
| 516 | insert_vectors = input("Insert vectors? (Y/n): ").strip().lower() in ["y", ""] |
| 517 | |
| 518 | # collection = None |
| 519 | if insert_vectors: |
| 520 | # Create collection |
| 521 | try: |
| 522 | print(f"Creating collection: {vector_db_name}") |
| 523 | create_db(name=vector_db_name) |
| 524 | print("Collection created") |
| 525 | |
| 526 | # Create explicit index |
| 527 | create_explicit_index(vector_db_name) |
| 528 | print("Explicit index created") |
| 529 | except Exception as e: |
| 530 | print(f"Collection may already exist: {e}") |
| 531 | |
| 532 | # Insert vectors into server using a single transaction |
| 533 | print("Creating single transaction for all vectors") |
| 534 | print(f"Inserting {num_vectors} vectors in batches of {batch_size}...") |
| 535 | start = time.time() |
| 536 | |
| 537 | # Create single transaction and process all batches within it |
| 538 | txn_id = create_transaction(vector_db_name) |
| 539 | with ThreadPoolExecutor(max_workers=32) as executor: |
| 540 | futures = [] |
| 541 | for batch_start in range(0, num_vectors, batch_size): |
| 542 | batch = vectors[batch_start : batch_start + batch_size] |
| 543 | futures.append( |
| 544 | executor.submit(upsert_in_transaction, vector_db_name, txn_id, batch) |
| 545 | ) |
| 546 |
no test coverage detected