{"id":9816,"date":"2024-12-17T18:47:43","date_gmt":"2024-12-17T10:47:43","guid":{"rendered":"http:\/\/www.yliyun.com\/?p=9816"},"modified":"2024-12-17T18:47:43","modified_gmt":"2024-12-17T10:47:43","slug":"milvus-%e8%af%a6%e7%bb%86%e4%bb%8b%e7%bb%8d%e4%b8%8e%e4%b8%8a%e6%89%8b%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/www.yliyun.com\/2024\/12\/17\/milvus-%e8%af%a6%e7%bb%86%e4%bb%8b%e7%bb%8d%e4%b8%8e%e4%b8%8a%e6%89%8b%e6%95%99%e7%a8%8b\/","title":{"rendered":"Milvus \u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u4e0a\u624b\u6559\u7a0b"},"content":{"rendered":"\n

\u4ec0\u4e48\u662f Milvus\uff1f<\/strong><\/p>\n\n\n\n

Milvus \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5411\u91cf\u6570\u636e\u5e93\uff0c\u4e13\u4e3a\u7ba1\u7406\u548c\u68c0\u7d22\u5927\u91cf\u5411\u91cf\u6570\u636e\u800c\u8bbe\u8ba1\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u4eba\u5de5\u667a\u80fd\u3001\u63a8\u8350\u7cfb\u7edf\u3001\u56fe\u50cf\u68c0\u7d22\u3001\u81ea\u7136\u8bed\u8a00\u5904\u7406\u7b49\u9886\u57df\u3002\u5b83\u652f\u6301 PB \u7ea7\u522b\u7684\u6570\u636e\u5b58\u50a8\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u5411\u91cf\u68c0\u7d22\u670d\u52a1\u3002<\/p>\n\n\n\n

Milvus \u7684\u6838\u5fc3\u529f\u80fd<\/strong><\/p>\n\n\n\n

1. \u9ad8\u6548\u68c0\u7d22\uff1a<\/strong> \u652f\u6301 ANN\uff08\u8fd1\u4f3c\u6700\u8fd1\u90bb\uff09\u68c0\u7d22\uff0c\u9002\u7528\u4e8e\u8d85\u5927\u89c4\u6a21\u5411\u91cf\u68c0\u7d22\u4efb\u52a1\u3002<\/p>\n\n\n\n

2. \u591a\u6570\u636e\u7c7b\u578b\uff1a<\/strong> \u652f\u6301\u6587\u672c\u3001\u56fe\u50cf\u3001\u89c6\u9891\u7b49\u591a\u79cd\u5d4c\u5165\u5411\u91cf\u6570\u636e\u3002<\/p>\n\n\n\n

3. \u5f39\u6027\u6269\u5c55\uff1a<\/strong> \u652f\u6301\u6c34\u5e73\u6269\u5c55\u548c\u5206\u5e03\u5f0f\u90e8\u7f72\u3002<\/p>\n\n\n\n

4. \u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff1a<\/strong> \u5305\u62ec IVF\u3001HNSW\u3001DiskANN \u7b49\u3002<\/p>\n\n\n\n

5. \u591a\u8bed\u8a00 SDK \u652f\u6301\uff1a<\/strong> \u63d0\u4f9b Python\u3001Java\u3001Go\u3001C++ \u7b49\u591a\u79cd SDK\u3002<\/p>\n\n\n\n

6. \u4e91\u539f\u751f\u67b6\u6784\uff1a<\/strong> \u652f\u6301 Kubernetes \u90e8\u7f72\uff0c\u4fbf\u4e8e\u4e91\u4e0a\u8fd0\u884c\u3002<\/p>\n\n\n\n

Milvus \u7684\u5e94\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n

1. \u56fe\u50cf\u548c\u89c6\u9891\u68c0\u7d22\uff08\u5185\u5bb9\u63a8\u8350\uff09<\/p>\n\n\n\n

2. \u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08\u8bed\u4e49\u68c0\u7d22\u4e0e\u63a8\u8350\uff09<\/p>\n\n\n\n

3. \u63a8\u8350\u7cfb\u7edf\uff08\u4e2a\u6027\u5316\u63a8\u8350\uff09<\/p>\n\n\n\n

4. \u751f\u7269\u533b\u5b66\u6570\u636e\u5206\u6790\uff08DNA \u6bd4\u5bf9\uff09<\/p>\n\n\n\n

5. \u5b89\u5168\u76d1\u63a7\uff08\u9762\u90e8\u8bc6\u522b\uff09<\/p>\n\n\n\n

Milvus \u5feb\u901f\u4e0a\u624b\u6559\u7a0b<\/strong><\/p>\n\n\n\n

1. \u73af\u5883\u51c6\u5907<\/strong><\/p>\n\n\n\n

\u2022 \u64cd\u4f5c\u7cfb\u7edf\uff1aLinux\/macOS\/Windows<\/p>\n\n\n\n

\u2022 \u5b89\u88c5 Docker\uff08\u63a8\u8350\uff09\u6216 Kubernetes\uff08\u7528\u4e8e\u751f\u4ea7\u73af\u5883\uff09<\/p>\n\n\n\n

2. \u5b89\u88c5 Milvus<\/strong><\/p>\n\n\n\n

\u4f7f\u7528 Docker \u5feb\u901f\u542f\u52a8\uff1a<\/strong><\/p>\n\n\n\n

docker pull milvusdb\/milvus:latest<\/p>\n\n\n\n

docker run -d –name milvus-standalone -p 19530:19530 -p 8080:8080 milvusdb\/milvus:latest<\/p>\n\n\n\n

3. \u521b\u5efa Milvus \u5ba2\u6237\u7aef<\/strong><\/p>\n\n\n\n

\u5b89\u88c5 Milvus Python SDK\uff1a<\/p>\n\n\n\n

pip install pymilvus<\/p>\n\n\n\n

4. \u8fde\u63a5\u5230 Milvus<\/strong><\/p>\n\n\n\n

from pymilvus import connections<\/p>\n\n\n\n

connections.connect(<\/p>\n\n\n\n

    alias=”default”,<\/p>\n\n\n\n

    host=”localhost”,<\/p>\n\n\n\n

    port=”19530″<\/p>\n\n\n\n

)<\/p>\n\n\n\n

5. \u521b\u5efa\u96c6\u5408\u4e0e\u63d2\u5165\u6570\u636e<\/strong><\/p>\n\n\n\n

from pymilvus import Collection, FieldSchema, CollectionSchema, DataType<\/p>\n\n\n\n

# \u5b9a\u4e49\u5b57\u6bb5<\/em><\/p>\n\n\n\n

fields = [<\/p>\n\n\n\n

    FieldSchema(name=”id”, dtype=DataType.INT64, is_primary=True, auto_id=True),<\/p>\n\n\n\n

    FieldSchema(name=”embedding”, dtype=DataType.FLOAT_VECTOR, dim=128)<\/p>\n\n\n\n

]<\/p>\n\n\n\n

# \u5b9a\u4e49\u96c6\u5408\u67b6\u6784<\/em><\/p>\n\n\n\n

schema = CollectionSchema(fields, “\u5411\u91cf\u6570\u636e\u96c6\u5408”)<\/p>\n\n\n\n

# \u521b\u5efa\u96c6\u5408<\/em><\/p>\n\n\n\n

collection = Collection(“example_collection”, schema)<\/p>\n\n\n\n

# \u63d2\u5165\u6570\u636e<\/em><\/p>\n\n\n\n

import numpy as np<\/p>\n\n\n\n

data = [<\/p>\n\n\n\n

    [i for i in range(1000)],              # id<\/em><\/p>\n\n\n\n

    np.random.random([1000, 128]).tolist() # \u968f\u673a\u5411\u91cf<\/em><\/p>\n\n\n\n

]<\/p>\n\n\n\n

collection.insert(data)<\/p>\n\n\n\n

6. \u521b\u5efa\u7d22\u5f15\u4e0e\u68c0\u7d22<\/strong><\/p>\n\n\n\n

# \u521b\u5efa\u7d22\u5f15<\/em><\/p>\n\n\n\n

index_params = {<\/p>\n\n\n\n

    “metric_type”: “L2”,<\/p>\n\n\n\n

    “index_type”: “IVF_FLAT”,<\/p>\n\n\n\n

    “params”: {“nlist”: 100}<\/p>\n\n\n\n

}<\/p>\n\n\n\n

collection.create_index(field_name=”embedding”, index_params=index_params)<\/p>\n\n\n\n

# \u641c\u7d22\u5411\u91cf<\/em><\/p>\n\n\n\n

search_params = {<\/p>\n\n\n\n

    “metric_type”: “L2”,<\/p>\n\n\n\n

    “params”: {“nprobe”: 10}<\/p>\n\n\n\n

}<\/p>\n\n\n\n

query_vector = np.random.random([1, 128]).tolist()<\/p>\n\n\n\n

results = collection.search(<\/p>\n\n\n\n

    data=query_vector,<\/p>\n\n\n\n

    anns_field=”embedding”,<\/p>\n\n\n\n

    param=search_params,<\/p>\n\n\n\n

    limit=5<\/p>\n\n\n\n

)<\/p>\n\n\n\n

# \u8f93\u51fa\u7ed3\u679c<\/em><\/p>\n\n\n\n

for result in results[0]:<\/p>\n\n\n\n

    print(f”ID: {result.id}, Distance: {result.distance}”)<\/p>\n\n\n\n

Milvus \u5b98\u65b9\u8d44\u6e90<\/strong><\/p>\n\n\n\n

\u2022 \u5b98\u7f51\uff1aMilvus \u5b98\u65b9\u7f51\u7ad9<\/a><\/p>\n\n\n\n

\u2022 \u6587\u6863\uff1aMilvus \u6587\u6863\u4e2d\u5fc3<\/a><\/p>\n\n\n\n

\u2022 GitHub\uff1aMilvus GitHub \u4ed3\u5e93<\/a><\/p>\n\n\n\n

\u5982\u679c\u9700\u8981\u66f4\u8be6\u7ec6\u7684\u6559\u7a0b\u6216\u9488\u5bf9\u7279\u5b9a\u573a\u666f\u7684\u4f7f\u7528\u6307\u5bfc\uff0c\u8bf7\u544a\u8bc9\u6211\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4ec0\u4e48\u662f Milvus\uff1f Milvus \u662f\u4e00\u4e2a\u5f00\u6e90\u7684 […]<\/p>\n","protected":false},"author":1,"featured_media":9817,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84,86],"tags":[96],"class_list":["post-9816","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rag","category-86","tag-96"],"_links":{"self":[{"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/posts\/9816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/comments?post=9816"}],"version-history":[{"count":1,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/posts\/9816\/revisions"}],"predecessor-version":[{"id":9818,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/posts\/9816\/revisions\/9818"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/media\/9817"}],"wp:attachment":[{"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/media?parent=9816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/categories?post=9816"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yliyun.com\/wp-json\/wp\/v2\/tags?post=9816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}