■ MilvusClient 클래스의 delete 메소드에서 collection_name/filter 인자를 사용해 엔터티를 삭제하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import numpy as np from pymilvus import MilvusClient milvusClient = MilvusClient("test.db") hasCollection = milvusClient.has_collection(collection_name = "temp") if milvusClient.has_collection(collection_name= "temp"): milvusClient.drop_collection(collection_name = "temp") milvusClient.create_collection( collection_name = "temp", dimension = 384 ) stringList = [ "Artificial intelligence was founded as an academic discipline in 1956.", "Alan Turing was the first person to conduct substantial research in AI.", "Born in Maida Vale, London, Turing was raised in southern England." ] stringVectorList = [[ np.random.uniform(-1, 1) for _ in range(384) ] for _ in range(len(stringList)) ] # NDArray list itemList = [{"id" : i, "vector" : stringVectorList[i], "text" : stringList[i], "subject" : "history"} for i in range(len(stringVectorList))] milvusClient.insert( collection_name = "temp", data = itemList ) extraList1 = milvusClient.search( collection_name = "temp", data = [stringVectorList[0]], filter = "subject == 'history'", limit = 2, output_fields = ["text", "subject"] ) print(extraList1[0][0]) print(extraList1[0][1]) print("-" * 100) extraList2 = milvusClient.query( collection_name = "temp", filter = "subject == 'history'", output_fields = ["text", "subject"] ) print(extraList2[0]) print(extraList2[1]) print(extraList2[2]) print("-" * 100) deletedIDList = milvusClient.delete( collection_name = "temp", filter = "subject == 'history'" ) # int list print(deletedIDList) print("-" * 100) """ {'id': 0, 'distance': 1.0000003576278687, 'entity': {'text': 'Artificial intelligence was founded as an academic discipline in 1956.', 'subject': 'history'}} {'id': 2, 'distance': 0.09245504438877106, 'entity': {'text': 'Born in Maida Vale, London, Turing was raised in southern England.', 'subject': 'history'}} |
{'id': 0, 'text': 'Artificial intelligence was founded as an academic discipline in 1956.', 'subject': 'history'}
{'id': 1, 'text': 'Alan Turing was the first person to conduct substantial research in AI.', 'subject': 'history'}
{'id': 2, 'text': 'Born in Maida Vale, London, Turing was raised in southern England.', 'subject': 'history'}
—————————————————————————————————-
[0, 1, 2]
—————————————————————————————————-
"""
—————————————————————————————————-
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
certifi==2024.8.30 charset-normalizer==3.3.2 coloredlogs==15.0.1 environs==9.5.0 filelock==3.16.1 flatbuffers==24.3.25 fsspec==2024.9.0 grpcio==1.66.2 huggingface-hub==0.25.1 humanfriendly==10.0 idna==3.10 marshmallow==3.22.0 milvus-lite==2.4.10 milvus-model==0.2.7 mpmath==1.3.0 numpy==2.1.2 onnxruntime==1.19.2 packaging==24.1 pandas==2.2.3 protobuf==5.28.2 pymilvus==2.4.7 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 pytz==2024.2 PyYAML==6.0.2 regex==2024.9.11 requests==2.32.3 safetensors==0.4.5 scipy==1.14.1 six==1.16.0 sympy==1.13.3 tokenizers==0.20.0 tqdm==4.66.5 transformers==4.45.1 typing_extensions==4.12.2 tzdata==2024.2 ujson==5.10.0 urllib3==2.2.3 |
※ pip install pymilvus[model] 명령을 실행했다.