{"id":32984,"date":"2025-04-26T10:26:40","date_gmt":"2025-04-26T02:26:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/32984.html"},"modified":"2025-04-26T10:26:40","modified_gmt":"2025-04-26T02:26:40","slug":"milvus%ef%bc%884%ef%bc%89%ef%bc%9a%e5%88%9b%e5%bb%ba-collections","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/32984.html","title":{"rendered":"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections"},"content":{"rendered":"<h2>1\u00a0\u521b\u5efa Collections<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49 Schema\u3001\u7d22\u5f15\u53c2\u6570\u3001\u5ea6\u91cf\u7c7b\u578b\u4ee5\u53ca\u521b\u5efa\u65f6\u662f\u5426\u52a0\u8f7d\u6765\u521b\u5efa\u4e00\u4e2a Collection\u3002<\/p>\n<h3>1.1\u00a0\u96c6\u5408\u6982\u8ff0<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Collection \u662f\u4e00\u4e2a\u4e8c\u7ef4\u8868&#xff0c;\u5177\u6709\u56fa\u5b9a\u7684\u5217\u548c\u53d8\u5316\u7684\u884c\u3002\u6bcf\u5217\u4ee3\u8868\u4e00\u4e2a\u5b57\u6bb5&#xff0c;\u6bcf\u884c\u4ee3\u8868\u4e00\u4e2a\u5b9e\u4f53\u3002\u8981\u5b9e\u73b0\u8fd9\u6837\u7684\u7ed3\u6784\u5316\u6570\u636e\u7ba1\u7406&#xff0c;\u9700\u8981\u4e00\u4e2a Schema\u3002\u8981\u63d2\u5165\u7684\u6bcf\u4e2a\u5b9e\u4f53\u90fd\u5fc5\u987b\u7b26\u5408 Schema \u4e2d\u5b9a\u4e49\u7684\u7ea6\u675f\u6761\u4ef6\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f60\u53ef\u4ee5\u786e\u5b9a Collections \u7684\u65b9\u65b9\u9762\u9762&#xff0c;\u5305\u62ec\u5176 Schema\u3001\u7d22\u5f15\u53c2\u6570\u3001\u5ea6\u91cf\u7c7b\u578b&#xff0c;\u4ee5\u53ca\u662f\u5426\u5728\u521b\u5efa\u65f6\u52a0\u8f7d&#xff0c;\u4ee5\u786e\u4fdd\u96c6\u5408\u5b8c\u5168\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\u3002\u8981\u521b\u5efa\u4e00\u4e2a Collection&#xff0c;\u60a8\u9700\u8981<\/p>\n<li>\u521b\u5efa Schema<\/li>\n<li>\u8bbe\u7f6e\u7d22\u5f15\u53c2\u6570&#xff08;\u53ef\u9009&#xff09;<\/li>\n<li>\u521b\u5efa Collections<\/li>\n<h3>1.2\u00a0\u521b\u5efa Schema<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Schema \u5b9a\u4e49\u4e86 Collections \u7684\u6570\u636e\u7ed3\u6784\u3002\u521b\u5efa Collections \u65f6&#xff0c;\u9700\u8981\u6839\u636e\u81ea\u5df1\u7684\u8981\u6c42\u8bbe\u8ba1\u6a21\u5f0f\u3002\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u521b\u5efa\u4e86\u4e00\u4e2a\u6a21\u5f0f&#xff0c;\u5176\u4e2d\u5305\u542b\u542f\u7528\u7684 Dynamic Field \u548c\u4e09\u4e2a\u5fc5\u586b\u5b57\u6bb5&#xff0c;\u5206\u522b\u547d\u540d\u4e3amy_id\u00a0\u3001my_vector\u00a0\u548cmy_varchar\u00a0\u3002<\/p>\n<p>from pymilvus import MilvusClient, DataType<\/p>\n<p>client &#061; MilvusClient(<br \/>\n    uri&#061;&#034;http:\/\/localhost:19530&#034;,<br \/>\n    token&#061;&#034;root:Milvus&#034;<br \/>\n)<\/p>\n<p>schema &#061; MilvusClient.create_schema(<br \/>\n    auto_id&#061;False,<br \/>\n    enable_dynamic_field&#061;True,<br \/>\n)<\/p>\n<p>schema.add_field(field_name&#061;&#034;my_id&#034;, datatype&#061;DataType.INT64, is_primary&#061;True)<br \/>\nschema.add_field(field_name&#061;&#034;my_vector&#034;, datatype&#061;DataType.FLOAT_VECTOR, dim&#061;5)<br \/>\nschema.add_field(field_name&#061;&#034;my_varchar&#034;, datatype&#061;DataType.VARCHAR, max_length&#061;512)<\/p>\n<h3>1.3\u00a0(\u53ef\u9009&#xff09;\u8bbe\u7f6e\u7d22\u5f15\u53c2\u6570<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u7279\u5b9a\u5b57\u6bb5\u4e0a\u521b\u5efa\u7d22\u5f15\u53ef\u52a0\u5feb\u5bf9\u8be5\u5b57\u6bb5\u7684\u641c\u7d22\u3002\u7d22\u5f15\u8bb0\u5f55\u4e86 Collections \u4e2d\u5b9e\u4f53\u7684\u987a\u5e8f\u3002\u5982\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u6240\u793a&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528metric_type\u00a0\u548cindex_type\u00a0\u4e3a Milvus \u9009\u62e9\u9002\u5f53\u7684\u65b9\u5f0f\u4e3a\u5b57\u6bb5\u5efa\u7acb\u7d22\u5f15&#xff0c;\u5e76\u6d4b\u91cf\u5411\u91cf\u5d4c\u5165\u4e4b\u95f4\u7684\u76f8\u4f3c\u6027\u3002\u5728 Milvus \u4e0a&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528AUTOINDEX\u00a0\u4f5c\u4e3a\u6240\u6709\u5411\u91cf\u573a\u7684\u7d22\u5f15\u7c7b\u578b&#xff0c;\u5e76\u6839\u636e\u9700\u8981\u4f7f\u7528COSINE\u00a0\u3001L2\u00a0\u548cIP\u00a0\u4e2d\u7684\u4e00\u79cd\u4f5c\u4e3a\u5ea6\u91cf\u7c7b\u578b\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u6240\u793a&#xff0c;\u60a8\u9700\u8981\u4e3a\u5411\u91cf\u573a\u540c\u65f6\u8bbe\u7f6e\u7d22\u5f15\u7c7b\u578b\u548c\u5ea6\u91cf\u7c7b\u578b&#xff0c;\u800c\u53ea\u9700\u4e3a\u6807\u91cf\u573a\u8bbe\u7f6e\u7d22\u5f15\u7c7b\u578b\u3002\u7d22\u5f15\u5bf9\u4e8e\u5411\u91cf\u5b57\u6bb5\u662f\u5f3a\u5236\u6027\u7684&#xff0c;\u5efa\u8bae\u60a8\u5728\u7b5b\u9009\u6761\u4ef6\u4e2d\u7ecf\u5e38\u4f7f\u7528\u7684\u6807\u91cf\u5b57\u6bb5\u4e0a\u521b\u5efa\u7d22\u5f15\u3002<\/p>\n<p>index_params &#061; client.prepare_index_params()<\/p>\n<p>index_params.add_index(<br \/>\n    field_name&#061;&#034;my_id&#034;,<br \/>\n    index_type&#061;&#034;AUTOINDEX&#034;<br \/>\n)<\/p>\n<p>index_params.add_index(<br \/>\n    field_name&#061;&#034;my_vector&#034;,<br \/>\n    index_type&#061;&#034;AUTOINDEX&#034;,<br \/>\n    metric_type&#061;&#034;COSINE&#034;<br \/>\n)<\/p>\n<h3>1.4\u00a0\u521b\u5efa Collections<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u521b\u5efa\u4e86\u5e26\u6709\u7d22\u5f15\u53c2\u6570\u7684 Collection&#xff0c;Milvus \u4f1a\u5728\u521b\u5efa\u65f6\u81ea\u52a8\u52a0\u8f7d\u8be5 Collection\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;\u7d22\u5f15\u53c2\u6570\u4e2d\u63d0\u5230\u7684\u6240\u6709\u5b57\u6bb5\u90fd\u4f1a\u88ab\u7d22\u5f15\u3002\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u6f14\u793a\u4e86\u5982\u4f55\u521b\u5efa\u5e26\u7d22\u5f15\u53c2\u6570\u7684 Collections \u5e76\u68c0\u67e5\u5176\u52a0\u8f7d\u72b6\u6001\u3002<\/p>\n<p>client.create_collection(<br \/>\n    collection_name&#061;&#034;customized_setup_1&#034;,<br \/>\n    schema&#061;schema,<br \/>\n    index_params&#061;index_params<br \/>\n)<\/p>\n<p>res &#061; client.get_load_state(<br \/>\n    collection_name&#061;&#034;customized_setup_1&#034;<br \/>\n)<\/p>\n<p>print(res)<\/p>\n<p># Output<br \/>\n#<br \/>\n# {<br \/>\n#     &#034;state&#034;: &#034;&lt;LoadState: Loaded&gt;&#034;<br \/>\n# }<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e0d\u5e26\u4efb\u4f55\u7d22\u5f15\u53c2\u6570\u7684 Collections&#xff0c;\u7136\u540e\u518d\u6dfb\u52a0\u7d22\u5f15\u53c2\u6570\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;Milvus \u4e0d\u4f1a\u5728\u521b\u5efa\u65f6\u52a0\u8f7d Collection\u3002.\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u6f14\u793a\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u4e0d\u5e26\u96c6\u5408\u7684 Collection&#xff0c;\u521b\u5efa\u65f6\u96c6\u5408\u7684\u52a0\u8f7d\u72b6\u6001\u4ecd\u4e3a\u672a\u52a0\u8f7d\u3002<\/p>\n<p>client.create_collection(<br \/>\n    collection_name&#061;&#034;customized_setup_2&#034;,<br \/>\n    schema&#061;schema,<br \/>\n)<\/p>\n<p>res &#061; client.get_load_state(<br \/>\n    collection_name&#061;&#034;customized_setup_2&#034;<br \/>\n)<\/p>\n<p>print(res)<\/p>\n<p># Output<br \/>\n#<br \/>\n# {<br \/>\n#     &#034;state&#034;: &#034;&lt;LoadState: NotLoad&gt;&#034;<br \/>\n# } <\/p>\n<h3>1.5\u00a0\u8bbe\u7f6e Collections \u5c5e\u6027<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u60a8\u53ef\u4ee5\u4e3a\u8981\u521b\u5efa\u7684 Collection \u8bbe\u7f6e\u5c5e\u6027&#xff0c;\u4f7f\u5176\u9002\u5408\u60a8\u7684\u670d\u52a1\u3002\u9002\u7528\u7684\u5c5e\u6027\u5982\u4e0b\u3002<\/p>\n<h4>1.5.1\u00a0\u8bbe\u7f6e\u5206\u7247\u7f16\u53f7<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5206\u7247\u662f Collections \u7684\u6c34\u5e73\u5207\u7247\u3002\u6bcf\u4e2a\u5206\u533a\u5bf9\u5e94\u4e00\u4e2a\u6570\u636e\u8f93\u5165\u901a\u9053\u3002\u6bcf\u4e2a Collections \u9ed8\u8ba4\u90fd\u6709\u4e00\u4e2a\u5206\u7247\u3002\u521b\u5efa Collections \u65f6&#xff0c;\u53ef\u6839\u636e\u9884\u671f\u541e\u5410\u91cf\u548c\u8981\u63d2\u5165 Collections \u7684\u6570\u636e\u91cf\u8bbe\u7f6e\u9002\u5f53\u7684\u5206\u7247\u6570\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u5e38\u89c1\u60c5\u51b5\u4e0b&#xff0c;\u6bcf\u5f53\u9884\u671f\u541e\u5410\u91cf\u589e\u52a0 500 MB\/\u79d2\u6216\u8981\u63d2\u5165\u7684\u6570\u636e\u91cf\u589e\u52a0 100 GB \u65f6&#xff0c;\u5c31\u53ef\u4ee5\u8003\u8651\u589e\u52a0\u4e00\u4e2a\u5206\u7247\u3002\u8fd9\u4e00\u5efa\u8bae\u662f\u57fa\u4e8e\u6211\u4eec\u81ea\u5df1\u7684\u7ecf\u9a8c&#xff0c;\u53ef\u80fd\u5e76\u4e0d\u5b8c\u5168\u9002\u5408\u60a8\u7684\u5e94\u7528\u573a\u666f\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u8c03\u6574\u8fd9\u4e2a\u6570\u5b57&#xff0c;\u6216\u8005\u76f4\u63a5\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u6f14\u793a\u4e86\u5982\u4f55\u5728\u521b\u5efa Collection \u65f6\u8bbe\u7f6e\u5206\u7247\u6570\u3002<\/p>\n<p># \u5e26\u5206\u7247\u53f7<br \/>\nclient.create_collection(<br \/>\n    collection_name&#061;&#034;customized_setup_3&#034;,<br \/>\n    schema&#061;schema,<br \/>\n    # highlight-next-line<br \/>\n    num_shards&#061;1<br \/>\n) <\/p>\n<h4>1.5.2\u00a0\u542f\u7528 mmap<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Milvus \u9ed8\u8ba4\u5728\u6240\u6709 Collections \u4e0a\u542f\u7528 mmap&#xff0c;\u5141\u8bb8 Milvus \u5c06\u539f\u59cb\u5b57\u6bb5\u6570\u636e\u6620\u5c04\u5230\u5185\u5b58\u4e2d&#xff0c;\u800c\u4e0d\u662f\u5b8c\u5168\u52a0\u8f7d\u5b83\u4eec\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u5360\u7528&#xff0c;\u63d0\u9ad8 Collections \u7684\u5bb9\u91cf\u3002<\/p>\n<p># With mmap<br \/>\nclient.create_collection(<br \/>\n    collection_name&#061;&#034;customized_setup_4&#034;,<br \/>\n    schema&#061;schema,<br \/>\n    # highlight-next-line<br \/>\n    enable_mmap&#061;False<br \/>\n)<br \/>\nexport params&#061;&#039;{<br \/>\n    &#034;mmap.enabled&#034;: True<br \/>\n}&#039;<\/p>\n<p>export CLUSTER_ENDPOINT&#061;&#034;http:\/\/localhost:19530&#034;<br \/>\nexport TOKEN&#061;&#034;root:Milvus&#034;<\/p>\n<p>curl &#8211;request POST \\\\<br \/>\n&#8211;url &#034;${CLUSTER_ENDPOINT}\/v2\/vectordb\/collections\/create&#034; \\\\<br \/>\n&#8211;header &#034;Authorization: Bearer ${TOKEN}&#034; \\\\<br \/>\n&#8211;header &#034;Content-Type: application\/json&#034; \\\\<br \/>\n-d &#034;{<br \/>\n    \\\\&#034;collectionName\\\\&#034;: \\\\&#034;customized_setup_5\\\\&#034;,<br \/>\n    \\\\&#034;schema\\\\&#034;: $schema,<br \/>\n    \\\\&#034;params\\\\&#034;: $params<br \/>\n}&#034;<\/p>\n<h4>1.5.3\u00a0\u8bbe\u7f6e Collections TTL<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u67d0\u4e2a Collection \u4e2d\u7684\u6570\u636e\u9700\u8981\u5728\u7279\u5b9a\u65f6\u95f4\u6bb5\u5185\u4e22\u5f03&#xff0c;\u53ef\u4ee5\u8003\u8651\u8bbe\u7f6e\u5176 Time-To-Live (TTL)&#xff0c;\u5355\u4f4d\u4e3a\u79d2\u3002\u4e00\u65e6 TTL \u8d85\u65f6&#xff0c;Milvus \u5c31\u4f1a\u5220\u9664 Collection \u4e2d\u7684\u5b9e\u4f53\u3002\u5220\u9664\u662f\u5f02\u6b65\u7684&#xff0c;\u8fd9\u8868\u660e\u5728\u5220\u9664\u5b8c\u6210\u4e4b\u524d&#xff0c;\u641c\u7d22\u548c\u67e5\u8be2\u4ecd\u7136\u53ef\u4ee5\u8fdb\u884c\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u5c06 TTL \u8bbe\u7f6e\u4e3a\u4e00\u5929&#xff08;86400 \u79d2&#xff09;\u3002\u5efa\u8bae\u81f3\u5c11\u5c06 TTL \u8bbe\u7f6e\u4e3a\u51e0\u5929\u3002<\/p>\n<p>client.create_collection(<br \/>\n    collection_name&#061;&#034;customized_setup_5&#034;,<br \/>\n    schema&#061;schema,<br \/>\n    # highlight-start<br \/>\n    properties&#061;{<br \/>\n        &#034;collection.ttl.seconds&#034;: 86400<br \/>\n    }<br \/>\n    # highlight-end<br \/>\n)<\/p>\n<h4>1.5.4\u00a0\u8bbe\u7f6e\u4e00\u81f4\u6027\u7ea7\u522b<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u521b\u5efa Collections \u65f6&#xff0c;\u53ef\u4ee5\u4e3a\u96c6\u5408\u4e2d\u7684\u641c\u7d22\u548c\u67e5\u8be2\u8bbe\u7f6e\u4e00\u81f4\u6027\u7ea7\u522b\u3002\u60a8\u8fd8\u53ef\u4ee5\u5728\u7279\u5b9a\u641c\u7d22\u6216\u67e5\u8be2\u8fc7\u7a0b\u4e2d\u66f4\u6539 Collections \u7684\u4e00\u81f4\u6027\u7ea7\u522b\u3002<\/p>\n<p>client.create_collection(<br \/>\n    collection_name&#061;&#034;customized_setup_6&#034;,<br \/>\n    schema&#061;schema,<br \/>\n    # highlight-next<br \/>\n    consistency_level&#061;&#034;Bounded&#034;,<br \/>\n) <\/p>\n<h4>1.5.5\u00a0\u542f\u7528\u52a8\u6001\u5b57\u6bb5<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Collections \u4e2d\u7684\u52a8\u6001\u5b57\u6bb5\u662f\u4e00\u4e2a\u4fdd\u7559\u7684 JavaScript Object Notation (JSON) \u5b57\u6bb5&#xff0c;\u540d\u4e3a$meta\u3002\u542f\u7528\u8be5\u5b57\u6bb5\u540e&#xff0c;Milvus \u4f1a\u5c06\u6bcf\u4e2a\u5b9e\u4f53\u4e2d\u643a\u5e26\u7684\u6240\u6709\u975e Schema \u5b9a\u4e49\u5b57\u6bb5\u53ca\u5176\u503c\u4f5c\u4e3a\u952e\u503c\u5bf9\u4fdd\u5b58\u5728\u4fdd\u7559\u5b57\u6bb5\u4e2d\u3002<\/p>\n<h2>2\u00a0\u5373\u65f6\u521b\u5efa Collections<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u901a\u8fc7\u8bbe\u7f6e\u540d\u79f0\u548c\u5411\u91cf\u573a\u7ef4\u5ea6&#xff0c;\u53ef\u4ee5\u7acb\u5373\u521b\u5efa\u4e00\u4e2a Collection\u3002\u521b\u5efa\u65f6&#xff0c;Milvus \u4f1a\u81ea\u52a8\u7d22\u5f15\u5411\u91cf\u573a\u5e76\u52a0\u8f7d Collections\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0AIGC \u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u4f7f\u7528\u5411\u91cf\u6570\u636e\u5e93\u4f5c\u4e3a\u77e5\u8bc6\u5e93&#xff0c;\u7ba1\u7406\u7528\u6237\u4e0e\u5927\u578b\u8bed\u8a00\u6a21\u578b&#xff08;LLMs&#xff09;\u4ea4\u4e92\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u6570\u636e\u3002\u8fd9\u4e9b\u77e5\u8bc6\u5e93\u51e0\u4e4e\u662f\u76f8\u4f3c\u7684\u3002\u4e3a\u4e86\u52a0\u5feb Milvus Collections \u5728\u6b64\u7c7b\u573a\u666f\u4e2d\u7684\u4f7f\u7528&#xff0c;\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u79cd\u5373\u65f6\u65b9\u6cd5&#xff0c;\u53ea\u9700\u4e24\u4e2a\u53c2\u6570&#xff0c;\u5373 Collections \u540d\u79f0\u548c\u5411\u91cf\u573a\u7ef4\u5ea6&#xff0c;\u5373\u53ef\u521b\u5efa\u4e00\u4e2a Collection\u3002\u4f7f\u7528\u9ed8\u8ba4\u8bbe\u7f6e\u5373\u65f6\u521b\u5efa Collections \u65f6&#xff0c;\u4ee5\u4e0b\u8bbe\u7f6e\u9002\u7528&#xff1a;<\/p>\n<ul>\n<li>\u4e3b\u5b57\u6bb5\u548c\u5411\u91cf\u5b57\u6bb5\u88ab\u6dfb\u52a0\u5230 Schema \u4e2d&#xff08;id\u548c\u5411\u91cf&#xff09;\u3002<\/li>\n<li>\u4e3b\u5b57\u6bb5\u63a5\u53d7\u6574\u6570\u5e76\u7981\u7528AutoId\u3002<\/li>\n<li>\u5411\u91cf\u5b57\u6bb5\u63a5\u53d7\u6d6e\u52a8\u5411\u91cf Embeddings\u3002<\/li>\n<li>AUTOINDEX\u7528\u4e8e\u5728\u5411\u91cf\u5b57\u6bb5\u4e0a\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li>COSINE\u7528\u4e8e\u6d4b\u91cf\u5411\u91cf\u5d4c\u5165\u4e4b\u95f4\u7684\u76f8\u4f3c\u6027\u3002<\/li>\n<li>\u542f\u7528\u540d\u4e3a$meta\u7684\u50a8\u5907\u52a8\u6001\u5b57\u6bb5&#xff0c;\u53ef\u5c06\u975e Schema \u5b9a\u4e49\u7684\u5b57\u6bb5\u53ca\u5176\u503c\u4fdd\u5b58\u4e3a\u952e\u503c\u5bf9\u3002<\/li>\n<li>\u8be5 Collections \u4f1a\u5728\u521b\u5efa\u65f6\u81ea\u52a8\u52a0\u8f7d\u3002<\/li>\n<\/ul>\n<h3>2.1\u00a0\u5feb\u901f\u8bbe\u7f6e<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;\u60a8\u53ea\u9700\u8f93\u5165\u96c6\u5408\u540d\u79f0\u548c\u5411\u91cf\u573a\u7ef4\u6570&#xff0c;\u5373\u53ef\u5373\u65f6\u521b\u5efa\u96c6\u5408\u3002<\/p>\n<p>from pymilvus import MilvusClient, DataType<\/p>\n<p>CLUSTER_ENDPOINT &#061; &#034;http:\/\/localhost:19530&#034;<br \/>\nTOKEN &#061; &#034;root:Milvus&#034;<\/p>\n<p># 1. \u8bbe\u7f6e\u4e00\u4e2aMilvus\u5ba2\u6237\u7aef<br \/>\nclient &#061; MilvusClient(<br \/>\n    uri&#061;CLUSTER_ENDPOINT,<br \/>\n    token&#061;TOKEN<br \/>\n)<\/p>\n<p># 2. \u5728\u5feb\u901f\u8bbe\u7f6e\u6a21\u5f0f\u4e0b\u521b\u5efa\u96c6\u5408<br \/>\nclient.create_collection(<br \/>\n    collection_name&#061;&#034;quick_setup&#034;,<br \/>\n    dimension&#061;5<br \/>\n)<\/p>\n<p>res &#061; client.get_load_state(<br \/>\n    collection_name&#061;&#034;quick_setup&#034;<br \/>\n)<\/p>\n<p>print(res)<\/p>\n<p># Output<br \/>\n#<br \/>\n# {<br \/>\n#     &#034;state&#034;: &#034;&lt;LoadState: Loaded&gt;&#034;<br \/>\n# } <\/p>\n<h3>2.2\u00a0\u4f7f\u7528\u81ea\u5b9a\u4e49\u5b57\u6bb5\u5feb\u901f\u8bbe\u7f6e<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c\u9ed8\u8ba4\u7684\u5ea6\u91cf\u7c7b\u578b\u3001\u5b57\u6bb5\u540d\u79f0\u548c\u6570\u636e\u7c7b\u578b\u4e0d\u80fd\u6ee1\u8db3\u60a8\u7684\u9700\u6c42&#xff0c;\u60a8\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u5f0f\u8c03\u6574\u8fd9\u4e9b\u8bbe\u7f6e\u3002<\/p>\n<p>from pymilvus import MilvusClient, DataType<\/p>\n<p>CLUSTER_ENDPOINT &#061; &#034;http:\/\/localhost:19530&#034;<br \/>\nTOKEN &#061; &#034;root:Milvus&#034;<\/p>\n<p># 1. \u8bbe\u7f6e\u4e00\u4e2aMilvus\u5ba2\u6237\u7aef<br \/>\nclient &#061; MilvusClient(<br \/>\n    uri&#061;CLUSTER_ENDPOINT,<br \/>\n    token&#061;TOKEN<br \/>\n)<\/p>\n<p># 2. \u5728\u5feb\u901f\u8bbe\u7f6e\u6a21\u5f0f\u4e0b\u521b\u5efa\u96c6\u5408<br \/>\nclient.create_collection(<br \/>\n    collection_name&#061;&#034;custom_quick_setup&#034;,<br \/>\n    dimension&#061;5,<br \/>\n    primary_field_name&#061;&#034;my_id&#034;,<br \/>\n    id_type&#061;&#034;string&#034;,<br \/>\n    vector_field_name&#061;&#034;my_vector&#034;,<br \/>\n    metric_type&#061;&#034;L2&#034;,<br \/>\n    auto_id&#061;True,<br \/>\n    max_length&#061;512<br \/>\n)<\/p>\n<p>res &#061; client.get_load_state(<br \/>\n    collection_name&#061;&#034;custom_quick_setup&#034;<br \/>\n)<\/p>\n<p>print(res)<\/p>\n<p># Output<br \/>\n#<br \/>\n# {<br \/>\n#     &#034;state&#034;: &#034;&lt;LoadState: Loaded&gt;&#034;<br \/>\n# }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb824\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf14\u6b21\u3002Collection \u662f\u4e00\u4e2a\u4e8c\u7ef4\u8868\uff0c\u5177\u6709\u56fa\u5b9a\u7684\u5217\u548c\u53d8\u5316\u7684\u884c\u3002\u6bcf\u5217\u4ee3\u8868\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6bcf\u884c\u4ee3\u8868\u4e00\u4e2a\u5b9e\u4f53\u3002\u8981\u5b9e\u73b0\u8fd9\u6837\u7684\u7ed3\u6784\u5316\u6570\u636e\u7ba1\u7406\uff0c\u9700\u8981\u4e00\u4e2a Schema\u3002\u8981\u63d2\u5165\u7684\u6bcf\u4e2a\u5b9e\u4f53\u90fd\u5fc5\u987b\u7b26\u5408 Schema \u4e2d\u5b9a\u4e49\u7684\u7ea6\u675f\u6761\u4ef6\u3002\u4f60\u53ef\u4ee5\u786e\u5b9a Collections \u7684\u65b9\u65b9\u9762\u9762\uff0c\u5305\u62ec\u5176 Schema\u3001\u7d22\u5f15\u53c2\u6570\u3001\u5ea6\u91cf\u7c7b\u578b\uff0c\u4ee5\u53ca\u662f\u5426\u5728\u521b\u5efa\u65f6\u52a0\u8f7d\uff0c\u4ee5\u786e\u4fdd\u96c6\u5408\u5b8c\u5168\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\u3002\u8981\u521b\u5efa\u4e00\u4e2a Collection\uff0c\u60a8\u9700\u8981\u521b\u5efa Schema\u8bbe\u7f6e\u7d22\u5f15\u53c2\u6570\uff08\u53ef\u9009\uff09\u521b\u5efa Collections\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[247,1741],"topic":[],"class_list":["post-32984","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai","tag-milvus"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Milvus\uff084\uff09\uff1a\u521b\u5efa Collections - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/32984.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb824\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf14\u6b21\u3002Collection \u662f\u4e00\u4e2a\u4e8c\u7ef4\u8868\uff0c\u5177\u6709\u56fa\u5b9a\u7684\u5217\u548c\u53d8\u5316\u7684\u884c\u3002\u6bcf\u5217\u4ee3\u8868\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6bcf\u884c\u4ee3\u8868\u4e00\u4e2a\u5b9e\u4f53\u3002\u8981\u5b9e\u73b0\u8fd9\u6837\u7684\u7ed3\u6784\u5316\u6570\u636e\u7ba1\u7406\uff0c\u9700\u8981\u4e00\u4e2a Schema\u3002\u8981\u63d2\u5165\u7684\u6bcf\u4e2a\u5b9e\u4f53\u90fd\u5fc5\u987b\u7b26\u5408 Schema \u4e2d\u5b9a\u4e49\u7684\u7ea6\u675f\u6761\u4ef6\u3002\u4f60\u53ef\u4ee5\u786e\u5b9a Collections \u7684\u65b9\u65b9\u9762\u9762\uff0c\u5305\u62ec\u5176 Schema\u3001\u7d22\u5f15\u53c2\u6570\u3001\u5ea6\u91cf\u7c7b\u578b\uff0c\u4ee5\u53ca\u662f\u5426\u5728\u521b\u5efa\u65f6\u52a0\u8f7d\uff0c\u4ee5\u786e\u4fdd\u96c6\u5408\u5b8c\u5168\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\u3002\u8981\u521b\u5efa\u4e00\u4e2a Collection\uff0c\u60a8\u9700\u8981\u521b\u5efa Schema\u8bbe\u7f6e\u7d22\u5f15\u53c2\u6570\uff08\u53ef\u9009\uff09\u521b\u5efa Collections\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/32984.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-26T02:26:40+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32984.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/32984.html\",\"name\":\"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-26T02:26:40+00:00\",\"dateModified\":\"2025-04-26T02:26:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/32984.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/32984.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32984.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/32984.html","og_locale":"zh_CN","og_type":"article","og_title":"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb824\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf14\u6b21\u3002Collection \u662f\u4e00\u4e2a\u4e8c\u7ef4\u8868\uff0c\u5177\u6709\u56fa\u5b9a\u7684\u5217\u548c\u53d8\u5316\u7684\u884c\u3002\u6bcf\u5217\u4ee3\u8868\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6bcf\u884c\u4ee3\u8868\u4e00\u4e2a\u5b9e\u4f53\u3002\u8981\u5b9e\u73b0\u8fd9\u6837\u7684\u7ed3\u6784\u5316\u6570\u636e\u7ba1\u7406\uff0c\u9700\u8981\u4e00\u4e2a Schema\u3002\u8981\u63d2\u5165\u7684\u6bcf\u4e2a\u5b9e\u4f53\u90fd\u5fc5\u987b\u7b26\u5408 Schema \u4e2d\u5b9a\u4e49\u7684\u7ea6\u675f\u6761\u4ef6\u3002\u4f60\u53ef\u4ee5\u786e\u5b9a Collections \u7684\u65b9\u65b9\u9762\u9762\uff0c\u5305\u62ec\u5176 Schema\u3001\u7d22\u5f15\u53c2\u6570\u3001\u5ea6\u91cf\u7c7b\u578b\uff0c\u4ee5\u53ca\u662f\u5426\u5728\u521b\u5efa\u65f6\u52a0\u8f7d\uff0c\u4ee5\u786e\u4fdd\u96c6\u5408\u5b8c\u5168\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\u3002\u8981\u521b\u5efa\u4e00\u4e2a Collection\uff0c\u60a8\u9700\u8981\u521b\u5efa Schema\u8bbe\u7f6e\u7d22\u5f15\u53c2\u6570\uff08\u53ef\u9009\uff09\u521b\u5efa Collections\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/32984.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-26T02:26:40+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/32984.html","url":"https:\/\/www.wsisp.com\/helps\/32984.html","name":"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-26T02:26:40+00:00","dateModified":"2025-04-26T02:26:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/32984.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/32984.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/32984.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Milvus\uff084\uff09\uff1a\u521b\u5efa Collections"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=32984"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32984\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=32984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=32984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=32984"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=32984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}