Docs Menu
Partition()
This is the constructor method to create a partition in the specified collection.
Invocation
Partition(collection, name, description='', **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
collection | Name of the collection | String | True |
name | Name of the partition to create | String | True |
description | Description of the collection | String | False |
Return
A new partition object created with the specified name.
Properties
Property | Description | Type |
---|---|---|
name | Name of the partition | String |
description | Description of the collection | String |
is_empty | Boolean value to indicate if the partition is empty | Bool |
num_entities | Number of entities in the partition | Integer |
Example
from pymilvus import Partition
partition = Partition("book", "novel", "")
delete()
This method deletes entities from a specified partition.
Invocation
delete(expr, timeout=None, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
expr | Boolean expression that specifies the primary keys of the entities to delete | String | True |
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
Return
A MutationResult object.
Properties
Property | Description | Type |
---|---|---|
delete_count | Number of the entities to delete | Integer |
Raises
RpcError
: error if gRPC encounter an error.ParamError
: error if the parameters are invalid.BaseException
: error if the return result from server is not ok.
Example
import random
data = [
[i for i in range(2000)],
[i for i in range(10000, 12000)],
[[random.random() for _ in range(2)] for _ in range(2000)],
]
from pymilvus import Partition
partition = Partition("book", "novel", "")
partition.insert(data)
expr = "book_id in [0,1]"
partition.delete(expr)
drop()
This method drops a partition and the data within.
Invocation
drop(timeout=None, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
Return
No return.
Raises
PartitionNotExistException
: error if the partition does not exist.
Example
from pymilvus import Partition
partition = Partition("book", "novel", "")
partition.drop()
get_replicas()
This method checks the replica information.
Invocation
get_replicas()
Return
The information about replica groups and the corresponding query nodes and shard.
Raises
Example
from pymilvus import Partition
partition = Partition("book", "novel")
partition.load(replica_number=2) # Load partition as 2 replicas
result = partition.get_replicas()
print(result)
insert()
This method inserts data into a specified partition.
Invocation
insert(data, timeout=None, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
data | Data to insert | list-like(list, tuple) | True |
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
Return
A MutationResult object.
Properties
Property | Description | Type |
---|---|---|
insert_count | Number of the inserted entities | Integer |
primary_keys | List of the primary keys of the inserted entities | list[String] |
Raises
PartitionNotExistException
: error if the partition does not exist.
Example
import random
data = [
[i for i in range(2000)],
[i for i in range(10000, 12000)],
[[random.random() for _ in range(2)] for _ in range(2000)],
]
from pymilvus import Partition
partition = Partition("book", "novel", "")
partition.insert(data)
load()
This method loads the specified partition to memory (for search or query).
Invocation
load(timeout=None, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
replica_number | Number of the replica(s) to load | Integer | False |
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
kwargs
|
| Bool | False |
Return
No return.
Raises
InvalidArgumentException
: error if the argument is invalid.
Example
from pymilvus import Partition
partition = Partition("book", "novel", "")
partition.load()
query()
This method conducts a vector query in a specified partition.
Invocation
query(expr, output_fields=None, timeout=None, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
expr | Boolean expression to filter the data | String | True |
output_fields | List of names of fields to output | list[String] | False |
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
kwargs
|
|
| False |
Return
A list that contains all results.
Raises
RpcError
: error if gRPC encounter an error.ParamError
: error if the parameters are invalid.BaseException
: error if the return result from server is not ok.
Example
from pymilvus import Partition
partition = Partition("novel")
res = collection.query(
expr = "book_id in [2,4,6,8]",
output_fields = ["book_id", "book_intro"],
consistency_level="Strong"
)
sorted_res = sorted(res, key=lambda k: k['book_id'])
sorted_res
release()
This method releases the specified partition from memory.
Invocation
release(timeout=None, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
Return
No return.
Raises
PartitionNotExistException
: error if the partition does not exist.
Example
from pymilvus import Partition
partition = Partition("book", "novel", "")
partition.load()
partition.release()
search()
This method conducts a vector similarity search in a specified partition.
Invocation
search(data, anns_field, param, limit, expr=None, output_fields=None, timeout=None, round_decimal=-1, **kwargs)
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
data | Data to search with | list[list[Float]] | True |
anns_field | Name of the vector field to search on | String | True |
param | Specific search parameter(s) of the index on the vector field | Dict | True |
limit | Number of nearest records to return | Integer | True |
expr | Boolean expression to filter the data | String | False |
output_fields | List of names of fields to output | list[String] | False |
timeout | An optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs. | Float | False |
round_decimal | Number of the decimal places of the returned distance | Integer | False |
kwargs
|
|
| False |
Return
A SearchResult object, an iterable, 2d-array-like class whose first dimension is the number of vectors to query (nq
), and the second dimension is the number of limit (topk
).
Raises
RpcError
: error if gRPC encounter an error.ParamError
: error if the parameters are invalid.BaseException
: error if the return result from server is not ok.
Example
search_params = {"metric_type": "L2", "params": {"nprobe": 10}}
from pymilvus import Partition
partition = Partition("novel")
results = partition.search(
data=[[0.1, 0.2]],
anns_field="book_intro",
param=search_params,
limit=10,
expr=None,
consistency_level="Strong"
)
results[0].ids
results[0].distances
- Invocation
- Parameters
- Return
- Properties
- Example
- delete()
- Invocation
- Parameters
- Return
- Properties
- Raises
- Example
- drop()
- Invocation
- Parameters
- Return
- Raises
- Example
- get_replicas()
- Invocation
- Return
- Raises
- Example
- insert()
- Invocation
- Parameters
- Return
- Properties
- Raises
- Example
- load()
- Invocation
- Parameters
- Return
- Raises
- Example
- query()
- Invocation
- Parameters
- Return
- Raises
- Example
- release()
- Invocation
- Parameters
- Return
- Raises
- Example
- search()
- Invocation
- Parameters
- Return
- Raises
- Example
On this page