From e651a07e24f1ea20197d49f5c2db07a3f0ddc5d6 Mon Sep 17 00:00:00 2001 From: Yang Xuan Date: Thu, 13 Jun 2019 17:15:28 +0800 Subject: [PATCH] feat(python): build docs, fix examples bug Former-commit-id: 79d4b0556dc9caeb432bf7981fc32e4302e48411 --- python/sdk/client/Abstract.py | 20 +- python/sdk/client/Client.py | 130 +++++-- python/sdk/client/Status.py | 5 +- python/sdk/doc/en/API/sdk.client.rst | 27 ++ python/sdk/doc/en/QuickStart.rst | 0 python/sdk/doc/en/api.rst | 11 + python/sdk/doc/en/conf.py | 61 ++++ python/sdk/doc/en/index.rst | 24 ++ python/sdk/documents/client.Abstract.html | 353 -------------------- python/sdk/documents/client.Client.html | 218 ------------ python/sdk/documents/client.Exceptions.html | 349 ------------------- python/sdk/documents/client.Status.html | 74 ---- python/sdk/documents/index.html | 25 -- python/sdk/examples/example.py | 63 ++-- python/sdk/setup.py | 6 +- 15 files changed, 275 insertions(+), 1091 deletions(-) create mode 100644 python/sdk/doc/en/API/sdk.client.rst create mode 100644 python/sdk/doc/en/QuickStart.rst create mode 100644 python/sdk/doc/en/api.rst create mode 100644 python/sdk/doc/en/conf.py create mode 100644 python/sdk/doc/en/index.rst delete mode 100644 python/sdk/documents/client.Abstract.html delete mode 100644 python/sdk/documents/client.Client.html delete mode 100644 python/sdk/documents/client.Exceptions.html delete mode 100644 python/sdk/documents/client.Status.html delete mode 100644 python/sdk/documents/index.html diff --git a/python/sdk/client/Abstract.py b/python/sdk/client/Abstract.py index ce3e28e42a..41ce37e9f6 100644 --- a/python/sdk/client/Abstract.py +++ b/python/sdk/client/Abstract.py @@ -128,7 +128,7 @@ class ConnectIntf(object): :type uri: str :param uri: (Optional) uri - :return Status, indicate if connect is successful + :return: Status, indicate if connect is successful """ _abstract() @@ -137,7 +137,7 @@ class ConnectIntf(object): connected, connection status Should be implemented - :return Status, indicate if connect is successful + :return: Status, indicate if connect is successful """ _abstract() @@ -146,7 +146,7 @@ class ConnectIntf(object): Disconnect, server will be disconnected after disconnect return SUCCESS Should be implemented - :return Status, indicate if connect is successful + :return: Status, indicate if connect is successful """ _abstract() @@ -158,7 +158,7 @@ class ConnectIntf(object): :type param: TableSchema :param param: provide table information to be created - :return Status, indicate if connect is successful + :return: Status, indicate if connect is successful """ _abstract() @@ -170,7 +170,7 @@ class ConnectIntf(object): :type table_name: str :param table_name: table_name of the deleting table - :return Status, indicate if connect is successful + :return: Status, indicate if connect is successful """ _abstract() @@ -185,7 +185,7 @@ class ConnectIntf(object): :type records: list[RowRecord] :param records: list of vectors been inserted - :returns + :returns: Status : indicate if vectors inserted successfully ids :list of id, after inserted every vector is given a id """ @@ -209,7 +209,7 @@ class ConnectIntf(object): :type top_k: int :param top_k: how many similar vectors will be searched - :returns + :returns: Status: indicate if query is successful query_results: list[TopKQueryResult] """ @@ -223,7 +223,7 @@ class ConnectIntf(object): :type table_name: str :param table_name: which table to be shown - :returns + :returns: Status: indicate if query is successful table_schema: TableSchema, given when operation is successful """ @@ -237,7 +237,7 @@ class ConnectIntf(object): :type table_name, str :param table_name, target table name. - :returns + :returns: Status: indicate if operation is successful count: int, table row count """ @@ -248,7 +248,7 @@ class ConnectIntf(object): Show all tables in database should be implemented - :return + :return: Status: indicate if this operation is successful tables: list[str], list of table names """ diff --git a/python/sdk/client/Client.py b/python/sdk/client/Client.py index d2d4930fbd..88db1b9d5a 100644 --- a/python/sdk/client/Client.py +++ b/python/sdk/client/Client.py @@ -26,8 +26,8 @@ from client.Exceptions import ( LOGGER = logging.getLogger(__name__) -__VERSION__ = '0.0.1' -__NAME__ = 'Thrift_Client' +__VERSION__ = '0.1.0' +__NAME__ = 'Milvus Python SDK' class Prepare(object): @@ -39,13 +39,16 @@ class Prepare(object): index_type=IndexType.INVALIDE, store_raw_vector = False): """ + :type table_name: str + :type dimension: int + :type index_type: IndexType + :type store_raw_vector: bool + :param table_name: (Required) name of table + :param dimension: (Required) dimension of the table + :param index_type: (Optional) index type, default = IndexType.INVALID + :param store_raw_vector: (Optional) default = False - :param table_name: str, (Required) name of table - :param index_type: IndexType, (Required) index type, default = IndexType.INVALID - :param dimension: int64, (Optional) dimension of the table - :param store_raw_vector: bool, (Optional) default = False - - :return: TableSchema + :return: TableSchema object """ temp = TableSchema(table_name,dimension, index_type, store_raw_vector) @@ -57,10 +60,12 @@ class Prepare(object): @classmethod def range(cls, start, end): """ - :param start: str, (Required) range start - :param end: str (Required) range end + :type start: str + :type end: str + :param start: (Required) range start + :param end: (Required) range end - :return Range + :return: Range object """ temp = Range(start=start, end=end) return ttypes.Range(start_value=temp.start, end_value=temp.end) @@ -68,9 +73,12 @@ class Prepare(object): @classmethod def row_record(cls, vector_data): """ - Record inserted + Transfer a float binary str to RowRecord and return - :param vector_data: float binary str, (Required) a binary str + :type vector_data: bytearray or bytes + :param vector_data: (Required) binary vector to store + + :return: RowRecord object """ temp = RowRecord(vector_data) @@ -78,6 +86,9 @@ class Prepare(object): class Milvus(ConnectIntf): + """ + The Milvus object is used to connect and communicate with the server + """ def __init__(self): self.status = None @@ -88,6 +99,20 @@ class Milvus(ConnectIntf): return '{}'.format(self.status) def connect(self, host='localhost', port='9090', uri=None): + """ + Connect method should be called before any operations. + Server will be connected after connect return OK + + :type host: str + :type port: str + :type uri: str + :param host: (Required) host of the server + :param port: (Required) port of the server + :param uri: (Optional) + + :return: Status, indicate if connect is successful + :rtype: Status + """ # TODO URI if self.status and self.status == Status.SUCCESS: raise RepeatingConnectError("You have already connected!") @@ -110,9 +135,21 @@ class Milvus(ConnectIntf): @property def connected(self): + """ + Check if client is connected to the server + + :return: if client is connected + :rtype bool + """ return self.status == Status.SUCCESS def disconnect(self): + """ + Disconnect the client + + :return: Status, indicate if disconnect is successful + :rtype: Status + """ if not self._transport: raise DisconnectNotConnectedClientError('Error') @@ -130,11 +167,13 @@ class Milvus(ConnectIntf): def create_table(self, param): """Create table - :param param: Provide table information to be created, + :type param: TableSchema + :param param: Provide table information to be created `Please use Prepare.table_schema generate param` :return: Status, indicate if operation is successful + :rtype: Status """ if not self._client: raise NotConnectError('Please Connect to the server first!') @@ -147,11 +186,14 @@ class Milvus(ConnectIntf): return Status(message='Table {} created!'.format(param.table_name)) def delete_table(self, table_name): - """Delete table + """ + Delete table with table_name + :type table_name: str :param table_name: Name of the table being deleted :return: Status, indicate if operation is successful + :rtype: Status """ try: self._client.DeleteTable(table_name) @@ -164,14 +206,19 @@ class Milvus(ConnectIntf): """ Add vectors to table + :type table_name: str + :type records: list[RowRecord] + :param table_name: table name been inserted - :param records: List[RowRecord], list of vectors been inserted + :param records: list of vectors been inserted `Please use Prepare.row_record generate records` :returns: - Status : indicate if vectors inserted successfully - ids :list of id, after inserted every vector is given a id + Status: indicate if vectors inserted successfully + + ids: list of id, after inserted every vector is given a id + :rtype: (Status, list(str)) """ try: ids = self._client.AddVector(table_name=table_name, record_array=records) @@ -184,17 +231,26 @@ class Milvus(ConnectIntf): """ Query vectors in a table - :param table_name: str, table name been queried - :param query_records: list[QueryRecord], all vectors going to be queried + + + :param query_ranges: Optional ranges for conditional search. + If not specified, search whole table + :type query_ranges: list[Range] + :param table_name: table name been queried + :type table_name: str + :param query_records: all vectors going to be queried `Please use Prepare.query_record generate QueryRecord` - + :type query_records: list[RowRecord] :param top_k: int, how many similar vectors will be searched - :param query_ranges, (Optional) list[Range], search range + :type top_k: int + + :returns: (Status, res) - :returns: Status: indicate if query is successful - res: list[TopKQueryResult], return when operation is successful + + res: return when operation is successful + :rtype: (Status, list[TopKQueryResult]) """ res = [] try: @@ -219,17 +275,17 @@ class Milvus(ConnectIntf): """ Show table information - :param table_name: str, which table to be shown + :type table_name: str + :param table_name: which table to be shown - :returns: + :returns: (Status, table_schema) Status: indicate if query is successful - table_schema: TableSchema, return when operation is successful + table_schema: return when operation is successful + :rtype: (Status, TableSchema) """ try: temp = self._client.DescribeTable(table_name) - # res = TableSchema(table_name=temp.table_name, dimension=temp.dimension, - # index_type=temp.index_type, store_raw_vector=temp.store_raw_vector) except (TApplicationException, TException) as e: LOGGER.error('{}'.format(e)) return Status(Status.PERMISSION_DENIED, str(e)), None @@ -241,14 +297,17 @@ class Milvus(ConnectIntf): :return: Status: indicate if this operation is successful - tables: list[str], list of table names, return when operation + + tables: list of table names, return when operation is successful + :rtype: + (Status, list[str]) """ try: res = self._client.ShowTables() tables = [] if res: - tables, _ = res + tables = res except (TApplicationException, TException) as e: LOGGER.error('{}'.format(e)) @@ -259,16 +318,17 @@ class Milvus(ConnectIntf): """ Get table row count - :type table_name, str - :param table_name, target table name. + :type table_name: str + :param table_name: target table name. :returns: Status: indicate if operation is successful + res: int, table row count """ try: - count, _ = self._client.GetTableRowCount(table_name) + count = self._client.GetTableRowCount(table_name) except (TApplicationException, TException) as e: LOGGER.error('{}'.format(e)) @@ -280,6 +340,7 @@ class Milvus(ConnectIntf): Provide client version :return: Client version + :rtype: str """ return __VERSION__ @@ -299,6 +360,7 @@ class Milvus(ConnectIntf): Provide server status :return: Server status + :rtype : str """ if not self.connected: raise NotConnectError('You have to connect first') diff --git a/python/sdk/client/Status.py b/python/sdk/client/Status.py index b60c48aa98..d74f7f010a 100644 --- a/python/sdk/client/Status.py +++ b/python/sdk/client/Status.py @@ -1,7 +1,8 @@ class Status(object): """ - :attribute code : int (optional) default as ok - :attribute message : str (optional) current status message + :attribute code: int (optional) default as ok + + :attribute message: str (optional) current status message """ SUCCESS = 0 CONNECT_FAILED = 1 diff --git a/python/sdk/doc/en/API/sdk.client.rst b/python/sdk/doc/en/API/sdk.client.rst new file mode 100644 index 0000000000..b28b507a10 --- /dev/null +++ b/python/sdk/doc/en/API/sdk.client.rst @@ -0,0 +1,27 @@ + +sdk.client.Client module +=============================== + +sdk.client.Client.Milvus +-------------------------------- + +.. autoclass:: client.Client.Milvus + :members: + :undoc-members: + :show-inheritance: + +sdk.client.Clinet.Prepare +-------------------------------- + +.. autoclass:: client.Client.Prepare + :members: + :undoc-members: + :show-inheritance: + +sdk.client.Status module +====================================== + +.. automodule:: client.Status + :members: + :undoc-members: + :show-inheritance: diff --git a/python/sdk/doc/en/QuickStart.rst b/python/sdk/doc/en/QuickStart.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/sdk/doc/en/api.rst b/python/sdk/doc/en/api.rst new file mode 100644 index 0000000000..a3724e08e3 --- /dev/null +++ b/python/sdk/doc/en/api.rst @@ -0,0 +1,11 @@ +API +*** + +client package +============================== + + +.. toctree:: + :maxdepth: 2 + + API/sdk.client.rst \ No newline at end of file diff --git a/python/sdk/doc/en/conf.py b/python/sdk/doc/en/conf.py new file mode 100644 index 0000000000..8a22479bf2 --- /dev/null +++ b/python/sdk/doc/en/conf.py @@ -0,0 +1,61 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.insert(0, os.path.join( + os.path.dirname(os.path.abspath(__file__)), + os.path.join('..', '..') +)) + + +# -- Project information ----------------------------------------------------- + +project = 'MilvusPythonSDK' +copyright = '2019, Zilliz' +author = 'YangXuan' + +# The full version, including alpha/beta/rc tags +release = '0.0.1' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + # 'sphinx.ext.viewcode' +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. + +master_doc = 'index' + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] diff --git a/python/sdk/doc/en/index.rst b/python/sdk/doc/en/index.rst new file mode 100644 index 0000000000..5e3b95eebc --- /dev/null +++ b/python/sdk/doc/en/index.rst @@ -0,0 +1,24 @@ +.. MilvusSDK documentation master file, created by + sphinx-quickstart on Thu Jun 13 11:42:09 2019. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +.. raw:: html + +
+ + Milvus +
+ +Milvus Python SDK +--------------------------- + +Using Milvus with Python + + +.. toctree:: + :maxdepth: 2 + :hidden: + + QuickStart + api diff --git a/python/sdk/documents/client.Abstract.html b/python/sdk/documents/client.Abstract.html deleted file mode 100644 index f2391700f3..0000000000 --- a/python/sdk/documents/client.Abstract.html +++ /dev/null @@ -1,353 +0,0 @@ - -Python: module Abstract - - - - - -
 
- 
Abstract
index
/home/yangxuan/vecwise_engine/python/sdk/client/Abstract.py
-

-

- - - - - -
 
-Classes
       
-
builtins.object -
-
-
ConnectIntf -
QueryResult -
Range -
RowRecord -
TableSchema -
TopKQueryResult -
-
-
enum.IntEnum(builtins.int, enum.Enum) -
-
-
IndexType -
-
-
-

- - - - - - - -
 
-class ConnectIntf(builtins.object)
   SDK client abstract class

-Connection is a abstract class
 
 Methods defined here:
-
add_vectors(self, table_name, records)
Add vectors to table
-Should be implemented

-:type  table_name: str
-:param table_name: table name been inserted

-:type  records: list[RowRecord]
-:param records: list of vectors been inserted

-:returns
-    Status : indicate if vectors inserted successfully
-    ids :list of id, after inserted every vector is given a id
- -
client_version(self)
Provide client version
-should be implemented

-:return: str, client version
- -
connect(self, host=None, port=None, uri=None)
Connect method should be called before any operations
-Server will be connected after connect return OK
-Should be implemented

-:type  host: str
-:param host: host

-:type  port: str
-:param port: port

-:type  uri: str
-:param uri: (Optional) uri

-:return Status,  indicate if connect is successful
- -
connected(self)
connected, connection status
-Should be implemented

-:return Status,  indicate if connect is successful
- -
create_table(self, param)
Create table
-Should be implemented

-:type  param: TableSchema
-:param param: provide table information to be created

-:return Status, indicate if connect is successful
- -
delete_table(self, table_name)
Delete table
-Should be implemented

-:type  table_name: str
-:param table_name: table_name of the deleting table

-:return Status, indicate if connect is successful
- -
describe_table(self, table_name)
Show table information
-Should be implemented

-:type  table_name: str
-:param table_name: which table to be shown

-:returns
-    Status: indicate if query is successful
-    table_schema: TableSchema, given when operation is successful
- -
disconnect(self)
Disconnect, server will be disconnected after disconnect return SUCCESS
-Should be implemented

-:return Status,  indicate if connect is successful
- -
get_table_row_count(self, table_name)
Get table row count
-Should be implemented

-:type  table_name, str
-:param table_name, target table name.

-:returns
-    Status: indicate if operation is successful
-    count: int, table row count
- -
search_vectors(self, table_name, query_records, query_ranges, top_k)
Query vectors in a table
-Should be implemented

-:type  table_name: str
-:param table_name: table name been queried

-:type  query_records: list[RowRecord]
-:param query_records: all vectors going to be queried

-:type  query_ranges: list[Range]
-:param query_ranges: Optional ranges for conditional search.
-    If not specified, search whole table

-:type  top_k: int
-:param top_k: how many similar vectors will be searched

-:returns
-    Status:  indicate if query is successful
-    query_results: list[TopKQueryResult]
- -
server_status(self, cmd)
Provide server status
-should be implemented
-:type cmd, str

-:return: str, server status
- -
server_version(self)
Provide server version
-should be implemented

-:return: str, server version
- -
show_tables(self)
Show all tables in database
-should be implemented

-:return
-    Status: indicate if this operation is successful
-    tables: list[str], list of table names
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class IndexType(enum.IntEnum)
   An enumeration.
 
 
Method resolution order:
-
IndexType
-
enum.IntEnum
-
builtins.int
-
enum.Enum
-
builtins.object
-
-
-Data and other attributes defined here:
-
IDMAP = <IndexType.IDMAP: 1>
- -
INVALIDE = <IndexType.INVALIDE: 0>
- -
IVFLAT = <IndexType.IVFLAT: 2>
- -
-Data descriptors inherited from enum.Enum:
-
name
-
The name of the Enum member.
-
-
value
-
The value of the Enum member.
-
-
-Data descriptors inherited from enum.EnumMeta:
-
__members__
-
Returns a mapping of member name->value.

-This mapping lists all enum members, including aliases. Note that this
-is a read-only view of the internal mapping.
-
-

- - - - - - - -
 
-class QueryResult(builtins.object)
   Query result

-:type  id: int64
-:param id: id of the vector

-:type  score: float
-:param score: Vector similarity 0 <= score <= 100
 
 Methods defined here:
-
__init__(self, id, score)
Initialize self.  See help(type(self)) for accurate signature.
- -
__repr__(self)
Return repr(self).
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class Range(builtins.object)
   Range information

-:type  start: str
-:param start: Range start value

-:type  end: str
-:param end: Range end value
 
 Methods defined here:
-
__init__(self, start, end)
Initialize self.  See help(type(self)) for accurate signature.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class RowRecord(builtins.object)
   Record inserted

-:type  vector_data: binary str
-:param vector_data: (Required) a vector
 
 Methods defined here:
-
__init__(self, vector_data)
Initialize self.  See help(type(self)) for accurate signature.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class TableSchema(builtins.object)
   Table Schema

-:type  table_name: str
-:param table_name: (Required) name of table

-:type  index_type: IndexType
-:param index_type: (Optional) index type, default = 0

-    `IndexType`: 0-invalid, 1-idmap, 2-ivflat

-:type  dimension: int64
-:param dimension: (Required) dimension of vector

-:type  store_raw_vector: bool
-:param store_raw_vector: (Optional) default = False
 
 Methods defined here:
-
__init__(self, table_name, dimension=0, index_type=<IndexType.INVALIDE: 0>, store_raw_vector=False)
Initialize self.  See help(type(self)) for accurate signature.
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - - - -
 
-class TopKQueryResult(builtins.object)
   TopK query results

-:type  query_results: list[QueryResult]
-:param query_results: TopK query results
 
 Methods defined here:
-
__init__(self, query_results)
Initialize self.  See help(type(self)) for accurate signature.
- -
__repr__(self)
Return repr(self).
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- \ No newline at end of file diff --git a/python/sdk/documents/client.Client.html b/python/sdk/documents/client.Client.html deleted file mode 100644 index 9586756765..0000000000 --- a/python/sdk/documents/client.Client.html +++ /dev/null @@ -1,218 +0,0 @@ - -Python: module Client - - - - - -
 
- 
Client
index
/home/yangxuan/vecwise_engine/python/sdk/client/Client.py
-

-

- - - - - -
 
-Modules
       
milvus.thrift.MilvusService
-thrift.protocol.TBinaryProtocol
-
thrift.transport.TSocket
-thrift.transport.TTransport
-
logging
-milvus.thrift.ttypes
-

- - - - - -
 
-Classes
       
-
builtins.object -
-
-
Prepare -
-
-
client.Abstract.ConnectIntf(builtins.object) -
-
-
Milvus -
-
-
-

- - - - - - - -
 
-class Milvus(client.Abstract.ConnectIntf)
   SDK client abstract class

-Connection is a abstract class
 
 
Method resolution order:
-
Milvus
-
client.Abstract.ConnectIntf
-
builtins.object
-
-
-Methods defined here:
-
__init__(self)
Initialize self.  See help(type(self)) for accurate signature.
- -
__repr__(self)
Return repr(self).
- -
add_vectors(self, table_name, records)
Add vectors to table

-:param table_name: table name been inserted
-:param records: List[RowRecord], list of vectors been inserted

-        `Please use Prepare.row_record generate records`

-:returns:
-    Status : indicate if vectors inserted successfully
-    ids :list of id, after inserted every vector is given a id
- -
client_version(self)
Provide client version

-:return: Client version
- -
connect(self, host='localhost', port='9090', uri=None)
Connect method should be called before any operations
-Server will be connected after connect return OK
-Should be implemented

-:type  host: str
-:param host: host

-:type  port: str
-:param port: port

-:type  uri: str
-:param uri: (Optional) uri

-:return Status,  indicate if connect is successful
- -
create_table(self, param)
Create table

-:param param: Provide table information to be created,

-        `Please use Prepare.table_schema generate param`

-:return: Status, indicate if operation is successful
- -
delete_table(self, table_name)
Delete table

-:param table_name: Name of the table being deleted

-:return: Status, indicate if operation is successful
- -
describe_table(self, table_name)
Show table information

-:param table_name: str, which table to be shown

-:returns:
-    Status: indicate if query is successful
-    table_schema: TableSchema, return when operation is successful
- -
disconnect(self)
Disconnect, server will be disconnected after disconnect return SUCCESS
-Should be implemented

-:return Status,  indicate if connect is successful
- -
get_table_row_count(self, table_name)
Get table row count

-:type  table_name, str
-:param table_name, target table name.

-:returns:
-    Status: indicate if operation is successful
-    res: int, table row count
- -
search_vectors(self, table_name, top_k, query_records, query_ranges=None)
Query vectors in a table

-:param table_name: str, table name been queried
-:param query_records: list[QueryRecord], all vectors going to be queried

-        `Please use Prepare.query_record generate QueryRecord`

-:param top_k: int, how many similar vectors will be searched
-:param query_ranges, (Optional) list[Range], search range

-:returns:
-    Status:  indicate if query is successful
-    res: list[TopKQueryResult], return when operation is successful
- -
server_status(self, cmd=None)
Provide server status

-:return: Server status
- -
server_version(self)
Provide server version

-:return: Server version
- -
show_tables(self)
Show all tables in database

-:return:
-    Status: indicate if this operation is successful
-    tables: list[str], list of table names, return when operation
-            is successful
- -
-Data descriptors defined here:
-
connected
-
-
-Data descriptors inherited from client.Abstract.ConnectIntf:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - -
 
-class Prepare(builtins.object)
    Class methods defined here:
-
range(start, end) from builtins.type
:param start: str, (Required) range start
-:param end: str (Required) range end

-:return Range
- -
row_record(vector_data) from builtins.type
Record inserted

-:param vector_data: float binary str, (Required) a binary str
- -
table_schema(table_name, dimension, index_type=<IndexType.INVALIDE: 0>, store_raw_vector=False) from builtins.type
:param table_name: str, (Required) name of table
-:param index_type: IndexType, (Required) index type, default = IndexType.INVALID
-:param dimension: int64, (Optional) dimension of the table
-:param store_raw_vector: bool, (Optional) default = False

-:return: TableSchema
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-

- - - - - -
 
-Data
       LOGGER = <Logger Client (WARNING)>
-__NAME__ = 'Thrift_Client'
-__VERSION__ = '0.0.1'
- \ No newline at end of file diff --git a/python/sdk/documents/client.Exceptions.html b/python/sdk/documents/client.Exceptions.html deleted file mode 100644 index 75d81c4440..0000000000 --- a/python/sdk/documents/client.Exceptions.html +++ /dev/null @@ -1,349 +0,0 @@ - -Python: module Exceptions - - - - - -
 
- 
Exceptions
index
/home/yangxuan/vecwise_engine/python/sdk/client/Exceptions.py
-

-

- - - - - -
 
-Classes
       
-
builtins.ValueError(builtins.Exception) -
-
-
ConnectError -
-
-
NotConnectError -
RepeatingConnectError -
-
-
DisconnectNotConnectedClientError -
ParamError -
-
-
-

- - - - - - - -
 
-class ConnectError(builtins.ValueError)
   Inappropriate argument value (of correct type).
 
 
Method resolution order:
-
ConnectError
-
builtins.ValueError
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Data descriptors defined here:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.ValueError:
-
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
- -
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
__str__(self, /)
Return str(self).
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- - - - - - - -
 
-class DisconnectNotConnectedClientError(builtins.ValueError)
   Inappropriate argument value (of correct type).
 
 
Method resolution order:
-
DisconnectNotConnectedClientError
-
builtins.ValueError
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Data descriptors defined here:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.ValueError:
-
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
- -
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
__str__(self, /)
Return str(self).
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- - - - - - - -
 
-class NotConnectError(ConnectError)
   Inappropriate argument value (of correct type).
 
 
Method resolution order:
-
NotConnectError
-
ConnectError
-
builtins.ValueError
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Data descriptors inherited from ConnectError:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.ValueError:
-
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
- -
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
__str__(self, /)
Return str(self).
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- - - - - - - -
 
-class ParamError(builtins.ValueError)
   Inappropriate argument value (of correct type).
 
 
Method resolution order:
-
ParamError
-
builtins.ValueError
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Data descriptors defined here:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.ValueError:
-
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
- -
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
__str__(self, /)
Return str(self).
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- - - - - - - -
 
-class RepeatingConnectError(ConnectError)
   Inappropriate argument value (of correct type).
 
 
Method resolution order:
-
RepeatingConnectError
-
ConnectError
-
builtins.ValueError
-
builtins.Exception
-
builtins.BaseException
-
builtins.object
-
-
-Data descriptors inherited from ConnectError:
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Methods inherited from builtins.ValueError:
-
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
- -
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.
- -
-Methods inherited from builtins.BaseException:
-
__delattr__(self, name, /)
Implement delattr(self, name).
- -
__getattribute__(self, name, /)
Return getattr(self, name).
- -
__reduce__(...)
helper for pickle
- -
__repr__(self, /)
Return repr(self).
- -
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
- -
__setstate__(...)
- -
__str__(self, /)
Return str(self).
- -
with_traceback(...)
Exception.with_traceback(tb) --
-set self.__traceback__ to tb and return self.
- -
-Data descriptors inherited from builtins.BaseException:
-
__cause__
-
exception cause
-
-
__context__
-
exception context
-
-
__dict__
-
-
__suppress_context__
-
-
__traceback__
-
-
args
-
-

- \ No newline at end of file diff --git a/python/sdk/documents/client.Status.html b/python/sdk/documents/client.Status.html deleted file mode 100644 index 9f51f67978..0000000000 --- a/python/sdk/documents/client.Status.html +++ /dev/null @@ -1,74 +0,0 @@ - -Python: module Status - - - - - -
 
- 
Status
index
/home/yangxuan/vecwise_engine/python/sdk/client/Status.py
-

-

- - - - - -
 
-Classes
       
-
builtins.object -
-
-
Status -
-
-
-

- - - - - - - -
 
-class Status(builtins.object)
   :attribute code : int (optional) default as ok
-:attribute message : str (optional) current status message
 
 Methods defined here:
-
__eq__(self, other)
Make Status comparable with self by code
- -
__init__(self, code=0, message=None)
Initialize self.  See help(type(self)) for accurate signature.
- -
__ne__(self, other)
Return self!=value.
- -
__repr__(self)
Return repr(self).
- -
-Data descriptors defined here:
-
__dict__
-
dictionary for instance variables (if defined)
-
-
__weakref__
-
list of weak references to the object (if defined)
-
-
-Data and other attributes defined here:
-
CONNECT_FAILED = 1
- -
ILLEGAL_ARGUMENT = 4
- -
ILLEGAL_DIMENSION = 6
- -
ILLEGAL_RANGE = 5
- -
PERMISSION_DENIED = 2
- -
SUCCESS = 0
- -
TABLE_NOT_EXISTS = 3
- -
__hash__ = None
- -

- \ No newline at end of file diff --git a/python/sdk/documents/index.html b/python/sdk/documents/index.html deleted file mode 100644 index 7948cdc4a9..0000000000 --- a/python/sdk/documents/index.html +++ /dev/null @@ -1,25 +0,0 @@ - -Python: package client - - - - - -
 
- 
client
index
/home/yangxuan/vecwise_engine/python/sdk/client/__init__.py
-

client module

-

- - - - - -
 
-Package Contents
       
Abstract
-
Client
-
Exceptions
-
Status
-
- \ No newline at end of file diff --git a/python/sdk/examples/example.py b/python/sdk/examples/example.py index 0e2589db1e..bb4f3a27f9 100644 --- a/python/sdk/examples/example.py +++ b/python/sdk/examples/example.py @@ -11,7 +11,7 @@ def main(): # Connect # Please change HOST and PORT to correct one - param = {'host': 'HOST', 'port': 'PORT'} + param = {'host': '192.168.1.121', 'port': '33001'} cnn_status = milvus.connect(**param) print('# Connect Status: {}'.format(cnn_status)) @@ -22,29 +22,44 @@ def main(): # Get server version print('# Server version: {}'.format(milvus.server_version())) - # Show tables and their description - status, tables = milvus.show_tables() - print('# Show tables: {}'.format(tables)) - - # Create table - # 01.Prepare data - param = { - 'table_name': 'test'+ str(random.randint(0,999)), - 'dimension': 256, - 'index_type': IndexType.IDMAP, - 'store_raw_vector': False - } - - # 02.Create table - res_status = milvus.create_table(Prepare.table_schema(**param)) - print('# Create table status: {}'.format(res_status)) - # Describe table + # Check if `test01` exists, if not, create a table test01 table_name = 'test01' res_status, table = milvus.describe_table(table_name) print('# Describe table status: {}'.format(res_status)) print('# Describe table:{}'.format(table)) + # Create table + # 01.Prepare data + if not table: + param = { + 'table_name': 'test01', + 'dimension': 256, + 'index_type': IndexType.IDMAP, + 'store_raw_vector': False + } + + # 02.Create table + res_status = milvus.create_table(Prepare.table_schema(**param)) + print('# Create table status: {}'.format(res_status)) + + # # Create table Optional + # # 01.Prepare data + # param = { + # 'table_name': 'test'+ str(random.randint(22,999)), + # 'dimension': 256, + # 'index_type': IndexType.IDMAP, + # 'store_raw_vector': False + # } + # + # # 02.Create table + # res_status = milvus.create_table(Prepare.table_schema(**param)) + # print('# Create table status: {}'.format(res_status)) + + # Show tables and their description + status, tables = milvus.show_tables() + print('# Show tables: {}'.format(tables)) + # Add vectors to table 'test01' # 01. Prepare data dim = 256 @@ -58,6 +73,12 @@ def main(): pprint(ids) # Search vectors + # When adding vectors for the first time, server will take at least 5s to + # persist vector data, so we have wait for 6s to search correctly + import time + print('Waiting for 6s...') + time.sleep(6) # Wait for server persist vector data + q_records = [Prepare.row_record(struct.pack(str(dim) + 'd', *[random.random() for _ in range(dim)])) for _ in range(5)] @@ -65,7 +86,7 @@ def main(): 'table_name': 'test01', 'query_records': q_records, 'top_k': 10, - # 'query_ranges': None # Optional + # 'query_ranges': # Optional } sta, results = milvus.search_vectors(**param) print('# Search vectors status: {}'.format(sta)) @@ -76,10 +97,6 @@ def main(): print('# Status: {}'.format(sta)) print('# Count: {}'.format(result)) - # Delete table 'test01' - res_status = milvus.delete_table(table_name) - print('# Delete table status: {}'.format(res_status)) - # Disconnect discnn_status = milvus.disconnect() print('# Disconnect Status: {}'.format(discnn_status)) diff --git a/python/sdk/setup.py b/python/sdk/setup.py index 176661cd75..46676284ca 100644 --- a/python/sdk/setup.py +++ b/python/sdk/setup.py @@ -3,11 +3,11 @@ import setuptools long_description = '' setuptools.setup( - name="MegaSearch", - version="0.0.1", + name="Milvus", + version="0.1.0", author="XuanYang", author_email="xuan.yang@zilliz.com", - description="Sdk for using MegaSearch", + description="Python Sdk for Milvus", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3.4",