-
Notifications
You must be signed in to change notification settings - Fork 157
Allow benchmarking larger-than-memory datasets #721
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
Open
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ logging/ | |
| ### JVM crashes | ||
| hs_err_pid* | ||
| replay_pid* | ||
| java_pid*.hprof | ||
|
|
||
| ### IntelliJ IDEA ### | ||
| .idea | ||
|
|
||
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,20 @@ | ||
| ### Allow benchmarking larger-than-memory Datasets | ||
|
|
||
| **Description** | ||
|
|
||
| This PR series allows Jvector's `BenchYAML` benchmarking system to process datasets that don't fit in physical memory by memory-mapping the dataset's index vectors. See `docs/benchmarking.md` for the full `BenchYAML` documentation. | ||
|
|
||
| Covers changes from #717, #718, #720, #721. | ||
|
|
||
| **How to enable** | ||
|
|
||
| Set the Java system property `jvector.bench.dataset.mmap.enable` to `true` while running `BenchYAML` normally. | ||
|
|
||
| Examples: | ||
| ```sh | ||
| java -cp ... -Xmx10g ... -Djvector.bench.dataset.mmap.enable=true io.github.jbellis.jvector.example.BenchYAML cohere-english-v3-10M | ||
|
|
||
| # on Linux you can use cgroups to constrain total memory available to the program | ||
| systemd-run --scope --user -p MemoryHigh=18G -p MemoryMax=20G -- \ | ||
| java -cp ... -Xmx10g ... -Djvector.bench.dataset.mmap.enable=true io.github.jbellis.jvector.example.BenchYAML cohere-english-v3-10M | ||
| ``` |
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
92 changes: 92 additions & 0 deletions
92
...ples/src/main/java/io/github/jbellis/jvector/example/benchmarks/datasets/RavvDataSet.java
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,92 @@ | ||
| /* | ||
| * Copyright DataStax, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.github.jbellis.jvector.example.benchmarks.datasets; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import io.github.jbellis.jvector.graph.RandomAccessVectorValues; | ||
| import io.github.jbellis.jvector.vector.VectorSimilarityFunction; | ||
| import io.github.jbellis.jvector.vector.types.VectorFloat; | ||
|
|
||
| public class RavvDataSet implements DataSet { | ||
| private final String name; | ||
| private final VectorSimilarityFunction similarityFunction; | ||
| private final RandomAccessVectorValues baseRavv; | ||
| private final List<VectorFloat<?>> queryVectors; | ||
| private final List<? extends List<Integer>> groundTruth; | ||
|
|
||
| public RavvDataSet( | ||
| String name, | ||
| VectorSimilarityFunction similarityFunction, | ||
| RandomAccessVectorValues baseRavv, | ||
| List<VectorFloat<?>> queryVectors, | ||
| List<? extends List<Integer>> groundTruth | ||
| ) { | ||
| if (queryVectors.isEmpty()) { | ||
| throw new IllegalArgumentException("Query vectors must not be empty"); | ||
| } | ||
| if (groundTruth.isEmpty()) { | ||
| throw new IllegalArgumentException("Ground truth vectors must not be empty"); | ||
| } | ||
|
|
||
| if (baseRavv.dimension() != queryVectors.get(0).length()) { | ||
| throw new IllegalArgumentException("Base and query vectors must have the same dimensionality"); | ||
| } | ||
| if (queryVectors.size() != groundTruth.size()) { | ||
| throw new IllegalArgumentException("Query and ground truth lists must be the same size"); | ||
| } | ||
|
|
||
| this.name = name; | ||
| this.similarityFunction = similarityFunction; | ||
| this.baseRavv = baseRavv; | ||
| this.queryVectors = queryVectors; | ||
| this.groundTruth = groundTruth; | ||
|
|
||
| System.out.format("%n%s: %d base and %d query vectors created, dimensions %d%n", | ||
| name, baseRavv.size(), queryVectors.size(), baseRavv.dimension()); | ||
| } | ||
|
|
||
| @Override | ||
| public int getDimension() { | ||
| return baseRavv.dimension(); | ||
| } | ||
|
|
||
| @Override | ||
| public RandomAccessVectorValues getBaseRavv() { | ||
| return baseRavv; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public VectorSimilarityFunction getSimilarityFunction() { | ||
| return similarityFunction; | ||
| } | ||
|
|
||
| @Override | ||
| public List<VectorFloat<?>> getQueryVectors() { | ||
| return queryVectors; | ||
| } | ||
|
|
||
| @Override | ||
| public List<? extends List<Integer>> getGroundTruth() { | ||
| return groundTruth; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just make getDataSet() return a DataSet, and have the implementation of that which is provided support RAVV? That was always the intent here.
A DataSet may implement its own loading methods by design. Some of our current implementation have historic limitations which should be removed. The way to do this would be to have a DataSet impl type which does it properly, and to remove any other surface but the RAVV style accessor.
To keep that supported, the getDataSet on DataSetInfo should remain a contract type, not any concrete type.