|
| 1 | +# Introduction |
| 2 | +Milvus is an open-source vector database built to power embedding similarity search and AI applications. Milvus makes unstructured data search more accessible, and provides a consistent user experience regardless of the deployment environment. |
| 3 | +Milvus Lite is a lightweight version of Milvus that can be embedded into your Python application, integrating the core vector search functionality of Milvus. |
| 4 | +Please note that it is not suggested to use Milvus Lite in a production environment. Consider using Milvus clustered or the fully managed Milvus on Cloud. |
| 5 | + |
| 6 | +# Requirements |
| 7 | +Milvus Lite is available in: |
| 8 | +- Google Colab |
| 9 | +- Jupyter Notebook |
| 10 | + |
| 11 | +Here's also a list of verified OS types where Milvus Lite can successfully build and run: |
| 12 | +- Ubuntu >= 20.04 (x86_64) |
| 13 | +- MacOS >= 11.0 (Apple Silicon) |
| 14 | + |
| 15 | +# Installation |
| 16 | +```shell |
| 17 | +pip install pymilvus |
| 18 | +``` |
| 19 | + |
| 20 | +# Usage |
| 21 | +In `pymilvus`, specify a local file name as uri parameter of MilvusClient to use Milvus Lite. |
| 22 | +```python |
| 23 | +from pymilvus import MilvusClient |
| 24 | +client = MilvusClient("./milvus_demo.db") |
| 25 | +``` |
| 26 | +Or with old `connections.connect` API (not recommended): |
| 27 | +```python |
| 28 | +from pymilvus import connections |
| 29 | +connections.connect(uri="./milvus_demo.db") |
| 30 | +``` |
| 31 | + |
| 32 | +# Examples |
| 33 | + |
| 34 | +```python |
| 35 | +from pymilvus import MilvusClient |
| 36 | +import numpy as np |
| 37 | + |
| 38 | +client = MilvusClient("./milvus_demo.db") |
| 39 | +client.create_collection( |
| 40 | + collection_name="demo_collection", |
| 41 | + dimension=384 # The vectors we will use in this demo has 384 dimensions |
| 42 | +) |
| 43 | + |
| 44 | +# Text strings to search from. |
| 45 | +docs = [ |
| 46 | + "Artificial intelligence was founded as an academic discipline in 1956.", |
| 47 | + "Alan Turing was the first person to conduct substantial research in AI.", |
| 48 | + "Born in Maida Vale, London, Turing was raised in southern England.", |
| 49 | +] |
| 50 | +# For illustration, here we use fake vectors with random numbers (384 dimension). |
| 51 | + |
| 52 | +vectors = [[ np.random.uniform(-1, 1) for _ in range(384) ] for _ in range(len(docs)) ] |
| 53 | +data = [ {"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"} for i in range(len(vectors)) ] |
| 54 | +res = client.insert( |
| 55 | + collection_name="demo_collection", |
| 56 | + data=data |
| 57 | +) |
| 58 | + |
| 59 | +# This will exclude any text in "history" subject despite close to the query vector. |
| 60 | +res = client.search( |
| 61 | + collection_name="demo_collection", |
| 62 | + data=[vectors[0]], |
| 63 | + filter="subject == 'history'", |
| 64 | + limit=2, |
| 65 | + output_fields=["text", "subject"], |
| 66 | +) |
| 67 | +print(res) |
| 68 | + |
| 69 | +# a query that retrieves all entities matching filter expressions. |
| 70 | +res = client.query( |
| 71 | + collection_name="demo_collection", |
| 72 | + filter="subject == 'history'", |
| 73 | + output_fields=["text", "subject"], |
| 74 | +) |
| 75 | +print(res) |
| 76 | + |
| 77 | +# delete |
| 78 | +res = client.delete( |
| 79 | + collection_name="demo_collection", |
| 80 | + filter="subject == 'history'", |
| 81 | +) |
| 82 | +print(res) |
| 83 | +``` |
| 84 | + |
| 85 | +# Contributing |
| 86 | +If you want to contribute to Milvus Lite, please read the [Contributing Guide](https://github.com/milvus-io/milvus-lite/blob/main/CONTRIBUTING.md) first. |
| 87 | + |
| 88 | +# Report a bug |
| 89 | +When you use or develop milvus-lite, if you find any bug, please report it to us. You could submit an issue in [milvus-lite](https://github.com/milvus-io/milvus-lite/issues/new/choose) or report you [milvus](https://github.com/milvus-io/milvus/issues/new/choose) repo if you think it is a Milvus issue. |
| 90 | + |
| 91 | +# License |
| 92 | +Milvus Lite is under the Apache 2.0 license. See the [LICENSE](https://github.com/milvus-io/milvus-lite/blob/main/LICENSE) file for details. |
0 commit comments