QdrantStorage

class QdrantStorage(BaseVectorStorage):

An implementation of the BaseVectorStorage for interacting with Qdrant, a vector search engine.

The detailed information about Qdrant is available at: Qdrant <https://qdrant.tech/>_

Parameters:

  • vector_dim (int): The dimension of storing vectors.
  • collection_name (Optional[str], optional): Name for the collection in the Qdrant. If not provided, set it to the current time with iso format. (default: :obj:None)
  • url_and_api_key (Optional[Tuple[str, str]], optional): Tuple containing the URL and API key for connecting to a remote Qdrant instance. (default: :obj:None)
  • path (Optional[str], optional): Path to a directory for initializing a local Qdrant client. (default: :obj:None)
  • distance (VectorDistance, optional): The distance metric for vector comparison (default: :obj:VectorDistance.COSINE)
  • delete_collection_on_del (bool, optional): Flag to determine if the collection should be deleted upon object destruction. (default: :obj:False) **kwargs (Any): Additional keyword arguments for initializing QdrantClient.
  • Notes: - If url_and_api_key is provided, it takes priority and the client will attempt to connect to the remote Qdrant instance using the URL endpoint. - If url_and_api_key is not provided and path is given, the client will use the local path to initialize Qdrant. - If neither url_and_api_key nor path is provided, the client will be initialized with an in-memory storage (":memory:").

init

def __init__(
    self,
    vector_dim: int,
    collection_name: Optional[str] = None,
    url_and_api_key: Optional[Tuple[str, str]] = None,
    path: Optional[str] = None,
    distance: VectorDistance = VectorDistance.COSINE,
    delete_collection_on_del: bool = False,
    **kwargs: Any
):

del

def __del__(self):

Deletes the collection if :obj:del_collection is set to :obj:True.

_create_client

def _create_client(
    self,
    url_and_api_key: Optional[Tuple[str, str]],
    path: Optional[str],
    **kwargs: Any
):

_check_and_create_collection

def _check_and_create_collection(self):

_create_collection

def _create_collection(
    self,
    collection_name: str,
    size: int,
    distance: VectorDistance = VectorDistance.COSINE,
    **kwargs: Any
):

Creates a new collection in the database.

Parameters:

  • collection_name (str): Name of the collection to be created.
  • size (int): Dimensionality of vectors to be stored in this collection.
  • distance (VectorDistance, optional): The distance metric to be used for vector similarity. (default: :obj:VectorDistance.COSINE) **kwargs (Any): Additional keyword arguments.

_delete_collection

def _delete_collection(self, collection_name: str, **kwargs: Any):

Deletes an existing collection from the database.

Parameters:

  • collection (str): Name of the collection to be deleted. **kwargs (Any): Additional keyword arguments.

_collection_exists

def _collection_exists(self, collection_name: str):

Returns whether the collection exists in the database

_generate_collection_name

def _generate_collection_name(self):

Generates a collection name if user doesn’t provide

_get_collection_info

def _get_collection_info(self, collection_name: str):

Retrieves details of an existing collection.

Parameters:

  • collection_name (str): Name of the collection to be checked.

Returns:

Dict[str, Any]: A dictionary containing details about the collection.

close_client

def close_client(self, **kwargs):

Closes the client connection to the Qdrant storage.

add

def add(self, records: List[VectorRecord], **kwargs):

Adds a list of vectors to the specified collection.

Parameters:

  • vectors (List[VectorRecord]): List of vectors to be added. **kwargs (Any): Additional keyword arguments.

update_payload

def update_payload(
    self,
    ids: List[str],
    payload: Dict[str, Any],
    **kwargs: Any
):

Updates the payload of the vectors identified by their IDs.

Parameters:

  • ids (List[str]): List of unique identifiers for the vectors to be updated.
  • payload (Dict[str, Any]): List of payloads to be updated. **kwargs (Any): Additional keyword arguments.

delete_collection

def delete_collection(self):

Deletes the entire collection in the Qdrant storage.

delete

def delete(
    self,
    ids: Optional[List[str]] = None,
    payload_filter: Optional[Dict[str, Any]] = None,
    **kwargs: Any
):

Deletes points from the collection based on either IDs or payload filters.

Parameters:

  • ids (Optional[List[str]], optional): List of unique identifiers for the vectors to be deleted.
  • payload_filter (Optional[Dict[str, Any]], optional): A filter for the payload to delete points matching specific conditions. If ids is provided, payload_filter will be ignored unless both are combined explicitly. **kwargs (Any): Additional keyword arguments pass to QdrantClient. delete.

status

def status(self):

query

def query(
    self,
    query: VectorDBQuery,
    filter_conditions: Optional[Dict[str, Any]] = None,
    **kwargs: Any
):

Searches for similar vectors in the storage based on the provided query.

Parameters:

  • query (VectorDBQuery): The query object containing the search vector and the number of top similar vectors to retrieve.
  • filter_conditions (Optional[Dict[str, Any]], optional): A dictionary specifying conditions to filter the query results. **kwargs (Any): Additional keyword arguments.

Returns:

List[VectorDBQueryResult]: A list of vectors retrieved from the storage based on similarity to the query vector.

clear

def clear(self):

Remove all vectors from the storage.

load

def load(self):

Load the collection hosted on cloud service.

client

def client(self):

Provides access to the underlying vector database client.