-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support $vectorSearch against nested embeddings and arrays of embeddings #2026
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
rozza
wants to merge
9
commits into
mongodb:main
Choose a base branch
from
rozza:JAVA-5987
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d273191
JAVA-5987: support $vectorSearch against nested embeddings and arrays…
rozza a6b4bfe
Remove stale @Beta from Scala VectorSearchOptions aliases
rozza 910415b
Document Scala wrapper mirroring convention in driver-scala AGENTS.md
rozza d70ab35
Remove stale @Beta annotation in search options
rozza 60190f5
Reuse a single Reflections instance in search mirror test
rozza 9756cb0
Test last-write-wins for parentFilter and nestedOptions
rozza 31784da
Merge BinaryVectorSearchOptionsTest into VectorSearchOptionsTest
rozza b87b717
Merge branch 'main' into JAVA-5987
rozza 2bbe312
Merge branch 'main' into JAVA-5987
rozza 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
Some comments aren't visible on the classic Files Changed page.
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
56 changes: 56 additions & 0 deletions
56
...er-core/src/main/com/mongodb/client/model/search/VectorSearchNestedConstructibleBson.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 2008-present MongoDB, 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 com.mongodb.client.model.search; | ||
|
|
||
| import com.mongodb.annotations.Immutable; | ||
| import com.mongodb.internal.client.model.AbstractConstructibleBson; | ||
| import org.bson.BsonDocument; | ||
| import org.bson.Document; | ||
| import org.bson.conversions.Bson; | ||
|
|
||
| import static com.mongodb.assertions.Assertions.notNull; | ||
|
|
||
| final class VectorSearchNestedConstructibleBson extends AbstractConstructibleBson<VectorSearchNestedConstructibleBson> | ||
| implements VectorSearchNestedOptions { | ||
| /** | ||
| * An {@linkplain Immutable immutable} {@link BsonDocument#isEmpty() empty} instance. | ||
| */ | ||
| static final VectorSearchNestedConstructibleBson EMPTY_IMMUTABLE = | ||
| new VectorSearchNestedConstructibleBson(AbstractConstructibleBson.EMPTY_IMMUTABLE); | ||
|
|
||
| VectorSearchNestedConstructibleBson(final Bson base) { | ||
| super(base); | ||
| } | ||
|
|
||
| private VectorSearchNestedConstructibleBson(final Bson base, final Document appended) { | ||
| super(base, appended); | ||
| } | ||
|
|
||
| @Override | ||
| protected VectorSearchNestedConstructibleBson newSelf(final Bson base, final Document appended) { | ||
| return new VectorSearchNestedConstructibleBson(base, appended); | ||
| } | ||
|
|
||
| @Override | ||
| public VectorSearchNestedOptions scoreMode(final VectorSearchScoreMode scoreMode) { | ||
| return newAppended("scoreMode", notNull("scoreMode", scoreMode).getValue()); | ||
| } | ||
|
|
||
| @Override | ||
| public VectorSearchNestedOptions option(final String name, final Object value) { | ||
| return newAppended(notNull("name", name), notNull("value", value)); | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
driver-core/src/main/com/mongodb/client/model/search/VectorSearchNestedOptions.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,69 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, 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 com.mongodb.client.model.search; | ||
|
|
||
| import com.mongodb.annotations.Sealed; | ||
| import org.bson.conversions.Bson; | ||
|
|
||
| /** | ||
| * Represents the optional {@code nestedOptions} sub-document of the {@code $vectorSearch} pipeline stage, | ||
| * used when searching against arrays of embeddings within nested (embedded) documents. | ||
| * | ||
| * @see VectorSearchOptions#nestedOptions(VectorSearchNestedOptions) | ||
| * @mongodb.atlas.manual atlas-vector-search/vector-search-stage/ $vectorSearch | ||
| * @mongodb.server.release 8.3 | ||
| * @since 5.10 | ||
| */ | ||
| @Sealed | ||
| public interface VectorSearchNestedOptions extends Bson { | ||
| /** | ||
| * Creates a new {@link VectorSearchNestedOptions} with the score aggregation mode specified. | ||
| * | ||
| * @param scoreMode The score aggregation mode for the matching embeddings within a document. | ||
| * @return A new {@link VectorSearchNestedOptions}. | ||
| */ | ||
| VectorSearchNestedOptions scoreMode(VectorSearchScoreMode scoreMode); | ||
|
|
||
| /** | ||
| * Creates a new {@link VectorSearchNestedOptions} with the specified option in situations when there is no | ||
| * builder method that better satisfies your needs. | ||
| * This method cannot be used to validate the syntax. | ||
| * <p> | ||
| * <i>Example</i><br> | ||
| * The following code creates two functionally equivalent {@link VectorSearchNestedOptions} objects, | ||
| * though they may not be {@linkplain Object#equals(Object) equal}. | ||
| * <pre>{@code | ||
| * VectorSearchNestedOptions options1 = VectorSearchNestedOptions.vectorSearchNestedOptions() | ||
| * .scoreMode(VectorSearchScoreMode.AVG); | ||
| * VectorSearchNestedOptions options2 = VectorSearchNestedOptions.vectorSearchNestedOptions() | ||
| * .option("scoreMode", "avg"); | ||
| * }</pre> | ||
| * | ||
| * @param name The option name. | ||
| * @param value The option value. | ||
| * @return A new {@link VectorSearchNestedOptions}. | ||
| */ | ||
| VectorSearchNestedOptions option(String name, Object value); | ||
|
|
||
| /** | ||
| * Returns {@link VectorSearchNestedOptions} that represents server defaults. | ||
| * | ||
| * @return {@link VectorSearchNestedOptions} that represents server defaults. | ||
| */ | ||
| static VectorSearchNestedOptions vectorSearchNestedOptions() { | ||
| return VectorSearchNestedConstructibleBson.EMPTY_IMMUTABLE; | ||
| } | ||
| } |
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
54 changes: 54 additions & 0 deletions
54
driver-core/src/main/com/mongodb/client/model/search/VectorSearchScoreMode.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,54 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, 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 com.mongodb.client.model.search; | ||
|
|
||
| /** | ||
| * The score aggregation mode for a {@code $vectorSearch} against arrays of embeddings in nested (embedded) documents. | ||
| * | ||
| * <p>If {@code scoreMode} is not specified, the server default is {@link #MAX} ({@code "max"}).</p> | ||
| * | ||
| * @see VectorSearchNestedOptions#scoreMode(VectorSearchScoreMode) | ||
| * @mongodb.atlas.manual atlas-vector-search/vector-search-stage/ $vectorSearch | ||
| * @mongodb.server.release 8.3 | ||
| * @since 5.10 | ||
| */ | ||
| public enum VectorSearchScoreMode { | ||
| /** | ||
| * Use the average of the scores of the matching embeddings within a document. | ||
| */ | ||
| AVG("avg"), | ||
|
|
||
| /** | ||
| * Use the maximum of the scores of the matching embeddings within a document. | ||
| */ | ||
| MAX("max"); | ||
|
|
||
| private final String value; | ||
|
|
||
| VectorSearchScoreMode(final String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the value used by the server for this score mode. | ||
| * | ||
| * @return the server value ({@code "avg"} or {@code "max"}). | ||
| * @since 5.10 | ||
| */ | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
| } |
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.
Note the whole SearchOptions file is annotated
@Beta(Reason.CLIENT)