hyrax.vector_dbs.vector_db_interface
====================================

.. py:module:: hyrax.vector_dbs.vector_db_interface


Classes
-------

.. autoapisummary::

   hyrax.vector_dbs.vector_db_interface.VectorDB


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

.. py:class:: VectorDB(config: dict | None = None, context: dict | None = None)

   Bases: :py:obj:`abc.ABC`


   Interface for a vector database

   .. 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:: config


   .. py:attribute:: context


   .. py:method:: connect()
      :abstractmethod:


      Connect to an existing database



   .. py:method:: create()
      :abstractmethod:


      Create a new database



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


      Insert a batch of vectors into the 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]]]
      :abstractmethod:


      Get the ids of the k nearest neighbors for a given id in the database.
      Should use the provided id to look up the vector, then call search_by_vector.

      :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 index 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]]]
      :abstractmethod:


      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:: get_by_id(ids: list[Union[str, int]]) -> dict[Union[str, int], list[float]]
      :abstractmethod:


      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]]



