|
| 1 | +import pytest |
| 2 | + |
| 3 | +from .helpers.helpers import request_with_validation |
| 4 | +from .helpers.collection_setup import drop_collection, multivec_collection_setup |
| 5 | + |
| 6 | +collection_name = 'test_collection_update_multivec' |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(autouse=True) |
| 10 | +def setup(): |
| 11 | + multivec_collection_setup(collection_name=collection_name) |
| 12 | + yield |
| 13 | + drop_collection(collection_name=collection_name) |
| 14 | + |
| 15 | + |
| 16 | +def test_collection_update_multivec(): |
| 17 | + response = request_with_validation( |
| 18 | + api='/collections/{collection_name}', |
| 19 | + method="PATCH", |
| 20 | + path_params={'collection_name': collection_name}, |
| 21 | + body={ |
| 22 | + "vectors": { |
| 23 | + "image": { |
| 24 | + "hnsw_config": { |
| 25 | + "m": 32, |
| 26 | + "ef_construct": 123, |
| 27 | + } |
| 28 | + } |
| 29 | + }, |
| 30 | + "optimizers_config": { |
| 31 | + "default_segment_number": 6, |
| 32 | + "indexing_threshold": 10000, |
| 33 | + }, |
| 34 | + } |
| 35 | + ) |
| 36 | + assert response.ok |
| 37 | + |
| 38 | + response = request_with_validation( |
| 39 | + api='/collections/{collection_name}/points', |
| 40 | + method="PUT", |
| 41 | + path_params={'collection_name': collection_name}, |
| 42 | + query_params={'wait': 'true'}, |
| 43 | + body={ |
| 44 | + "points": [ |
| 45 | + { |
| 46 | + "id": 7, |
| 47 | + "vector": { |
| 48 | + "image": [0.15, 0.31, 0.76, 0.74] |
| 49 | + }, |
| 50 | + "payload": {"city": "Rome"} |
| 51 | + } |
| 52 | + ] |
| 53 | + } |
| 54 | + ) |
| 55 | + assert response.ok |
| 56 | + |
| 57 | + response = request_with_validation( |
| 58 | + api='/collections/{collection_name}/points/{id}', |
| 59 | + method="GET", |
| 60 | + path_params={'collection_name': collection_name, 'id': 7}, |
| 61 | + ) |
| 62 | + assert response.ok |
| 63 | + |
| 64 | + |
| 65 | +def test_hnsw_update(): |
| 66 | + response = request_with_validation( |
| 67 | + api='/collections/{collection_name}', |
| 68 | + method="GET", |
| 69 | + path_params={'collection_name': collection_name}, |
| 70 | + ) |
| 71 | + assert response.ok |
| 72 | + result = response.json()["result"] |
| 73 | + config = result["config"] |
| 74 | + assert "hnsw_config" not in config["params"]["vectors"] |
| 75 | + assert config["hnsw_config"]["m"] == 16 |
| 76 | + assert config["hnsw_config"]["ef_construct"] == 100 |
| 77 | + |
| 78 | + response = request_with_validation( |
| 79 | + api='/collections/{collection_name}', |
| 80 | + method="PATCH", |
| 81 | + path_params={'collection_name': collection_name}, |
| 82 | + body={ |
| 83 | + "vectors": { |
| 84 | + "text": { |
| 85 | + "hnsw_config": { |
| 86 | + "m": 32, |
| 87 | + } |
| 88 | + } |
| 89 | + }, |
| 90 | + "hnsw_config": { |
| 91 | + "ef_construct": 123, |
| 92 | + }, |
| 93 | + } |
| 94 | + ) |
| 95 | + assert response.ok |
| 96 | + |
| 97 | + response = request_with_validation( |
| 98 | + api='/collections/{collection_name}', |
| 99 | + method="GET", |
| 100 | + path_params={'collection_name': collection_name}, |
| 101 | + ) |
| 102 | + assert response.ok |
| 103 | + result = response.json()["result"] |
| 104 | + config = result["config"] |
| 105 | + assert config["params"]["vectors"]["text"]["hnsw_config"]["m"] == 32 |
| 106 | + assert config["hnsw_config"]["m"] == 16 |
| 107 | + assert config["hnsw_config"]["ef_construct"] == 123 |
| 108 | + |
| 109 | + response = request_with_validation( |
| 110 | + api='/collections/{collection_name}', |
| 111 | + method="PATCH", |
| 112 | + path_params={'collection_name': collection_name}, |
| 113 | + body={ |
| 114 | + "vectors": { |
| 115 | + "text": { |
| 116 | + "hnsw_config": { |
| 117 | + "m": 10, |
| 118 | + "ef_construct": 100, |
| 119 | + } |
| 120 | + } |
| 121 | + }, |
| 122 | + } |
| 123 | + ) |
| 124 | + assert response.ok |
| 125 | + |
| 126 | + response = request_with_validation( |
| 127 | + api='/collections/{collection_name}', |
| 128 | + method="GET", |
| 129 | + path_params={'collection_name': collection_name}, |
| 130 | + ) |
| 131 | + assert response.ok |
| 132 | + result = response.json()["result"] |
| 133 | + config = result["config"] |
| 134 | + assert config["params"]["vectors"]["text"]["hnsw_config"]["m"] == 10 |
| 135 | + assert config["params"]["vectors"]["text"]["hnsw_config"]["ef_construct"] == 100 |
| 136 | + |
| 137 | + |
| 138 | +def test_invalid_vector_name(): |
| 139 | + response = request_with_validation( |
| 140 | + api='/collections/{collection_name}', |
| 141 | + method="PATCH", |
| 142 | + path_params={'collection_name': collection_name}, |
| 143 | + body={ |
| 144 | + "vectors": { |
| 145 | + "i_do_no_exist": { |
| 146 | + "hnsw_config": { |
| 147 | + "m": 32, |
| 148 | + } |
| 149 | + } |
| 150 | + }, |
| 151 | + } |
| 152 | + ) |
| 153 | + assert not response.ok |
| 154 | + assert response.status_code == 400 |
| 155 | + error = response.json()["status"]["error"] |
| 156 | + assert error == "Wrong input: Not existing vector name error: i_do_no_exist" |
0 commit comments