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