MilvusVectorStore#

class llama_index.vector_stores.MilvusVectorStore(uri: str = 'http://localhost:19530', token: str = '', collection_name: str = 'llamalection', dim: Optional[int] = None, embedding_field: str = 'embedding', doc_id_field: str = 'doc_id', similarity_metric: str = 'IP', consistency_level: str = 'Strong', overwrite: bool = False, text_key: Optional[str] = None, index_config: Optional[dict] = None, search_config: Optional[dict] = None, **kwargs: Any)#

Bases: VectorStore

The Milvus Vector Store.

In this vector store we store the text, its embedding and a its metadata in a Milvus collection. This implementation allows the use of an already existing collection. It also supports creating a new one if the collection doesn’t exist or if overwrite is set to True.

Parameters
  • uri (str, optional) – The URI to connect to, comes in the form of “http://address:port”.

  • token (str, optional) – The token for log in. Empty if not using rbac, if using rbac it will most likely be “username:password”.

  • collection_name (str, optional) – The name of the collection where data will be stored. Defaults to “llamalection”.

  • dim (int, optional) – The dimension of the embedding vectors for the collection. Required if creating a new collection.

  • embedding_field (str, optional) – The name of the embedding field for the collection, defaults to DEFAULT_EMBEDDING_KEY.

  • doc_id_field (str, optional) – The name of the doc_id field for the collection, defaults to DEFAULT_DOC_ID_KEY.

  • similarity_metric (str, optional) – The similarity metric to use, currently supports IP and L2.

  • consistency_level (str, optional) – Which consistency level to use for a newly created collection. Defaults to “Strong”.

  • overwrite (bool, optional) – Whether to overwrite existing collection with same name. Defaults to False.

  • text_key (str, optional) – What key text is stored in in the passed collection. Used when bringing your own collection. Defaults to None.

  • index_config (dict, optional) – The configuration used for building the Milvus index. Defaults to None.

  • search_config (dict, optional) – The configuration used for searching the Milvus index. Note that this must be compatible with the index type specified by index_config. Defaults to None.

Raises
  • ImportError – Unable to import pymilvus.

  • MilvusException – Error communicating with Milvus, more can be found in logging under Debug.

Returns

Vectorstore that supports add, delete, and query.

Return type

MilvusVectorstore

Attributes Summary

Methods Summary

add(nodes, **add_kwargs)

Add the embeddings and their nodes into Milvus.

delete(ref_doc_id, **delete_kwargs)

Delete nodes using with ref_doc_id.

query(query, **kwargs)

Query index for top k most similar nodes.

Attributes Documentation

client#

Get client.

stores_node: bool = True#
stores_text: bool = True#

Methods Documentation

add(nodes: List[BaseNode], **add_kwargs: Any) List[str]#

Add the embeddings and their nodes into Milvus.

Parameters

nodes (List[BaseNode]) – List of nodes with embeddings to insert.

Raises

MilvusException – Failed to insert data.

Returns

List of ids inserted.

Return type

List[str]

delete(ref_doc_id: str, **delete_kwargs: Any) None#

Delete nodes using with ref_doc_id.

Parameters

ref_doc_id (str) – The doc_id of the document to delete.

Raises

MilvusException – Failed to delete the doc.

query(query: VectorStoreQuery, **kwargs: Any) VectorStoreQueryResult#

Query index for top k most similar nodes.

Parameters
  • query_embedding (List[float]) – query embedding

  • similarity_top_k (int) – top k most similar nodes

  • doc_ids (Optional[List[str]]) – list of doc_ids to filter by

  • node_ids (Optional[List[str]]) – list of node_ids to filter by

  • output_fields (Optional[List[str]]) – list of fields to return

  • embedding_field (Optional[str]) – name of embedding field