-
Notifications
You must be signed in to change notification settings - Fork 126
feat: Add sparse vectors benchmark support for Qdrant #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d14e5fe
feat: Add sparse vectors benchmark support in Qdrant
KShivendu b9be8bb
fix: Self review
KShivendu 7af636a
feat: Add sparse dataset for CI benchmarks
KShivendu ce902b2
feat: Introduce SparseVector class
KShivendu 50ca05f
feat: Disallow sparse vector dataset being run with non sparse vector…
KShivendu feb3323
feat: use different engine config to run sparse vector benchmarks
KShivendu 2a653f7
fix: use different engine config to run sparse vector benchmarks
KShivendu 9d0fc40
feat: Optimize CI benchmarks workflow
KShivendu 218c775
feat: Add 1M sparse dataset
KShivendu 36bcfaa
fix: remove scipy, read csr matrix manually (#117)
joein 4a7f09d
fix: Dataset query reader should have sparse_vector=None by default
KShivendu 074d06c
refactor: Changes based on feedback
KShivendu 8622eea
refactoring: refactor sparse vector support (#118)
joein 6be36d2
feat: Use pydantic construct
KShivendu 174ef91
refactor: Update all engines to use Query and Record dataclasses (#116)
KShivendu 750ad61
Merge branch 'master' into feat/sparse-ci-benchmarks
KShivendu 931d9e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6aa5ee8
fix: Type issue
KShivendu 542fd33
fix: Allow python 3.8 since scipy is now removed
KShivendu b11d41f
fix: Add missing redis-m-16-ef-128 config
KShivendu a30f25b
fix: redis container port
KShivendu 4091b78
fix linter
generall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,18 +15,29 @@ jobs: | |
| - uses: webfactory/[email protected] | ||
| with: | ||
| ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
| - name: Setup CI | ||
| run: bash -x tools/setup_ci.sh | ||
| - name: Benches | ||
| run: | | ||
| export HCLOUD_TOKEN=${{ secrets.HCLOUD_TOKEN }} | ||
| export GCS_KEY=${{ secrets.GCS_KEY }} | ||
| export GCS_SECRET=${{ secrets.GCS_SECRET }} | ||
| export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} | ||
| export POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} | ||
| export HCLOUD_TOKEN=${{ secrets.HCLOUD_TOKEN }} | ||
| export GCS_KEY=${{ secrets.GCS_KEY }} | ||
| export GCS_SECRET=${{ secrets.GCS_SECRET }} | ||
| export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} | ||
| export POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} | ||
|
|
||
| # Benchmark the dev branch: | ||
| export QDRANT_VERSION=ghcr/dev | ||
| bash -x tools/run_ci.sh | ||
| declare -A DATASET_TO_ENGINE | ||
| DATASET_TO_ENGINE["laion-small-clip"]="qdrant-continuous-benchmark" | ||
| DATASET_TO_ENGINE["msmarco-sparse-1M"]="qdrant-sparse-vector" | ||
|
|
||
| # Benchmark the master branch: | ||
| export QDRANT_VERSION=docker/master | ||
| bash -x tools/run_ci.sh | ||
| for dataset in "${!DATASET_TO_ENGINE[@]}"; do | ||
| export ENGINE_NAME=${DATASET_TO_ENGINE[$dataset]} | ||
| export DATASETS=$dataset | ||
|
|
||
| # Benchmark the dev branch: | ||
| export QDRANT_VERSION=ghcr/dev | ||
| bash -x tools/run_ci.sh | ||
|
|
||
| # Benchmark the master branch: | ||
| export QDRANT_VERSION=docker/master | ||
| bash -x tools/run_ci.sh | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Iterator, List, Tuple, Union | ||
|
|
||
| import numpy as np | ||
|
|
||
| from dataset_reader.base_reader import BaseReader, Query, Record, SparseVector | ||
|
|
||
|
|
||
| def read_sparse_matrix_fields( | ||
| filename: Union[Path, str] | ||
| ) -> Tuple[np.array, np.array, np.array]: | ||
| """Read the fields of a CSR matrix without instantiating it""" | ||
|
|
||
| with open(filename, "rb") as f: | ||
| sizes = np.fromfile(f, dtype="int64", count=3) | ||
| n_row, n_col, n_non_zero = sizes | ||
| index_pointer = np.fromfile(f, dtype="int64", count=n_row + 1) | ||
| assert n_non_zero == index_pointer[-1] | ||
| columns = np.fromfile(f, dtype="int32", count=n_non_zero) | ||
| assert np.all(columns >= 0) and np.all(columns < n_col) | ||
| values = np.fromfile(f, dtype="float32", count=n_non_zero) | ||
| return values, columns, index_pointer | ||
|
|
||
|
|
||
| def csr_to_sparse_vectors( | ||
| values: List[float], columns: List[int], index_pointer: List[int] | ||
| ) -> Iterator[SparseVector]: | ||
| num_rows = len(index_pointer) - 1 | ||
|
|
||
| for i in range(num_rows): | ||
| start = index_pointer[i] | ||
| end = index_pointer[i + 1] | ||
| row_values, row_indices = [], [] | ||
| for j in range(start, end): | ||
| row_values.append(values[j]) | ||
| row_indices.append(columns[j]) | ||
| yield SparseVector(indices=row_indices, values=row_values) | ||
|
|
||
|
|
||
| def read_csr_matrix(filename: Union[Path, str]) -> Iterator[SparseVector]: | ||
| """Read a CSR matrix in spmat format""" | ||
| values, columns, index_pointer = read_sparse_matrix_fields(filename) | ||
| values = values.tolist() | ||
| columns = columns.tolist() | ||
| index_pointer = index_pointer.tolist() | ||
|
|
||
| yield from csr_to_sparse_vectors(values, columns, index_pointer) | ||
|
|
||
|
|
||
| def knn_result_read( | ||
| filename: Union[Path, str] | ||
| ) -> Tuple[List[List[int]], List[List[float]]]: | ||
| n, d = map(int, np.fromfile(filename, dtype="uint32", count=2)) | ||
| assert os.stat(filename).st_size == 8 + n * d * (4 + 4) | ||
| with open(filename, "rb") as f: | ||
| f.seek(4 + 4) | ||
| ids = np.fromfile(f, dtype="int32", count=n * d).reshape(n, d).tolist() | ||
| scores = np.fromfile(f, dtype="float32", count=n * d).reshape(n, d).tolist() | ||
| return ids, scores | ||
|
|
||
|
|
||
| class SparseReader(BaseReader): | ||
| def __init__(self, path, normalize=False): | ||
| self.path = path | ||
| self.normalize = normalize | ||
|
|
||
| def read_queries(self) -> Iterator[Query]: | ||
| queries_path = self.path / "queries.csr" | ||
| X = read_csr_matrix(queries_path) | ||
|
|
||
| gt_path = self.path / "results.gt" | ||
| gt_indices, _ = knn_result_read(gt_path) | ||
|
|
||
| for i, sparse_vector in enumerate(X): | ||
| yield Query( | ||
| vector=None, | ||
| sparse_vector=sparse_vector, | ||
| meta_conditions=None, | ||
| expected_result=gt_indices[i], | ||
| ) | ||
|
|
||
| def read_data(self) -> Iterator[Record]: | ||
| data_path = self.path / "data.csr" | ||
| X = read_csr_matrix(data_path) | ||
|
|
||
| for i, sparse_vector in enumerate(X): | ||
| yield Record(id=i, vector=None, sparse_vector=sparse_vector, metadata=None) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| vals = [1, 3, 2, 3, 6, 4, 5] | ||
| cols = [0, 2, 2, 1, 3, 0, 2] | ||
| pointers = [0, 2, 3, 5, 7] | ||
| vecs = [vec for vec in csr_to_sparse_vectors(vals, cols, pointers)] | ||
|
|
||
| assert vecs[0] == SparseVector(indices=[0, 2], values=[1, 3]) | ||
| assert vecs[1] == SparseVector(indices=[2], values=[2]) | ||
| assert vecs[2] == SparseVector(indices=[1, 3], values=[3, 6]) | ||
| assert vecs[3] == SparseVector(indices=[0, 2], values=[4, 5]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.