Spaces:
Build error
Build error
File size: 6,681 Bytes
3932407 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
import pytest
from .helpers.collection_setup import basic_collection_setup, drop_collection
from .helpers.helpers import request_with_validation
default_name = ""
@pytest.fixture(autouse=True)
def setup(on_disk_vectors, collection_name):
basic_collection_setup(collection_name=collection_name, on_disk_vectors=on_disk_vectors)
yield
drop_collection(collection_name=collection_name)
def test_collection_update(collection_name):
response = request_with_validation(
api='/collections/{collection_name}',
method="PATCH",
path_params={'collection_name': collection_name},
body={
"vectors": {
default_name: {
"hnsw_config": {
"m": 32,
"ef_construct": 123,
},
"quantization_config": {
"scalar": {
"type": "int8",
"quantile": 0.8
}
},
},
},
"sparse_vectors": {
"sparse-text": {
"index": {
"on_disk": True,
}
},
},
"optimizers_config": {
"default_segment_number": 6,
"indexing_threshold": 10000,
},
}
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}/points',
method="PUT",
path_params={'collection_name': collection_name},
query_params={'wait': 'true'},
body={
"points": [
{
"id": 7,
"vector": [0.15, 0.31, 0.76, 0.74],
"payload": {"city": "Rome"}
},
],
}
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}/points/{id}',
method="GET",
path_params={'collection_name': collection_name, 'id': 7},
)
assert response.ok
def test_edit_collection_params(on_disk_vectors, on_disk_payload, collection_name):
response = request_with_validation(
api='/collections/{collection_name}',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
result = response.json()["result"]
config = result["config"]
assert "hnsw_config" not in config["params"]["vectors"]
assert "quantization_config" not in config["params"]["vectors"]
assert config["params"]["vectors"]["on_disk"] == on_disk_vectors
assert not config["params"]["on_disk_payload"]
assert config["hnsw_config"]["m"] == 16
assert config["hnsw_config"]["ef_construct"] == 100
assert config["quantization_config"] is None
response = request_with_validation(
api='/collections/{collection_name}',
method="PATCH",
path_params={'collection_name': collection_name},
body={
"vectors": {
default_name: {
"hnsw_config": {
"m": 32,
},
"quantization_config": {
"scalar": {
"type": "int8",
"quantile": 0.8
}
},
"on_disk": True,
},
},
"hnsw_config": {
"ef_construct": 123,
},
"quantization_config": {
"scalar": {
"type": "int8",
"quantile": 0.99,
"always_ram": True
}
},
"params": {
"on_disk_payload": on_disk_payload,
},
}
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
result = response.json()["result"]
config = result["config"]
assert config["params"]["vectors"]["hnsw_config"]["m"] == 32
assert config["params"]["vectors"]["quantization_config"]["scalar"]["type"] == "int8"
assert config["params"]["vectors"]["quantization_config"]["scalar"]["quantile"] == 0.8
assert "always_ram" not in config["params"]["vectors"]["quantization_config"]["scalar"]
assert config["params"]["vectors"]["on_disk"]
assert config["params"]["on_disk_payload"] == on_disk_payload
assert config["hnsw_config"]["m"] == 16
assert config["hnsw_config"]["ef_construct"] == 123
assert config["quantization_config"]["scalar"]["type"] == "int8"
assert config["quantization_config"]["scalar"]["quantile"] == 0.99
assert config["quantization_config"]["scalar"]["always_ram"]
response = request_with_validation(
api='/collections/{collection_name}',
method="PATCH",
path_params={'collection_name': collection_name},
body={
"vectors": {
default_name: {
"hnsw_config": {
"m": 10,
"ef_construct": 100,
},
"quantization_config": {
"product": {
"compression": "x32",
"always_ram": True
}
},
"on_disk": False,
},
},
"params": {
"on_disk_payload": on_disk_payload,
},
}
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
result = response.json()["result"]
config = result["config"]
assert config["params"]["vectors"]["hnsw_config"]["m"] == 10
assert config["params"]["vectors"]["hnsw_config"]["ef_construct"] == 100
assert config["params"]["vectors"]["quantization_config"]["product"]["compression"] == "x32"
assert config["params"]["vectors"]["quantization_config"]["product"]["always_ram"]
assert not config["params"]["vectors"]["on_disk"]
assert config["params"]["on_disk_payload"] == on_disk_payload
assert config["quantization_config"]["scalar"]["type"] == "int8"
assert config["quantization_config"]["scalar"]["quantile"] == 0.99
assert config["quantization_config"]["scalar"]["always_ram"]
|