(name)
| 67 | |
| 68 | |
| 69 | def create_explicit_index(name): |
| 70 | data = { |
| 71 | "name": name, |
| 72 | "distance_metric_type": "cosine", |
| 73 | "quantization": {"type": "auto", "properties": {"sample_threshold": 100}}, |
| 74 | "index": { |
| 75 | "type": "hnsw", |
| 76 | "properties": { |
| 77 | "num_layers": 5, |
| 78 | "max_cache_size": 1000, |
| 79 | "ef_construction": 64, |
| 80 | "ef_search": 32, |
| 81 | "neighbors_count": 32, |
| 82 | "level_0_neighbors_count": 64, |
| 83 | }, |
| 84 | }, |
| 85 | } |
| 86 | response = requests.post( |
| 87 | f"{base_url}/collections/{name}/indexes/dense", |
| 88 | headers=generate_headers(), |
| 89 | data=json.dumps(data), |
| 90 | verify=False, |
| 91 | ) |
| 92 | |
| 93 | if response.status_code not in [200, 201, 204]: # Allow 201 |
| 94 | raise Exception( |
| 95 | f"Failed to create index: {response.status_code} ({response.text})" |
| 96 | ) |
| 97 | return response.json() if response.status_code != 204 and response.text else {} |
| 98 | |
| 99 | |
| 100 | # Function to find a database (collection) by Id |
no test coverage detected