generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 169
Adding serializer and api implementation for segment profiler state #2687
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
Closed
oaganesh
wants to merge
8
commits into
opensearch-project:feature/vector-profile
from
oaganesh:main-compression-segment-serializer
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33ad02f
Updating serializer, compression, and api.
oaganesh 5cce54e
Updating changelog and formatting.
oaganesh b4a80e1
Updating aggregation and serializer for api implementation.
oaganesh 5b2fbda
Updating aggregation and refactoring constructors.
oaganesh 40375eb
Merge branch 'feature/vector-profile' into main-compression-segment-s…
oaganesh 4a6d45b
Adding unit and integration tests for shard aggregation.
oaganesh 6464751
Updating testing configuration.
oaganesh 3f9bc09
Refactoring tests and serialization for API.
oaganesh 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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/org/opensearch/knn/index/query/SegmentProfilerUtil.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,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.query; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.lucene.index.LeafReader; | ||
import org.opensearch.knn.profiler.SegmentProfileKNNCollector; | ||
import org.opensearch.knn.profiler.SegmentProfilerState; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Utility class to get segment profiler state for a given field | ||
*/ | ||
@UtilityClass | ||
public class SegmentProfilerUtil { | ||
|
||
/** | ||
* Gets the segment profile state for a given field | ||
* @param leafReader The leaf reader to query | ||
* @param fieldName The field name to profile | ||
* @return The segment profiler state | ||
* @throws IOException If there's an error reading the segment | ||
*/ | ||
public static SegmentProfilerState getSegmentProfileState(final LeafReader leafReader, String fieldName) throws IOException { | ||
final SegmentProfileKNNCollector tempCollector = new SegmentProfileKNNCollector(); | ||
leafReader.searchNearestVectors(fieldName, new float[0], tempCollector, null); | ||
if (tempCollector.getSegmentProfilerState() == null) { | ||
throw new IllegalStateException(String.format(Locale.ROOT, "No segment state found for field %s", fieldName)); | ||
} | ||
return tempCollector.getSegmentProfilerState(); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/org/opensearch/knn/plugin/transport/KNNIndexShardProfileResult.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,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.plugin.transport; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.knn.profiler.SegmentProfilerState; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
public class KNNIndexShardProfileResult implements Writeable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need deserialization logic with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be useful especially when compressing vectors. |
||
List<SegmentProfilerState> segmentProfilerStateList; | ||
String shardId; | ||
|
||
/** | ||
* Constructor to deserialize from StreamInput | ||
* | ||
* @param in StreamInput to read from | ||
* @throws IOException if there's an error reading from the stream | ||
*/ | ||
public KNNIndexShardProfileResult(StreamInput in) throws IOException { | ||
this.shardId = in.readString(); | ||
|
||
// Read the number of SegmentProfilerStates | ||
int size = in.readInt(); | ||
this.segmentProfilerStateList = new ArrayList<>(size); | ||
|
||
// Read each SegmentProfilerState | ||
for (int i = 0; i < size; i++) { | ||
byte[] stateBytes = in.readByteArray(); | ||
this.segmentProfilerStateList.add(SegmentProfilerState.fromBytes(stateBytes)); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
streamOutput.writeString(shardId); | ||
|
||
// Write the segment profiler state list size | ||
streamOutput.writeInt(segmentProfilerStateList.size()); | ||
|
||
// Write each SegmentProfilerState as bytes | ||
for (SegmentProfilerState state : segmentProfilerStateList) { | ||
byte[] stateBytes = state.toByteArray(); | ||
streamOutput.writeByteArray(stateBytes); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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 are we adding these changes? Weren't they already merged?
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.
Yes, updated branch to adjust with changes already implemented in feature branch