@@ -165,9 +165,43 @@ def test_field_not_exists(self):
165
165
name = "recent_article_idx" ,
166
166
fields = ["headline" , "non_existing_name" , "title_embedded" ],
167
167
)
168
- with connection .schema_editor () as editor :
169
- msg = "Article has no field named 'non_existing_name'"
170
- with self .assertRaisesMessage (
171
- FieldDoesNotExist , msg
172
- ), connection .schema_editor () as editor :
173
- editor .add_index (index = index , model = Article )
168
+ msg = "Article has no field named 'non_existing_name'"
169
+ with self .assertRaisesMessage (FieldDoesNotExist , msg ), connection .schema_editor () as editor :
170
+ editor .add_index (index = index , model = Article )
171
+
172
+ def test_field_size_required (self ):
173
+ index = VectorSearchIndex (
174
+ name = "recent_article_idx" ,
175
+ fields = ["number_list" ],
176
+ )
177
+ msg = "Atlas vector search requires size."
178
+ with self .assertRaisesMessage (ValueError , msg ), connection .schema_editor () as editor :
179
+ editor .add_index (index = index , model = Article )
180
+
181
+ def test_field_type_mismatch (self ):
182
+ index = VectorSearchIndex (
183
+ name = "recent_article_idx" ,
184
+ fields = ["name_list" ],
185
+ )
186
+ msg = "Base type must be Float or Decimal."
187
+ with self .assertRaisesMessage (ValueError , msg ), connection .schema_editor () as editor :
188
+ editor .add_index (index = index , model = Article )
189
+
190
+ def test_field_unsuported_type (self ):
191
+ index = VectorSearchIndex (
192
+ name = "recent_article_idx" ,
193
+ fields = ["data" ],
194
+ )
195
+ msg = "Unsupported filter of type JSONField."
196
+ with self .assertRaisesMessage (ValueError , msg ), connection .schema_editor () as editor :
197
+ editor .add_index (index = index , model = Article )
198
+
199
+ def test_field_unsuported_similarity_function (self ):
200
+ msg = (
201
+ "cross_product isn't a valid similarity function, options"
202
+ f" 'are { ',' .join (VectorSearchIndex .ALLOWED_SIMILARITY_FUNCTIONS )} "
203
+ )
204
+ with self .assertRaisesMessage (ValueError , msg ):
205
+ VectorSearchIndex (
206
+ name = "recent_article_idx" , fields = ["data" ], similarities = "cross_product"
207
+ )
0 commit comments