Module indexes (0.4.0)

API documentation for indexes module.

Classes

BaseIndex

BaseIndex(name: Optional[str] = None, index_type: str = 'base', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy = <factory>, partial_indexes: Optional[list[str]] = None)

BaseIndex(name: Optional[str] = None, index_type: str = 'base', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy =

DistanceStrategy

DistanceStrategy(value)

Enumerator of the Distance strategies.

ExactNearestNeighbor

ExactNearestNeighbor(name: Optional[str] = None, index_type: str = 'exactnearestneighbor', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy = <factory>, partial_indexes: Optional[list[str]] = None)

ExactNearestNeighbor(name: Optional[str] = None, index_type: str = 'exactnearestneighbor', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy =

HNSWIndex

HNSWIndex(name: Optional[str] = None, index_type: str = 'hnsw', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy = <factory>, partial_indexes: Optional[list[str]] = None, m: int = 16, ef_construction: int = 64)

HNSWIndex(name: Optional[str] = None, index_type: str = 'hnsw', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy =

HNSWQueryOptions

HNSWQueryOptions(ef_search: int = 40)

HNSWQueryOptions(ef_search: int = 40)

IVFFlatIndex

IVFFlatIndex(name: Optional[str] = None, index_type: str = 'ivfflat', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy = <factory>, partial_indexes: Optional[list[str]] = None, lists: int = 100)

IVFFlatIndex(name: Optional[str] = None, index_type: str = 'ivfflat', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy =

IVFFlatQueryOptions

IVFFlatQueryOptions(probes: int = 1)

IVFFlatQueryOptions(probes: int = 1)

IVFIndex

IVFIndex(name: Optional[str] = None, index_type: str = 'ivf', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy = <factory>, partial_indexes: Optional[list[str]] = None, lists: int = 100)

IVFIndex(name: Optional[str] = None, index_type: str = 'ivf', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy =

IVFQueryOptions

IVFQueryOptions(probes: int = 1)

IVFQueryOptions(probes: int = 1)

QueryOptions

QueryOptions()

API documentation for QueryOptions class.

ScaNNIndex

ScaNNIndex(name: typing.Optional[str] = None, index_type: str = 'ScaNN', distance_strategy: llama_index_alloydb_pg.indexes.DistanceStrategy = <factory>, partial_indexes: typing.Optional[list[str]] = None, num_leaves: int = 5, *, mode: typing.Optional[str] = None)

ScaNN index configuration for AlloyDB.

See https://cloud.google.com/alloydb/docs/ai/create-scann-index.

Parameters
Name Description
num_leaves int

Number of partitions. Used by the default and "MANUAL" modes. Defaults to 5.

mode Optional[str]

Keyword-only. "AUTO" lets AlloyDB choose the index parameters, so num_leaves and quantizer are not sent. "MANUAL" sends num_leaves and quantizer explicitly. Case-insensitive. Defaults to None, which emits the same index options as previous releases. "AUTO" needs a table with at least 10,000 rows. On a smaller table it needs deferred index creation (Preview): turn on the scann.enable_index_maintenance flag and scann.enable_index_with_insufficient_data or scann.enable_preview_features. AlloyDB then builds the index when the table reaches 10,000 rows. See https://cloud.google.com/alloydb/docs/ai/create-scann-index. The set_maintenance_work_mem sizing is based on num_leaves, so it doesn't apply to "AUTO".

Exceptions
Type Description
ValueError If mode is not "AUTO" or "MANUAL", or if num_leaves is not an integer of at least 1.

ScaNNQueryOptions

ScaNNQueryOptions(
    num_leaves_to_search: int = 1,
    pre_reordering_num_neighbors: int = -1,
    pct_leaves_to_search: typing.Optional[float] = None,
)
Parameters
Name Description
num_leaves_to_search int

Number of partitions to search. Defaults to 1.

pre_reordering_num_neighbors int

Number of candidate neighbors to consider before reordering. -1 uses the server default. Defaults to -1.

pct_leaves_to_search Optional[float]

Percentage of the current partitions to search, between 0 and 100 (fractions allowed). A value above 0 is used instead of num_leaves_to_search. 0 turns it off, so AlloyDB uses num_leaves_to_search. Defaults to None, which does not send it, so the server setting applies. See https://cloud.google.com/alloydb/docs/ai/maintain-vector-indexes#manage-leave-to-search-split-partitions.

Exceptions
Type Description
ValueError If pct_leaves_to_search is outside 0 to 100.

StrategyMixin

StrategyMixin(
    operator: str, search_function: str, index_function: str, scann_index_function: str
)

API documentation for StrategyMixin class.