Skip to content

Commit

Permalink
Prepare version 0.2.11 (#210)
Browse files Browse the repository at this point in the history
* add new api search_by_ids

Signed-off-by: Yhz <[email protected]>

* update example

Signed-off-by: Yhz <[email protected]>

* fix typo

Signed-off-by: Yhz <[email protected]>

* fix search by ids error

Signed-off-by: Yhz <[email protected]>

* add search_by_ids test case

Signed-off-by: Yhz <[email protected]>

* use connection pool

Signed-off-by: yhz <[email protected]>

* async api pass

Signed-off-by: Yhz <[email protected]>

* add async examples

Signed-off-by: Yhz <[email protected]>

* Fix TypeError raised in inserting vectors with async set true (#200)

Signed-off-by: Yhz <[email protected]>

* add timeout for async APIs

Signed-off-by: Yhz <[email protected]>

* add API close

Signed-off-by: Yhz <[email protected]>

* optimzie code

Signed-off-by: Yhz <[email protected]>

* remove terminate() in pool

Signed-off-by: Yhz <[email protected]>

* deprated connect

Signed-off-by: Yhz <[email protected]>

* get collection info failed when info is null (fix #201)

Signed-off-by: yhz <[email protected]>

* fix

Signed-off-by: yhz <[email protected]>

* update http handler

Signed-off-by: yhz <[email protected]>

* ..

Signed-off-by: yhz <[email protected]>

* filter -1 result

Signed-off-by: Yhz <[email protected]>

* Update APIs names

Signed-off-by: yhz <[email protected]>

* update future done not raise exception

Signed-off-by: Yhz <[email protected]>

* update

Signed-off-by: yhz <[email protected]>

* Fix excepted exceptions if async invoke with timeout (#207)

Signed-off-by: yhz <[email protected]>

* remove api compacity

Signed-off-by: yhz <[email protected]>

* add more params in pool

Signed-off-by: yhz <[email protected]>

* add pool try_connect and pre_ping params

Signed-off-by: yhz <[email protected]>

* remove parms recycle

Signed-off-by: yhz <[email protected]>

* update for http handler

Signed-off-by: Yhz <[email protected]>

* update example

Signed-off-by: yhz <[email protected]>

* update readme

Signed-off-by: yhz <[email protected]>

* update

Signed-off-by: yhz <[email protected]>

* rename project name

Signed-off-by: yhz <[email protected]>

* Prepare for v0.2.11

Signed-off-by: yhz <[email protected]>

* update async example

Signed-off-by: yhz <[email protected]>
  • Loading branch information
BossZou authored May 15, 2020
1 parent 1631277 commit bb79982
Show file tree
Hide file tree
Showing 33 changed files with 3,090 additions and 906 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# pymilvus 0.2.11(TBD)
# pymilvus 0.2.11(2020-05-15)

## Bug
- \#190 - Fix rpc return error when error occur
- \#200 - Fix TypeError raised in inserting vectors with async set true
- \#201 - Fix get collection info failed when info is null
- \#202 - Fix async 'NoneType' object has no attribute 'result'
- \#207 - Fix excepted exceptions if async invoke with timeout

## Improvement
- \#175 - Remove connect API
- \#203 - Add method 'is_done()' in Future class
- \#205 - Filter search results which id is -1
- \#206 - Update APIs names

## New Feature
- \#174 - Support connection pool
- \#177 - Support async API
- \#199 - Add API 'has_partition'


# pymilvus 0.2.10(2020-04-15)
Expand Down
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Python SDK for [Milvus](https://github.com/milvus-io/milvus). To contribute code to this project, please read our [contribution guidelines](https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md) first.

For detailed SDK documentation, refer to [API Documentation](https://milvus-io.github.io/milvus-sdk-python/pythondoc/v0.2.10/index.html).
For detailed SDK documentation, refer to [API Documentation](https://milvus-io.github.io/milvus-sdk-python/pythondoc/v0.2.11/index.html).


<!-- TOC -->
Expand Down Expand Up @@ -69,12 +69,13 @@ The following collection shows Milvus versions and recommended pymilvus versions
| 0.7.0 | 0.2.8 |
| 0.7.1 | 0.2.9 |
| 0.8.0 | 0.2.10 |
| 0.9.0 | 0.2.11 |


You can install a specific version of pymilvus by:

```shell
$ pip install pymilvus==0.2.10
$ pip install pymilvus==0.2.11
```

You can upgrade `pymilvus` to the latest version by:
Expand All @@ -98,12 +99,11 @@ Refer to [examples](/examples) for more example programs.
>>> from milvus import Milvus, IndexType, MetricType, Status
```

2. Connect to Milvus server by using one of the following methods:
2. Create a client to Milvus server by using one of the following methods:

```python
# Connect to Milvus server
>>> client = Milvus(host='localhost', port='19530')
>>> client.connect()
```

> Note: In the above code, default values are used for `host` and `port` parameters. Feel free to change them to the IP address and port you set for Milvus server.
Expand Down Expand Up @@ -148,11 +148,11 @@ You can split collections into partitions by partition tags for improved search
>>> client.create_partition(collection_name='test01', partition_tag='tag01')
```

Use `show_partitions()` to verify whether the partition is created.
Use `list_partitions()` to verify whether the partition is created.

```python
# Show partitions
>>> client.show_partitions(collection_name='test01')
>>> client.list_partitions(collection_name='test01')
```

### Drop a partition
Expand Down Expand Up @@ -204,40 +204,34 @@ Use `show_partitions()` to verify whether the partition is created.

```python
# Insert vectors
>>> client.insert(collection_name='test01', records=vectors)
>>> status, inserted_vector_ids = client.insert(collection_name='test01', records=vectors)
```

Alternatively, you can also provide user-defined vector ids:

```python
>>> vector_ids = [id for id in range(20)]
>>> client.insert(collection_name='test01', records=vectors, ids=vector_ids)
>>> status, inserted_vector_ids = client.insert(collection_name='test01', records=vectors, ids=vector_ids)
```

### Insert vectors in a partition

```python
>>> client.insert('test01', vectors, partition_tag="tag01")
>>> status, inserted_vector_ids = client.insert('test01', vectors, partition_tag="tag01")
```

To verify the vectors you have inserted, use `get_vector_by_id()`. Assume you have a vector with the following ID.
To verify the vectors you have inserted, use `get_vector_by_id()`. Assume you have vector with the following ID.

```python
>>> status, vector = client.get_vector_by_id(collection_name='test01', vector_id=0)
>>> status, vector = client.get_entity_by_id(collection_name='test01', ids=inserted_vector_ids[:10])
```

### Delete vectors by ID

Assume you have some vectors with the following IDs:

```python
>>> ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
```

You can delete these vectors by:

```python
>>> client.delete_by_id('test01', ids)
>>> client.delete_entity_by_id('test01', inserted_vector_ids[:10])
```

## Flush data in one or multiple collections to disk
Expand Down Expand Up @@ -285,8 +279,8 @@ A segment is a data file that Milvus automatically creates by merging inserted v

> Note: If you do not specify `partition_tags`, Milvus searches the whole collection.
## Disconnect from the Milvus server
## close client

```python
>>> client.disconnect()
>>> client.close()
```
15 changes: 8 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,35 @@ def connect(request, ghandler):
port_default = default_http_port if handler == "HTTP" else default_grpc_port
port = request.config.getoption("--port", default=port_default)

milvus = Milvus(handler=ghandler)
milvus.connect(host=ip, port=port)
client = Milvus(host=ip, port=port, handler=ghandler)
# milvus.connect()

def fin():
try:
milvus.disconnect()
client.close()
except:
pass

request.addfinalizer(fin)
return milvus
return client


@pytest.fixture(scope="module")
def gcon(request, ghandler):
ip = request.config.getoption("--ip")
port = request.config.getoption("--port")
milvus = Milvus(host=ip, port=port, handler=ghandler)
client = Milvus(host=ip, port=port, handler=ghandler)

def fin():
try:
client.close()
pass
except Exception as e:
print(e)
pass

request.addfinalizer(fin)
return milvus
return client


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -111,7 +112,7 @@ def gcollection(request, gcon):
gcon.flush([table_name])

def teardown():
status, table_names = gcon.show_collections()
status, table_names = gcon.list_collections()
for name in table_names:
gcon.drop_collection(name)

Expand Down
35 changes: 21 additions & 14 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
# create a vector collection,
# insert 10 vectors,
# and execute a vector similarity search.

import datetime
import sys

sys.path.append(".")
import random
import threading
import time

import numpy as np

from milvus import Milvus, IndexType, MetricType, Status
from milvus.client.abstract import TopKQueryResult

# Milvus server IP address and port.
# You may need to change _HOST and _PORT accordingly.
_HOST = '127.0.0.1'
_PORT = '19530' # default value
# _PORT = '19121' # default http value

# Vector parameters
_DIM = 128 # dimension of vector
Expand All @@ -25,10 +30,9 @@

def main():
# Specify server addr when create milvus client instance
milvus = Milvus(_HOST, _PORT)

# Check if server is accessible
milvus.connect()
# milvus client instance maintain a connection pool, param
# `pool_size` specify the max connection num.
milvus = Milvus(_HOST, _PORT, pool_size=10)

# Create collection demo_collection if it dosen't exist.
collection_name = 'example_collection_'
Expand All @@ -45,22 +49,18 @@ def main():
milvus.create_collection(param)

# Show collections in Milvus server
_, collections = milvus.show_collections()

# present collection info
_, info = milvus.collection_info(collection_name)
print(info)
_, collections = milvus.list_collections()

# Describe demo_collection
_, collection = milvus.describe_collection(collection_name)
_, collection = milvus.get_collection_info(collection_name)
print(collection)

# 10000 vectors with 16 dimension
# 10000 vectors with 128 dimension
# element per dimension is float32 type
# vectors should be a 2-D array
vectors = [[random.random() for _ in range(_DIM)] for _ in range(10000)]
# You can also use numpy to generate random vectors:
# `vectors = np.random.rand(10000, 16).astype(np.float32)`
# vectors = np.random.rand(10000, _DIM).astype(np.float32)

# Insert vectors into demo_collection, return status and vectors id list
status, ids = milvus.insert(collection_name=collection_name, records=vectors)
Expand All @@ -69,7 +69,14 @@ def main():
milvus.flush([collection_name])

# Get demo_collection row count
status, result = milvus.count_collection(collection_name)
status, result = milvus.count_entities(collection_name)

# present collection statistics info
_, info = milvus.get_collection_stats(collection_name)
print(info)

# Obtain raw vectors by providing vector ids
status, result_vectors = milvus.get_entity_by_id(collection_name, ids[:10])

# create index of vectors, search more rapidly
index_param = {
Expand All @@ -83,7 +90,7 @@ def main():
status = milvus.create_index(collection_name, IndexType.IVF_FLAT, index_param)

# describe index, get information of index
status, index = milvus.describe_index(collection_name)
status, index = milvus.get_index_info(collection_name)
print(index)

# Use the top 10 vectors for similarity search
Expand Down
Loading

0 comments on commit bb79982

Please sign in to comment.