Skip to content

pixano_inference.pydantic.data.vector_database

Pydantic model for the Vector databases.

LanceVector

Bases: BaseModel

Lance vector model.

Attributes:

Name Type Description
path str

The path to the LANCE dataset.

column str

The column to read.

indice int | None

The index of the row to read.

where str | None

The filter to apply. If specified, only one row should be returned.

shape list[int] | None

The shape of the vector.

read_vector(return_type='tensor')

Reads a vector from a Lance dataset.

Parameters:

Name Type Description Default
return_type Literal['tensor', 'numpy']

The type of the return value. Either 'tensor' or 'numpy'.

'tensor'

Returns:

Type Description
'Tensor' | ndarray

The vector.

Source code in pixano_inference/pydantic/data/vector_database.py
def read_vector(self, return_type: Literal["tensor", "numpy"] = "tensor") -> "Tensor" | np.ndarray:
    """Reads a vector from a Lance dataset.

    Args:
        return_type: The type of the return value. Either 'tensor' or 'numpy'.

    Returns:
        The vector.
    """
    return read_lance_vector(self.path, self.column, self.indice, self.where, self.shape, return_type)

validate_indice_or_where()

Validates that only one of 'indice' and 'where' is specified.

Source code in pixano_inference/pydantic/data/vector_database.py
@model_validator(mode="after")
def validate_indice_or_where(self) -> Self:
    """Validates that only one of 'indice' and 'where' is specified."""
    if self.indice is not None and self.where is not None:
        raise ValueError("Only one of 'indice' and 'where' can be specified.")
    elif self.indice is None and self.where is None:
        raise ValueError("One of 'indice' and 'where' must be specified.")
    return self