instancelib.instances.vectorstorage module

class instancelib.instances.vectorstorage.VectorStorage(*args, **kwds)[source]

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

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

None

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

None

abstract get_matrix(keys)[source]
Parameters:

keys (Sequence[TypeVar(KT)]) –

Return type:

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

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

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

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

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

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

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

abstract matrices_chunker(chunk_size=200)[source]
Parameters:

chunk_size (int) –

Return type:

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

abstract reload()[source]

Reload the index from disk

Return type:

None

abstract property writeable: bool
instancelib.instances.vectorstorage.ensure_writeable(func)[source]

A decorator that ensures that the wrapped method is only executed when the object is opened in writable mode

Parameters:

func (F) – The method that should only be executed if the method

Returns:

The same method with a check wrapped around it

Return type:

F