opatio.index.floatvectorindex module

class opatio.index.floatvectorindex.FloatVectorIndex(vector: Tuple[float, ...], hashPrecision: int)[source]

Bases: object

Represents an index for a float vector with hashing and serialization capabilities.

Parameters:
  • vector (Tuple[float]) – The tuple of floats representing the vector.

  • hashPrecision (int) – The precision to which floats are rounded for hashing.

__hash__() int[source]

Compute the hash of the float vector index.

__bytes__() bytes[source]

Convert the float vector index to bytes.

__len__() int[source]

Get the number of elements in the float vector.

__repr__() str[source]

Get the string representation of the float vector index.

__getitem__(index: int) float[source]

Get the item from vector at the specified index.

copy() FloatVectorIndex[source]

Create a copy of the float vector index.

Examples

>>> index = FloatVectorIndex((1.12345, 2.6789), hashPrecision=3)
>>> hash(index)
1234567890123456789
>>> bytes(index)
b'...'
>>> len(index)
2
>>> index[0]
1.123
copy() FloatVectorIndex[source]

Create a copy of the float vector index.

Returns:

A new instance of FloatVectorIndex with the same values.

Return type:

FloatVectorIndex

Examples

>>> index = FloatVectorIndex((1.12345, 2.6789), hashPrecision=3)
>>> index_copy = index.copy()
>>> index_copy.vector
(1.12345, 2.6789)
hashPrecision: int
vector: Tuple[float, ...]