morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService
- class MilvusVectorDBService(uri, user='', password='', db_name='', token='', truncate_long_strings=False, **kwargs)[source]
Bases:
<a href="morpheus.service.vdb.vector_db_service.VectorDBService.html#morpheus.service.vdb.vector_db_service.VectorDBService">morpheus.service.vdb.vector_db_service.VectorDBService</a>
Service class for Milvus Vector Database implementation. This class provides functions for interacting with a Milvus vector database.
- Parameters
- host
- port
- alias
- truncate_long_strings
- **kwargs
The hostname or IP address of the Milvus server.
The port number for connecting to the Milvus server.
Alias for the Milvus connection, by default “default”.
When true, truncate strings values that are longer than the max length of the field
Additional keyword arguments specific to the Milvus connection configuration.
Methods
<a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.close">close</a>
()Close the connection to the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.count">count</a>
(name, **kwargs)Returns number of rows/entities in the given collection. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.create">create</a>
(name[, overwrite])Create a collection in the Milvus vector database with the specified name and configuration. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.create_from_dataframe">create_from_dataframe</a>
(name, df[, overwrite])Create collections in the vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.delete">delete</a>
(name, expr, **kwargs)Delete vectors from the collection using expressions. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.delete_by_keys">delete_by_keys</a>
(name, keys, **kwargs)Delete vectors by keys from the collection. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.describe">describe</a>
(name, **kwargs)Describe the collection in the vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.drop">drop</a>
(name, **kwargs)Drop a collection, index, or partition in the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.get_collection_lock">get_collection_lock</a>
(name)Get a lock for a given collection name. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.has_store_object">has_store_object</a>
(name)Check if a collection exists in the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.insert">insert</a>
(name, data, **kwargs)Insert a collection specific data in the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.insert_dataframe">insert_dataframe</a>
(name, df, **kwargs)Converts dataframe to rows and insert to a collection in the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.list_store_objects">list_store_objects</a>
(**kwargs)List the names of all collections in the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.query">query</a>
(name[, query])Query data in a collection in the Milvus vector database. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.release_resource">release_resource</a>
(name)Release a loaded collection from the memory. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.retrieve_by_keys">retrieve_by_keys</a>
(name, keys, **kwargs)Retrieve the inserted vectors using their primary keys from the Collection. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.similarity_search">similarity_search</a>
(name, **kwargs)Perform a similarity search within the collection. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.transform">transform</a>
(data, **kwargs)Transform data according to the specific vector database implementation. <a href="#morpheus.service.vdb.milvus_vector_db_service.MilvusVectorDBService.update">update</a>
(name, data, **kwargs)Update data in the vector database. load_resource - close()[source]
Close the connection to the Milvus vector database.
This method disconnects from the Milvus vector database by removing the connection.
- count(name, **kwargs)[source]
Returns number of rows/entities in the given collection.
- Parameters
- name
- **kwargs
Name of the collection.
Additional keyword arguments for the count operation.
- Returns
- int
Returns number of entities in the collection.
- create(name, overwrite=False, **kwargs)[source]
Create a collection in the Milvus vector database with the specified name and configuration. This method creates a new collection in the Milvus vector database with the provided name and configuration options. If the collection already exists, it can be overwritten if the
overwrite
parameter is set to True.- Parameters
- name
- overwrite
- **kwargs
Name of the collection to be created.
If True, the collection will be overwritten if it already exists, by default False.
Additional keyword arguments containing collection configuration.
- Raises
- ValueError
If the provided schema fields configuration is empty.
- create_from_dataframe(name, df, overwrite=False, **kwargs)[source]
Create collections in the vector database.
- Parameters
- name
- df
- overwrite
- **kwargs
Name of the collection.
The dataframe to create the collection from.
Whether to overwrite the collection if it already exists. Default is False.
Extra keyword arguments specific to the vector database implementation.
- delete(name, expr, **kwargs)[source]
Delete vectors from the collection using expressions.
- Parameters
- name
- expr
- **kwargs
Name of the collection.
Delete expression.
Extra keyword arguments specific to the vector database implementation.
- Returns
- dict[str, typing.Any]
Returns result of the given keys that are delete from the collection.
- delete_by_keys(name, keys, **kwargs)[source]
Delete vectors by keys from the collection.
- Parameters
- name
- keys
- **kwargs
Name of the collection.
Primary keys to delete vectors.
Extra keyword arguments specific to the vector database implementation.
- Returns
- typing.Any
Returns result of the given keys that are delete from the collection.
- describe(name, **kwargs)[source]
Describe the collection in the vector database.
- Parameters
- name
- **kwargs
Name of the collection.
Additional keyword arguments specific to the Milvus vector database.
- Returns
- dict
Returns collection information.
- drop(name, **kwargs)[source]
Drop a collection, index, or partition in the Milvus vector database.
This method allows you to drop a collection, an index within a collection, or a specific partition within a collection in the Milvus vector database.
- Parameters
- name
- **kwargs
Name of the collection, index, or partition to be dropped.
Additional keyword arguments for specifying the type and partition name (if applicable).
- Raises
- ValueError
If mandatory arguments are missing or if the provided ‘collection’ value is invalid.
- classmethod get_collection_lock(name)[source]
Get a lock for a given collection name.
- Parameters
- name
Name of the collection for which to acquire the lock.
- Returns
- threading.Lock
A thread lock specific to the given collection name.
- has_store_object(name)[source]
Check if a collection exists in the Milvus vector database.
- Parameters
- name
Name of the collection to check.
- Returns
- bool
True if the collection exists, False otherwise.
- insert(name, data, **kwargs)[source]
Insert a collection specific data in the Milvus vector database.
- Parameters
- name
- data
- **kwargs
Name of the collection to be inserted.
Data to be inserted in the collection.
Additional keyword arguments containing collection configuration.
- Returns
- dict
Returns response content as a dictionary.
- Raises
- RuntimeError
If the collection not exists exists.
- insert_dataframe(name, df, **kwargs)[source]
Converts dataframe to rows and insert to a collection in the Milvus vector database.
- Parameters
- name
- df
- **kwargs
Name of the collection to be inserted.
Dataframe to be inserted in the collection.
Additional keyword arguments containing collection configuration.
- Returns
- dict
Returns response content as a dictionary.
- Raises
- RuntimeError
If the collection not exists exists.
- list_store_objects(**kwargs)[source]
List the names of all collections in the Milvus vector database.
- Returns
- list[str]
A list of collection names.
- query(name, query=None, **kwargs)[source]
Query data in a collection in the Milvus vector database.
This method performs a search operation in the specified collection/partition in the Milvus vector database.
- Parameters
- name
- query
- **kwargs
Name of the collection to search within.
The search query, which can be a filter expression.
Additional keyword arguments for the search operation.
- Returns
- typing.Any
The search result, which can vary depending on the query and options.
- release_resource(name)[source]
Release a loaded collection from the memory.
- Parameters
- name
Name of the collection to release.
- retrieve_by_keys(name, keys, **kwargs)[source]
Retrieve the inserted vectors using their primary keys from the Collection.
- Parameters
- name
- keys
- **kwargs
Name of the collection.
Primary keys to get vectors for. Depending on pk_field type it can be int or str or a list of either.
Additional keyword arguments for the retrieval operation.
- Returns
- list[typing.Any]
Returns result rows of the given keys from the collection.
- async similarity_search(name, **kwargs)[source]
Perform a similarity search within the collection.
- Parameters
- name
- **kwargs
Name of the collection.
Extra keyword arguments specific to the vector database implementation.
- Returns
- list[dict]
Returns a list of dictionaries representing the results of the similarity search.
- transform(data, **kwargs)[source]
Transform data according to the specific vector database implementation.
- Parameters
- data
- **kwargs
Data to be updated in the resource.
Extra keyword arguments specific to the vector database implementation.
- Returns
- typing.Any
Returns transformed data as per the implementation.
- update(name, data, **kwargs)[source]
Update data in the vector database.
- Parameters
- name
- data
- **kwargs
Name of the collection.
Data to be updated in the collection.
Extra keyword arguments specific to upsert operation.
- Returns
- dict[str, typing.Any]
Returns result of the updated operation stats.