-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add inner hits support to semantic query #111834
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 10 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
854bc26
Added inner hits builder to semantic query
Mikep86 733cae8
Pass inner hit builder to nested query builder
Mikep86 ada0b3a
Added InnerChunkBuilder
Mikep86 a8fac5f
Update InnerChunkBuilder to not inherit from InnerHitBuilder
Mikep86 557dc9a
Hard-code name in InnerChunkBuilder
Mikep86 8e94854
Updated semantic query builder tests
Mikep86 a860e69
Added YAML tests
Mikep86 dac2bd4
Resolved TODOs
Mikep86 dd67452
Update docs/changelog/111834.yaml
Mikep86 9d5fa1d
Fixed changelog
Mikep86 639adad
Set inner chunk builder name based on field name
Mikep86 4b8a62b
Add YAML test for querying multiple semantic text fields with inner c…
Mikep86 9311cc1
Fix YAML tests
Mikep86 df127b9
Rename inner_chunks to chunks
Mikep86 202314c
Fail the semantic query request if the transport version is not compa…
Mikep86 17e8edb
YAML test updates
Mikep86 91add83
Exclude embeddings from inner hit _source output
Mikep86 ae898fd
Updated YAML tests to check that embeddings are not in inner hits _so…
Mikep86 23d3344
Updated semantic query documentation
Mikep86 43b0a7f
Fix link
Mikep86 91f21f9
Merge branch 'main' into semantic-query_inner-hits
Mikep86 a5a03d9
Docs adjustments
Mikep86 1982eda
Fix headings
Mikep86 b0244f1
Merge branch 'main' into semantic-query_inner-hits
Mikep86 a5ee5d8
Merge branch 'main' into semantic-query_inner-hits
Mikep86 e28e72f
Added cluster feature for semantic text inner hits support
Mikep86 ee95981
Merge branch 'main' into semantic-query_inner-hits
Mikep86 8c73841
Rename chunks param to inner_hits
Mikep86 b779e29
Update documentation to address feedback and rename chunks to inner_hits
Mikep86 9f42742
Added reason for skipping doc tests
Mikep86 a19fd6e
Added "Query semantic text field in object with inner hits" YAML test
Mikep86 bb95eee
Merge branch 'main' into semantic-query_inner-hits
Mikep86 f62649d
Merge branch 'main' into semantic-query_inner-hits
Mikep86 3cbd7a5
PR feedback
Mikep86 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 111834 | ||
summary: Add inner hits support to semantic query | ||
area: Search | ||
type: enhancement | ||
issues: [] |
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
119 changes: 119 additions & 0 deletions
119
.../inference/src/main/java/org/elasticsearch/xpack/inference/queries/InnerChunkBuilder.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,119 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.queries; | ||
|
||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.index.query.InnerHitBuilder; | ||
import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
import org.elasticsearch.xcontent.ObjectParser; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.index.query.InnerHitBuilder.DEFAULT_FROM; | ||
import static org.elasticsearch.index.query.InnerHitBuilder.DEFAULT_SIZE; | ||
|
||
public class InnerChunkBuilder implements Writeable, ToXContentObject { | ||
private static final ObjectParser<InnerChunkBuilder, Void> PARSER = new ObjectParser<>("inner_chunks", InnerChunkBuilder::new); | ||
|
||
static { | ||
PARSER.declareInt(InnerChunkBuilder::setFrom, SearchSourceBuilder.FROM_FIELD); | ||
PARSER.declareInt(InnerChunkBuilder::setSize, SearchSourceBuilder.SIZE_FIELD); | ||
} | ||
|
||
private final String name; | ||
private int from = DEFAULT_FROM; | ||
private int size = DEFAULT_SIZE; | ||
|
||
public InnerChunkBuilder() { | ||
// Set hard-coded name value here so that if we change it in the future, the updated value is serialized/deserialized and propagated | ||
// across nodes | ||
this.name = "chunks"; | ||
} | ||
|
||
public InnerChunkBuilder(StreamInput in) throws IOException { | ||
name = in.readString(); | ||
from = in.readVInt(); | ||
size = in.readVInt(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(name); | ||
out.writeVInt(from); | ||
out.writeVInt(size); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getFrom() { | ||
return from; | ||
} | ||
|
||
public InnerChunkBuilder setFrom(int from) { | ||
this.from = from; | ||
return this; | ||
} | ||
|
||
public int getSize() { | ||
return size; | ||
} | ||
|
||
public InnerChunkBuilder setSize(int size) { | ||
this.size = size; | ||
return this; | ||
} | ||
|
||
public InnerHitBuilder toInnerHitBuilder() { | ||
return new InnerHitBuilder(name).setFrom(from).setSize(size); | ||
Mikep86 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
// Don't include name in XContent because it is hard-coded | ||
builder.startObject(); | ||
if (from != DEFAULT_FROM) { | ||
builder.field(SearchSourceBuilder.FROM_FIELD.getPreferredName(), from); | ||
} | ||
if (size != DEFAULT_SIZE) { | ||
builder.field(SearchSourceBuilder.SIZE_FIELD.getPreferredName(), size); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public static InnerChunkBuilder fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, new InnerChunkBuilder(), null); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
InnerChunkBuilder that = (InnerChunkBuilder) o; | ||
return from == that.from && size == that.size && Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, from, size); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Strings.toString(this, true, true); | ||
} | ||
} |
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.