|
| 1 | +# Copyright (C) 2019-2024 Zilliz. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 4 | +# in compliance with the License. You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software distributed under the License |
| 9 | +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 10 | +# or implied. See the License for the specific language governing permissions and limitations under |
| 11 | +# the License. |
| 12 | + |
| 13 | +import unittest |
| 14 | +from pymilvus import MilvusClient, MilvusException, DataType |
| 15 | + |
| 16 | + |
| 17 | +class TestDefaultSearch(unittest.TestCase): |
| 18 | + def test_schema_field_limits(self): |
| 19 | + collection_name = "hello_milvus" |
| 20 | + milvus_client = MilvusClient("./local_test.db") |
| 21 | + has_collection = milvus_client.has_collection(collection_name) |
| 22 | + if has_collection: |
| 23 | + milvus_client.drop_collection(collection_name) |
| 24 | + schema = milvus_client.create_schema(enable_dynamic_field=True) |
| 25 | + schema.add_field("id", DataType.INT64, is_primary=True) |
| 26 | + schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=2) |
| 27 | + for i in range(62): |
| 28 | + schema.add_field('a' + str(i), DataType.INT64) |
| 29 | + index_params = milvus_client.prepare_index_params() |
| 30 | + index_params.add_index(field_name = "embeddings", metric_type="L2") |
| 31 | + milvus_client.create_collection(collection_name, schema=schema, index_params=index_params) |
| 32 | + |
| 33 | + def test_schema_field_out_limits(self): |
| 34 | + collection_name = "hello_milvus" |
| 35 | + milvus_client = MilvusClient("./local_test.db") |
| 36 | + has_collection = milvus_client.has_collection(collection_name) |
| 37 | + if has_collection: |
| 38 | + milvus_client.drop_collection(collection_name) |
| 39 | + schema = milvus_client.create_schema(enable_dynamic_field=True) |
| 40 | + schema.add_field("id", DataType.INT64, is_primary=True) |
| 41 | + schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=2) |
| 42 | + for i in range(63): |
| 43 | + schema.add_field('a' + str(i), DataType.INT64) |
| 44 | + index_params = milvus_client.prepare_index_params() |
| 45 | + index_params.add_index(field_name = "embeddings", metric_type="L2") |
| 46 | + with self.assertRaises(MilvusException): |
| 47 | + milvus_client.create_collection(collection_name, schema=schema, index_params=index_params) |
| 48 | + |
| 49 | + def test_varchar_field_maxlen(self): |
| 50 | + collection_name = "hello_milvus" |
| 51 | + milvus_client = MilvusClient("./local_test.db") |
| 52 | + has_collection = milvus_client.has_collection(collection_name) |
| 53 | + if has_collection: |
| 54 | + milvus_client.drop_collection(collection_name) |
| 55 | + schema = milvus_client.create_schema(enable_dynamic_field=True) |
| 56 | + schema.add_field("id", DataType.INT64, is_primary=True) |
| 57 | + schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=2) |
| 58 | + schema.add_field("string", DataType.VARCHAR, max_length=65535) |
| 59 | + index_params = milvus_client.prepare_index_params() |
| 60 | + index_params.add_index(field_name = "embeddings", metric_type="L2") |
| 61 | + milvus_client.create_collection(collection_name, schema=schema, index_params=index_params) |
| 62 | + |
| 63 | + def test_varchar_field_out_maxlen(self): |
| 64 | + collection_name = "hello_milvus" |
| 65 | + milvus_client = MilvusClient("./local_test.db") |
| 66 | + has_collection = milvus_client.has_collection(collection_name) |
| 67 | + if has_collection: |
| 68 | + milvus_client.drop_collection(collection_name) |
| 69 | + schema = milvus_client.create_schema(enable_dynamic_field=True) |
| 70 | + schema.add_field("id", DataType.INT64, is_primary=True) |
| 71 | + schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=2) |
| 72 | + schema.add_field("string", DataType.VARCHAR, max_length=65536) |
| 73 | + index_params = milvus_client.prepare_index_params() |
| 74 | + index_params.add_index(field_name = "embeddings", metric_type="L2") |
| 75 | + with self.assertRaises(MilvusException): |
| 76 | + milvus_client.create_collection(collection_name, schema=schema, index_params=index_params) |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == '__main__': |
| 80 | + unittest.main() |
0 commit comments