# Vectors `Vector`, `SparseVector`, `Distance` and `VectorIndex` are importable from `agensgraph`; the rest from `agensgraph.vector`. See [Embedding vectors](../../data/vectors.md). ## Values ```{py:currentmodule} agensgraph ``` ````{py:class} Vector(values: Iterable[float] | None = None, *, half: bool = False) A dense vector, single precision, kept as the bytes it arrived in until a number is read. Sent as a `vector`. `half=True` reads text at half precision. ```{py:property} values :type: array[float] The numbers, an `array('f')`. ``` ```{py:method} tolist() -> list[float] The numbers, a `list`. ``` ```{py:method} to_bytes() -> bytes pgvector's binary form. ``` ```{py:method} index(value: float) -> int ``` ```{py:method} count(value: float) -> int ``` ```{py:method} from_wire(raw: bytes, *, half: bool = False) -> Vector :classmethod: From pgvector's binary form. ``` ```{py:method} from_wire_text(text: bytes, *, half: bool = False) -> Vector :classmethod: From pgvector's text form. ``` ```` ````{py:class} SparseVector(entries: Mapping[int, float] | Iterable[tuple[int, float]], dimensions: int) A sparse vector of `dimensions`, from a mapping or pairs of index and value. Indices count from zero. Sent as `sparsevec` text. ```{py:property} dimensions :type: int ``` ```{py:property} indices :type: tuple[int, ...] ``` ```{py:property} values :type: tuple[float, ...] ``` ```{py:method} to_dict() -> dict[int, float] ``` ```{py:method} to_dense() -> list[float] ``` ```{py:method} to_text() -> str pgvector's text form, counting from one. ``` ```{py:method} from_dense(values: Sequence[float]) -> SparseVector :classmethod: ``` ```{py:method} from_text(text: str | bytes) -> SparseVector :classmethod: ``` ```` ````{py:class} Distance A distance, whose value is its operator. ```{py:attribute} L2 `<->` ``` ```{py:attribute} INNER_PRODUCT `<#>`, negated ``` ```{py:attribute} COSINE `<=>` ``` ```{py:attribute} L1 `<+>` ``` ```{py:attribute} HAMMING `<~>`, for bits ``` ```{py:attribute} JACCARD `<%>`, for bits ``` ```{py:property} operator_class :type: str The `vector` operator class that serves it. ``` ```{py:property} is_for_bits :type: bool ``` ```` ````{py:class} VectorIndex(label: str, name: str, property: str, method: str, operator_class: str | None, type: str | None, dimensions: int | None, options: dict[str, str]) A vector index, in parts. ```{py:attribute} label :type: str ``` ```{py:attribute} name :type: str ``` ```{py:attribute} property :type: str ``` ```{py:attribute} method :type: str ``` ```{py:attribute} operator_class :type: str | None `None` for the method's default ``` ```{py:attribute} type :type: str | None ``` ```{py:attribute} dimensions :type: int | None ``` ```{py:attribute} options :type: dict[str, str] the settings it was built with, as strings ``` ```` ## Statements ```{py:currentmodule} agensgraph.vector ``` ```{py:function} generated_column(name: str, dimensions: int, *, type: str = 'vector') -> str A column definition, `name vector(n) generated`, for `CREATE VLABEL`. ``` ```{py:function} vector_index(label: str, property: str, *, dimensions: int | None = None, type: str = 'vector', method: str = 'hnsw', operator_class: str = 'vector_cosine_ops', name: str | None = None, options: Mapping[str, object] | None = None) -> str A property index for a vector property. Pass `dimensions` for a property in the map, and leave it out for a column of its own. ``` ```{py:function} nearest(label: str, property: str, *, dimensions: int | None = None, type: str = 'vector', limit: int = 10, operator: str = '<=>', variable: str = 'n') -> str The nearest-neighbour search matching `vector_index()`, with one `%s` for the query vector. ``` ```{py:function} search_option_statements(options: Mapping[str, object], *, local: bool = True) -> list[str] The `SET` statements `vector_search_options()` sends. ``` ```{py:data} SEARCH_OPTIONS :value: {'hnsw.ef_search': , 'hnsw.iterative_scan': , 'hnsw.max_scan_tuples': , 'hnsw.scan_mem_multiplier': , 'ivfflat.probes': , 'ivfflat.iterative_scan': , 'ivfflat.max_probes': } The search settings, with the type each takes. ``` ```{py:data} TYPES :value: ('vector', 'halfvec', 'sparsevec') pgvector's types the driver reads. ```