hyrax.vector_dbs.vector_db_interface
Classes
Interface for a vector database |
Module Contents
- class VectorDB(config: dict | None = None, context: dict | None = None)[source]
Bases:
abc.ABCInterface for a vector database
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
- abstractmethod insert(ids: list[str | int], vectors: list[numpy.ndarray])[source]
Insert a batch of vectors into the 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
- abstractmethod 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. Should use the provided id to look up the vector, then call search_by_vector.
- 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 index as the key and the ids of the k nearest neighbors as the value.
- Return type:
dict[int, list[Union[str, int]]]
- abstractmethod 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]]]
- abstractmethod 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]]