@@ -162,12 +162,14 @@ class Meta:
162162 @skipUnlessDBFeature ("supports_atlas_search" )
163163 def test_invalid_similarities_function (self ):
164164 class Article (models .Model ):
165- vector_data = ArrayField (models .DecimalField (), size = 10 )
165+ vector1 = ArrayField (models .DecimalField (), size = 10 )
166+ vector2 = ArrayField (models .DecimalField (), size = 10 )
167+ vector3 = ArrayField (models .DecimalField (), size = 10 )
166168
167169 class Meta :
168170 indexes = [
169171 VectorSearchIndex (
170- fields = ["vector_data " , "vector_data " , "vector_data " ],
172+ fields = ["vector1 " , "vector2 " , "vector3 " ],
171173 similarities = ["sum" , "dotProduct" , "tangh" ],
172174 ),
173175 ]
@@ -191,6 +193,34 @@ class Meta:
191193 ],
192194 )
193195
196+ @skipUnlessDBFeature ("supports_atlas_search" )
197+ def test_define_field_twice (self ):
198+ class Article (models .Model ):
199+ vector_data = ArrayField (models .DecimalField (), size = 10 )
200+
201+ class Meta :
202+ indexes = [
203+ VectorSearchIndex (
204+ fields = ["vector_data" , "vector_data" ],
205+ similarities = "dotProduct" ,
206+ ),
207+ ]
208+
209+ errors = checks .run_checks (app_configs = self .apps .get_app_configs (), databases = {"default" })
210+ self .assertEqual (
211+ errors ,
212+ [
213+ checks .Error (
214+ "Field 'vector_data' is defined more than once. Vector and filter"
215+ " fields must use distinct field names." ,
216+ id = "django_mongodb_backend.indexes.VectorSearchIndex.E005" ,
217+ hint = "If you need different configurations for the same field,"
218+ " create separate indexes." ,
219+ obj = Article ._meta .indexes [0 ],
220+ ),
221+ ],
222+ )
223+
194224 @skipUnlessDBFeature ("supports_atlas_search" )
195225 def test_simple (self ):
196226 class Article (models .Model ):
0 commit comments