hyrax.vector_dbs.qdrantdb_impl
==============================

.. py:module:: hyrax.vector_dbs.qdrantdb_impl


Classes
-------

.. autoapisummary::

   hyrax.vector_dbs.qdrantdb_impl.QdrantDB


Module Contents
---------------

.. py:class:: QdrantDB(config, context)

   Bases: :py:obj:`hyrax.vector_dbs.vector_db_interface.VectorDB`


   Implementation of the VectorDB interface using Qdrant as the backend.

   .. py:method:: __init__

   Create a new instance of a `VectorDB` object.

   :param config: An instance of the runtime configuration, by default None
   :type config: dict, optional
   :param context: An instance of the context object, by default None
   :type context: dict, optional


   .. py:attribute:: client
      :value: None



   .. py:attribute:: collection_size
      :value: 0



   .. py:method:: _convert_id_to_uuid(id: Union[str, int]) -> str

      Convert an id to a UUID string using the OID namespace.



   .. py:method:: connect()

      Connect to the Qdrant database and return an instance of the client.



   .. py:method:: create()

      Create a new Qdrant database



   .. py:method:: insert(ids: list[Union[str, int]], vectors: list[numpy.ndarray])

      Insert a batch of vectors into the Qdrant database.

      :param ids: The ids to associate with the vectors
      :type ids: list[Union[str, int]]
      :param vectors: The vectors to insert into the database
      :type vectors: list[np.ndarray]



   .. py:method:: search_by_id(id: Union[str, int], k: int = 1) -> dict[int, list[Union[str, int]]]

      Get the ids of the k nearest neighbors for a given id in the database.

      Qdrant will exclude the id itself from the results, thus we first
      retrieve the vector for a given id, and then use that vector to find the
      k nearest neighbors.

      :param id: The id of the vector in the database for which we want to find the
                 k nearest neighbors
      :type id: Union[str, int]
      :param k: The number of nearest neighbors to return, by default 1, return only
                the closest neighbor
      :type k: int, optional

      :returns: Dictionary with input vector id as the key and the ids of the k
                nearest neighbors as the value.
      :rtype: dict[int, list[Union[str, int]]]



   .. py:method:: search_by_vector(vectors: Union[numpy.ndarray, list[numpy.ndarray]], k: int = 1) -> dict[int, list[Union[str, int]]]

      Get the ids of the k nearest neighbors for a given vector.

      :param vectors: The one or more vectors to use when searching for nearest neighbors
      :type vectors: Union[np.array, list[np.ndarray]]
      :param k: The number of nearest neighbors to return, by default 1, return only
                the closest neighbor
      :type k: int, optional

      :returns: Dictionary with input vector index as the key and the ids of the
                k nearest neighbors as the value.
      :rtype: dict[int, list[Union[str, int]]]



   .. py:method:: _query_by_vector(vector: numpy.ndarray, k: int = 1) -> list[str]

      Query the Qdrant database for the k nearest neighbors of a given vector.



   .. py:method:: get_by_id(ids: list[Union[str, int]]) -> dict[Union[str, int], list[float]]

      Retrieve the vectors associated with a list of ids.

      :param ids: The ids of the vectors to retrieve.
      :type ids: list[Union[str, int]]

      :returns: Dictionary with the ids as the keys and the vectors as the values.
      :rtype: dict[Union[str, int], list[float]]



