hyrax.vector_dbs.qdrantdb_impl

Classes

QdrantDB

Implementation of the VectorDB interface using Qdrant as the backend.

Module Contents

class QdrantDB(config, context)[source]

Bases: hyrax.vector_dbs.vector_db_interface.VectorDB

Implementation of the VectorDB interface using Qdrant as the backend.

__init__()[source]

Create a new instance of a VectorDB object.

Parameters:
  • config (dict, optional) – An instance of the runtime configuration, by default None

  • context (dict, optional) – An instance of the context object, by default None

client = None[source]
collection_size = 0[source]
_convert_id_to_uuid(id: str | int) str[source]

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

connect()[source]

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

create()[source]

Create a new Qdrant database

insert(ids: list[str | int], vectors: list[numpy.ndarray])[source]

Insert a batch of vectors into the Qdrant database.

Parameters:
  • ids (list[Union[str, int]]) – The ids to associate with the vectors

  • vectors (list[np.ndarray]) – The vectors to insert into the database

search_by_id(id: str | int, k: int = 1) dict[int, list[str | int]][source]

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.

Parameters:
  • id (Union[str, int]) – The id of the vector in the database for which we want to find the k nearest neighbors

  • k (int, optional) – The number of nearest neighbors to return, by default 1, return only the closest neighbor

Returns:

Dictionary with input vector id as the key and the ids of the k nearest neighbors as the value.

Return type:

dict[int, list[Union[str, int]]]

search_by_vector(vectors: numpy.ndarray | list[numpy.ndarray], k: int = 1) dict[int, list[str | int]][source]

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

Parameters:
  • vectors (Union[np.array, list[np.ndarray]]) – The one or more vectors to use when searching for nearest neighbors

  • k (int, optional) – The number of nearest neighbors to return, by default 1, return only the closest neighbor

Returns:

Dictionary with input vector index as the key and the ids of the k nearest neighbors as the value.

Return type:

dict[int, list[Union[str, int]]]

_query_by_vector(vector: numpy.ndarray, k: int = 1) list[str][source]

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

get_by_id(ids: list[str | int]) dict[str | int, list[float]][source]

Retrieve the vectors associated with a list of ids.

Parameters:

ids (list[Union[str, int]]) – The ids of the vectors to retrieve.

Returns:

Dictionary with the ids as the keys and the vectors as the values.

Return type:

dict[Union[str, int], list[float]]