()
| 45 | |
| 46 | |
| 47 | def test_basic_functionality(): |
| 48 | # Get password from .env file or prompt securely |
| 49 | password = os.getenv("COSDATA_PASSWORD") |
| 50 | if not password: |
| 51 | password = getpass.getpass("Enter your database password: ") |
| 52 | |
| 53 | # Initialize client |
| 54 | host = os.getenv("COSDATA_HOST", "http://127.0.0.1:8443") |
| 55 | username = os.getenv("COSDATA_USERNAME", "admin") |
| 56 | client = Client(host=host, username=username, password=password, verify=False) |
| 57 | |
| 58 | # Test collection name |
| 59 | collection_name = "test_collection" |
| 60 | |
| 61 | try: |
| 62 | # Create a collection |
| 63 | print("Creating collection...") |
| 64 | collection = client.create_collection( |
| 65 | name=collection_name, |
| 66 | dimension=768, |
| 67 | description="Test collection for basic functionality", |
| 68 | ) |
| 69 | print("Collection created successfully") |
| 70 | |
| 71 | # Create an index |
| 72 | print("Creating index...") |
| 73 | index = collection.create_index( |
| 74 | distance_metric="cosine", |
| 75 | num_layers=7, |
| 76 | max_cache_size=1000, |
| 77 | ef_construction=512, |
| 78 | ef_search=256, |
| 79 | neighbors_count=32, |
| 80 | level_0_neighbors_count=64, |
| 81 | ) |
| 82 | print("Index created successfully") |
| 83 | |
| 84 | # Generate test vectors |
| 85 | print("Generating test vectors...") |
| 86 | test_vectors = [] |
| 87 | for i in range(10): |
| 88 | values = np.random.uniform(-1, 1, 768).tolist() |
| 89 | test_vectors.append( |
| 90 | { |
| 91 | "id": f"vec_{i}", |
| 92 | "dense_values": values, |
| 93 | } |
| 94 | ) |
| 95 | |
| 96 | # Insert vectors using transaction |
| 97 | print("Inserting vectors...") |
| 98 | txn_id = None |
| 99 | with collection.transaction() as txn: |
| 100 | txn.batch_upsert_vectors(test_vectors) |
| 101 | txn_id = txn.transaction_id |
| 102 | |
| 103 | print("Vectors inserted successfully") |
| 104 |
no test coverage detected