Vector Search Study¶
vector_search_study ¶
Public package interface for Vector Search Study.
ExactSearcher ¶
Bases: Protocol
Common synchronous interface implemented by every exact searcher.
Source code in src/vector_search_study/api.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
prepare_queries ¶
prepare_queries(queries: FloatMatrix) -> PreparedQueries
Prepare queries outside the timed search operation.
Source code in src/vector_search_study/api.py
167 168 169 | |
search ¶
search(queries: FloatMatrix, k: int) -> SearchResult
Validate and search a raw query matrix.
Source code in src/vector_search_study/api.py
171 172 173 | |
search_prepared ¶
search_prepared(
queries: PreparedQueries, k: int
) -> SearchResult
Search queries prepared outside the timed operation.
Source code in src/vector_search_study/api.py
175 176 177 | |
PreparedQueries
dataclass
¶
Validated, immutable queries ready for repeated timed searches.
Constructing this object validates normalization and copies the query matrix. Benchmarks can therefore prepare it outside the timed operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
FloatMatrix
|
C-contiguous float32 or float64 query matrix. |
required |
objective
|
SearchObjective
|
Score convention for which the queries were prepared. |
NORMALIZED_COSINE
|
Source code in src/vector_search_study/api.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
__post_init__ ¶
__post_init__() -> None
Validate, own, and freeze the query matrix.
Source code in src/vector_search_study/api.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
SearchObjective ¶
Bases: StrEnum
Exact-search score convention used throughout the study.
Source code in src/vector_search_study/api.py
18 19 20 21 22 23 24 25 26 27 28 | |
requires_normalization
property
¶
requires_normalization: bool
Return whether corpus and query rows must have unit L2 norm.
SearchResult
dataclass
¶
Ordered exact top-k indices and scores for a query batch.
Rows are ordered by decreasing score, with smaller corpus indices winning exact score ties. Scores are float64 and always use a higher-is-better convention: negative squared distance, inner product, or normalized cosine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
NDArray[int64]
|
Corpus indices with shape |
required |
scores
|
NDArray[float64]
|
Objective scores with the same shape. |
required |
Source code in src/vector_search_study/api.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__post_init__ ¶
__post_init__() -> None
Enforce the public result representation and ordering contract.
Source code in src/vector_search_study/api.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
BackendUnavailableError ¶
Bases: VectorSearchStudyError
Raised when an optional search backend is not installed.
Source code in src/vector_search_study/exceptions.py
16 17 | |
InvalidSearchParameterError ¶
Bases: VectorSearchStudyError
Raised when a search parameter is outside its supported range.
Source code in src/vector_search_study/exceptions.py
12 13 | |
InvalidVectorDataError ¶
Bases: VectorSearchStudyError
Raised when a corpus or query matrix violates the vector contract.
Source code in src/vector_search_study/exceptions.py
8 9 | |
UnsupportedObjectiveError ¶
Bases: VectorSearchStudyError
Raised when a backend cannot exactly implement a search objective.
Source code in src/vector_search_study/exceptions.py
20 21 | |
VectorSearchStudyError ¶
Bases: ValueError
Raised when Vector Search Study cannot complete an operation.
Source code in src/vector_search_study/exceptions.py
4 5 | |
FaissFlatIPSearcher ¶
Bases: BaseExactSearcher
Exact Faiss IndexFlatIP search for inner product or cosine.
Source code in src/vector_search_study/faiss_search.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective
| str = SearchObjective.INNER_PRODUCT,
) -> None
Build a float32 flat inner-product index outside search timing.
Source code in src/vector_search_study/faiss_search.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
FaissFlatL2Searcher ¶
Bases: BaseExactSearcher
Exact Faiss IndexFlatL2 search with negative squared-distance scores.
Source code in src/vector_search_study/faiss_search.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
__init__ ¶
__init__(corpus: FloatMatrix) -> None
Build a float32 flat L2 index outside search timing.
Source code in src/vector_search_study/faiss_search.py
19 20 21 22 23 24 25 26 | |
NumpyArgpartitionSearcher ¶
Bases: BaseExactSearcher
Score by matrix multiplication and partially select exact top-k rows.
Source code in src/vector_search_study/numpy_search.py
38 39 40 41 42 43 44 45 | |
NumpyBlockedSearcher ¶
Bases: BaseExactSearcher
Limit score-matrix memory by searching fixed-size corpus blocks.
Source code in src/vector_search_study/numpy_search.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
block_size: int = 16384,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> None
Build an index with a fixed number of corpus rows per block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus
|
FloatMatrix
|
Pre-normalized corpus vectors. |
required |
block_size
|
int
|
Maximum number of corpus rows scored per matrix multiplication. |
16384
|
objective
|
SearchObjective | str
|
Exact-search score convention. |
NORMALIZED_COSINE
|
Source code in src/vector_search_study/numpy_search.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
NumpySortSearcher ¶
Bases: BaseExactSearcher
Score by matrix multiplication and fully sort every score row.
Source code in src/vector_search_study/numpy_search.py
28 29 30 31 32 33 34 35 | |
PythonHeapSearcher ¶
Bases: BaseExactSearcher
Stream exhaustive scalar scores through a bounded size-k heap.
Source code in src/vector_search_study/python_search.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> None
Build the scalar corpus representation outside search timing.
Source code in src/vector_search_study/python_search.py
50 51 52 53 54 55 56 57 58 | |
PythonSortSearcher ¶
Bases: BaseExactSearcher
Exhaustively score into a Python list and fully sort it.
Source code in src/vector_search_study/python_search.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> None
Build the scalar corpus representation outside search timing.
Source code in src/vector_search_study/python_search.py
17 18 19 20 21 22 23 24 25 | |
ScipyCKDTreeSearcher ¶
Bases: BaseExactSearcher
Exact one-worker SciPy cKDTree search for L2-derived objectives.
Source code in src/vector_search_study/scipy_search.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective | str,
leaf_size: int = 16,
) -> None
Build a balanced compact cKDTree outside search timing.
Source code in src/vector_search_study/scipy_search.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
SklearnBallTreeSearcher ¶
Bases: BaseExactSearcher
Exact scikit-learn BallTree search for L2-derived objectives.
Source code in src/vector_search_study/sklearn_search.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective | str,
leaf_size: int = 40,
) -> None
Build a Euclidean BallTree outside search timing.
Source code in src/vector_search_study/sklearn_search.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
SklearnBruteSearcher ¶
Bases: BaseExactSearcher
Exact scikit-learn brute-force L2 or cosine search.
Source code in src/vector_search_study/sklearn_search.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
__init__ ¶
__init__(
corpus: FloatMatrix, *, objective: SearchObjective | str
) -> None
Build a one-thread brute-force nearest-neighbor index.
Source code in src/vector_search_study/sklearn_search.py
23 24 25 26 27 28 29 30 | |
SklearnKDTreeSearcher ¶
Bases: BaseExactSearcher
Exact scikit-learn KDTree search for L2-derived objectives.
Source code in src/vector_search_study/sklearn_search.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective | str,
leaf_size: int = 40,
) -> None
Build a Euclidean KDTree outside search timing.
Source code in src/vector_search_study/sklearn_search.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
SyntheticDataset
dataclass
¶
An immutable generated corpus/query pair and its provenance.
Attributes:
| Name | Type | Description |
|---|---|---|
corpus |
FloatMatrix
|
Pre-normalized corpus vectors. |
queries |
FloatMatrix
|
Pre-normalized query vectors. |
distribution |
str
|
Generator family name. |
seed |
int
|
PCG64 seed. |
objective |
SearchObjective
|
Search objective for which vectors were generated. |
Source code in src/vector_search_study/synthetic.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
TorchTopKSearcher ¶
Bases: BaseExactSearcher
Exact CPU PyTorch matmul/topk search for every study objective.
Source code in src/vector_search_study/torch_search.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
__init__ ¶
__init__(
corpus: FloatMatrix,
*,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> None
Materialize the corpus tensor outside search timing.
Source code in src/vector_search_study/torch_search.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
prepare_queries ¶
prepare_queries(queries: FloatMatrix) -> PreparedQueries
Validate queries and materialize their CPU tensor outside timing.
Source code in src/vector_search_study/torch_search.py
36 37 38 39 40 41 42 43 44 45 | |
normalize_rows ¶
normalize_rows(values: FloatMatrix) -> FloatMatrix
Return a C-contiguous copy with every row L2-normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
FloatMatrix
|
A finite, non-empty float32 or float64 matrix. |
required |
Returns:
| Type | Description |
|---|---|
FloatMatrix
|
A normalized matrix with the input dtype. |
Raises:
| Type | Description |
|---|---|
InvalidVectorDataError
|
If the input violates the matrix contract or contains a zero row. |
Source code in src/vector_search_study/api.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
prepare_queries ¶
prepare_queries(
queries: FloatMatrix,
*,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> PreparedQueries
Validate and copy queries for repeated search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queries
|
FloatMatrix
|
C-contiguous float32 or float64 matrix. Rows must be normalized for normalized cosine. |
required |
objective
|
SearchObjective | str
|
Score convention for the prepared queries. |
NORMALIZED_COSINE
|
Returns:
| Type | Description |
|---|---|
PreparedQueries
|
An immutable prepared query batch. |
Source code in src/vector_search_study/api.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
reference_search ¶
reference_search(
corpus: FloatMatrix,
queries: FloatMatrix,
k: int,
*,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> SearchResult
Compute canonical exact top-k results with accurate scalar summation.
This intentionally slow implementation is designed for correctness tests and untimed benchmark validation, not performance measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus
|
FloatMatrix
|
Corpus matrix with shape |
required |
queries
|
FloatMatrix
|
Query matrix with shape |
required |
k
|
int
|
Number of ordered neighbors to return. |
required |
objective
|
SearchObjective | str
|
Exact-search score convention. |
NORMALIZED_COSINE
|
Returns:
| Type | Description |
|---|---|
SearchResult
|
Canonically ordered exact results. |
Raises:
| Type | Description |
|---|---|
InvalidVectorDataError
|
If corpus and query contracts do not match. |
Source code in src/vector_search_study/reference.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
make_clustered_dataset ¶
make_clustered_dataset(
corpus_size: int,
dimension: int,
query_count: int,
*,
cluster_count: int = 8,
noise: float = 0.15,
dtype: object = np.float32,
seed: int = 20260801,
objective: SearchObjective
| str = SearchObjective.NORMALIZED_COSINE,
) -> SyntheticDataset
Generate normalized vectors around shared random cluster centroids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus_size
|
int
|
Number of corpus vectors. |
required |
dimension
|
int
|
Embedding dimension. |
required |
query_count
|
int
|
Number of query vectors. |
required |
cluster_count
|
int
|
Number of latent centroids. |
8
|
noise
|
float
|
Positive standard deviation around each centroid. |
0.15
|
dtype
|
object
|
Either float32 or float64. |
float32
|
seed
|
int
|
Non-negative PCG64 seed. |
20260801
|
objective
|
SearchObjective | str
|
Exact-search score convention. Cosine output is normalized; L2 and inner-product output is not. |
NORMALIZED_COSINE
|
Returns:
| Type | Description |
|---|---|
SyntheticDataset
|
A deterministic normalized clustered dataset. |
Source code in src/vector_search_study/synthetic.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
make_gaussian_dataset ¶
make_gaussian_dataset(
corpus_size: int,
dimension: int,
query_count: int,
*,
objective: SearchObjective | str,
dtype: object = np.float32,
seed: int = 20260801,
) -> SyntheticDataset
Generate deterministic unnormalized Gaussian embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus_size
|
int
|
Number of corpus vectors. |
required |
dimension
|
int
|
Embedding dimension. |
required |
query_count
|
int
|
Number of query vectors. |
required |
objective
|
SearchObjective | str
|
Squared L2 or inner-product search. |
required |
dtype
|
object
|
Either float32 or float64. |
float32
|
seed
|
int
|
Non-negative PCG64 seed. |
20260801
|
Returns:
| Type | Description |
|---|---|
SyntheticDataset
|
A deterministic unnormalized synthetic dataset. |
Raises:
| Type | Description |
|---|---|
InvalidSearchParameterError
|
If normalized cosine is requested. |
Source code in src/vector_search_study/synthetic.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
make_uniform_sphere_dataset ¶
make_uniform_sphere_dataset(
corpus_size: int,
dimension: int,
query_count: int,
*,
dtype: object = np.float32,
seed: int = 20260801,
) -> SyntheticDataset
Generate independent corpus and query vectors on the unit sphere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus_size
|
int
|
Number of corpus vectors. |
required |
dimension
|
int
|
Embedding dimension. |
required |
query_count
|
int
|
Number of query vectors. |
required |
dtype
|
object
|
Either float32 or float64. |
float32
|
seed
|
int
|
Non-negative PCG64 seed. |
20260801
|
Returns:
| Type | Description |
|---|---|
SyntheticDataset
|
A deterministic normalized synthetic dataset. |
Source code in src/vector_search_study/synthetic.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |