instancelib.instances.memoryvectorstorage module

class instancelib.instances.memoryvectorstorage.MemoryVectorStorage(storage, from_matrix, to_matrix)[source]

Bases: VectorStorage[KT, VT, MT], Generic[KT, VT, MT]

Parameters:
add_bulk(input_keys, input_values)[source]
Parameters:
Return type:

None

add_bulk_matrix(input_keys, matrix)[source]
Parameters:
Return type:

None

classmethod create(from_matrix, to_matrix)[source]
Parameters:
Return type:

MemoryVectorStorage[TypeVar(KT), TypeVar(VT), TypeVar(MT)]

from_matrix: Callable[[TypeVar(MT)], Sequence[TypeVar(VT)]]
get_matrix(keys)[source]
Parameters:

keys (Sequence[TypeVar(KT)]) –

Return type:

Tuple[Sequence[TypeVar(KT)], TypeVar(MT)]

get_matrix_chunked(keys, chunk_size)[source]
Parameters:
Return type:

Iterator[Tuple[Sequence[TypeVar(KT)], TypeVar(MT)]]

get_vectors(keys)[source]

Return the vectors that correspond with the keys

Parameters:

keys (Sequence[KT]) – A list of identifier keys

Returns:

A tuple containing two lists:

  • A list with identifier (order may differ from keys argument)

  • A list with vectors

Return type:

Tuple[Sequence[KT], Sequence[VT]]

get_vectors_chunked(keys, chunk_size=200)[source]

Return vectors in chunks of chunk_size containing the vectors requested in keys

Parameters:
  • keys (Sequence[KT]) – A list of identifier keys

  • chunk_size (int, optional) – The size of the chunks, by default 200

Yields:

Tuple[Sequence[KT], Sequence[VT]]

A tuple containing two lists:

  • A list with identifiers (order may differ from keys argument)

  • A list with vectors

Return type:

Iterator[Tuple[Sequence[TypeVar(KT)], Sequence[TypeVar(VT)]]]

get_vectors_zipped(keys, chunk_size=200)[source]
Parameters:
Return type:

Iterator[Sequence[Tuple[TypeVar(KT), TypeVar(VT)]]]

matrices_chunker(chunk_size=200)[source]
Parameters:

chunk_size (int) –

Return type:

Iterator[Tuple[Sequence[TypeVar(KT)], TypeVar(MT)]]

reload()[source]

Reload the index from disk

Return type:

None

to_matrix: Callable[[Sequence[TypeVar(VT)]], TypeVar(MT)]
writeable()[source]
Return type:

bool

class instancelib.instances.memoryvectorstorage.NumpyFromMatrix[source]

Bases: object

class instancelib.instances.memoryvectorstorage.NumpyMemoryStorage(storage)[source]

Bases: MemoryVectorStorage[KT, ndarray, ndarray], Generic[KT]

Parameters:

storage (MutableMapping[TypeVar(KT), ndarray[Any, dtype[Any]]]) –

classmethod create()[source]
Return type:

NumpyMemoryStorage[TypeVar(KT)]

from_matrix: Callable[[TypeVar(MT)], Sequence[TypeVar(VT)]]
to_matrix: Callable[[Sequence[TypeVar(VT)]], TypeVar(MT)]
class instancelib.instances.memoryvectorstorage.NumpyToMatrix[source]

Bases: object