-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathtest_config_methods.py
More file actions
247 lines (223 loc) · 8.5 KB
/
test_config_methods.py
File metadata and controls
247 lines (223 loc) · 8.5 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
from weaviate.collections.classes.config_methods import (
_collection_config_from_json,
_collection_configs_simple_from_json,
_nested_properties_from_config,
_properties_from_config,
)
def test_collection_config_simple_from_json_with_none_vectorizer_config() -> None:
"""Test that _collection_configs_simple_from_json handles None vectorizer config."""
schema = {
"classes": [
{
"class": "TestCollection",
"vectorConfig": {
"default": {
"vectorizer": {"text2vec-transformers": None},
"vectorIndexType": "hnsw",
"vectorIndexConfig": {
"skip": False,
"cleanupIntervalSeconds": 300,
"maxConnections": 64,
"efConstruction": 128,
"ef": -1,
"dynamicEfMin": 100,
"dynamicEfMax": 500,
"dynamicEfFactor": 8,
"vectorCacheMaxObjects": 1000000000000,
"flatSearchCutoff": 40000,
"distance": "cosine",
},
}
},
"properties": [],
"invertedIndexConfig": {
"bm25": {"b": 0.75, "k1": 1.2},
"cleanupIntervalSeconds": 60,
"stopwords": {"preset": "en", "additions": None, "removals": None},
},
"replicationConfig": {"factor": 1, "deletionStrategy": "NoAutomatedResolution"},
"shardingConfig": {
"virtualPerPhysical": 128,
"desiredCount": 1,
"actualCount": 1,
"desiredVirtualCount": 128,
"actualVirtualCount": 128,
"key": "_id",
"strategy": "hash",
"function": "murmur3",
},
"vectorIndexType": "hnsw",
"vectorIndexConfig": {
"skip": False,
"cleanupIntervalSeconds": 300,
"maxConnections": 64,
"efConstruction": 128,
"ef": -1,
"dynamicEfMin": 100,
"dynamicEfMax": 500,
"dynamicEfFactor": 8,
"vectorCacheMaxObjects": 1000000000000,
"flatSearchCutoff": 40000,
"distance": "cosine",
},
}
]
}
configs = _collection_configs_simple_from_json(schema)
assert "TestCollection" in configs
vec_config = configs["TestCollection"].vector_config
assert vec_config is not None
assert "default" in vec_config
assert vec_config["default"].vectorizer.model == {}
assert vec_config["default"].vectorizer.source_properties is None
def _make_text_prop(name: str, **extra) -> dict:
base = {
"name": name,
"dataType": ["text"],
"indexFilterable": True,
"indexSearchable": True,
"indexRangeFilters": False,
"tokenization": "word",
}
base.update(extra)
return base
def test_properties_from_config_parses_text_analyzer() -> None:
schema = {
"vectorizer": "none",
"properties": [
_make_text_prop(
"title",
textAnalyzer={"asciiFold": True, "asciiFoldIgnore": ["é"]},
),
_make_text_prop("body"),
],
}
props = _properties_from_config(schema)
title = next(p for p in props if p.name == "title")
body = next(p for p in props if p.name == "body")
assert title.text_analyzer is not None
assert title.text_analyzer.ascii_fold is True
assert title.text_analyzer.ascii_fold_ignore == ["é"]
assert body.text_analyzer is None
# The dataclass round-trips back to the wire format.
assert title.to_dict()["textAnalyzer"] == {
"asciiFold": True,
"asciiFoldIgnore": ["é"],
}
assert "textAnalyzer" not in body.to_dict()
def test_properties_from_config_text_analyzer_omitted_when_no_ascii_fold() -> None:
"""If the server response omits asciiFold, the client treats text_analyzer as unset."""
schema = {
"vectorizer": "none",
"properties": [
# Server response with textAnalyzer present but no asciiFold key
_make_text_prop("title", textAnalyzer={"asciiFoldIgnore": ["é"]}),
],
}
title = _properties_from_config(schema)[0]
assert title.text_analyzer is None
def test_nested_properties_from_config_parses_text_analyzer() -> None:
nested = _nested_properties_from_config(
[
_make_text_prop(
"title",
textAnalyzer={"asciiFold": True, "asciiFoldIgnore": ["ñ"]},
),
]
)
assert nested[0].text_analyzer is not None
assert nested[0].text_analyzer.ascii_fold is True
assert nested[0].text_analyzer.ascii_fold_ignore == ["ñ"]
assert nested[0].to_dict()["textAnalyzer"] == {
"asciiFold": True,
"asciiFoldIgnore": ["ñ"],
}
def test_properties_from_config_parses_stopword_preset_only() -> None:
"""A property with only stopwordPreset (no asciiFold) must still produce a text_analyzer."""
schema = {
"vectorizer": "none",
"properties": [
_make_text_prop("title", textAnalyzer={"stopwordPreset": "fr"}),
],
}
title = _properties_from_config(schema)[0]
assert title.text_analyzer is not None
assert title.text_analyzer.ascii_fold is False
assert title.text_analyzer.ascii_fold_ignore is None
assert title.text_analyzer.stopword_preset == "fr"
def test_properties_from_config_parses_combined_text_analyzer() -> None:
schema = {
"vectorizer": "none",
"properties": [
_make_text_prop(
"title",
textAnalyzer={
"asciiFold": True,
"asciiFoldIgnore": ["é"],
"stopwordPreset": "fr",
},
),
],
}
title = _properties_from_config(schema)[0]
assert title.text_analyzer is not None
assert title.text_analyzer.ascii_fold is True
assert title.text_analyzer.ascii_fold_ignore == ["é"]
assert title.text_analyzer.stopword_preset == "fr"
def _full_schema(class_name: str, **inverted_overrides) -> dict:
inverted = {
"bm25": {"b": 0.75, "k1": 1.2},
"cleanupIntervalSeconds": 60,
"stopwords": {"preset": "en", "additions": None, "removals": None},
}
inverted.update(inverted_overrides)
return {
"class": class_name,
"vectorizer": "none",
"properties": [],
"invertedIndexConfig": inverted,
"replicationConfig": {"factor": 1, "deletionStrategy": "NoAutomatedResolution"},
"shardingConfig": {
"virtualPerPhysical": 128,
"desiredCount": 1,
"actualCount": 1,
"desiredVirtualCount": 128,
"actualVirtualCount": 128,
"key": "_id",
"strategy": "hash",
"function": "murmur3",
},
"vectorIndexType": "hnsw",
"vectorIndexConfig": {
"skip": False,
"cleanupIntervalSeconds": 300,
"maxConnections": 64,
"efConstruction": 128,
"ef": -1,
"dynamicEfMin": 100,
"dynamicEfMax": 500,
"dynamicEfFactor": 8,
"vectorCacheMaxObjects": 1000000000000,
"flatSearchCutoff": 40000,
"distance": "cosine",
},
}
def test_collection_config_parses_stopword_presets() -> None:
"""The inverted index config exposes stopwordPresets when present in the schema."""
schema = _full_schema(
"TestStopwordPresets",
stopwordPresets={
"fr": ["le", "la", "les"],
"es": ["el", "la", "los"],
},
)
full = _collection_config_from_json(schema)
assert full.inverted_index_config.stopword_presets == {
"fr": ["le", "la", "les"],
"es": ["el", "la", "los"],
}
def test_collection_config_stopword_presets_absent() -> None:
"""If the server response omits stopwordPresets, the parsed value is None."""
schema = _full_schema("TestNoStopwordPresets")
full = _collection_config_from_json(schema)
assert full.inverted_index_config.stopword_presets is None