-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Simplified Linear Retriever #129200
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
Simplified Linear Retriever #129200
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6da6bb2
Simplified linear retriever
Mikep86 896f9ba
Simplified retriever format feature
Mikep86 4e88234
Update docs/changelog/129200.yaml
Mikep86 cee5765
Fix changelog
Mikep86 3f7870a
Centralized logic for creating a RetrieverSource from a RetrieverBuilder
Mikep86 b891166
Copy pre-filters during linear retriever rewrite
Mikep86 fc57b61
Added filter propagation test
Mikep86 ad55a8f
Remove TODO
Mikep86 05080f9
Rename fields
Mikep86 51eeaaf
Added sparse vector query test
Mikep86 2c8085d
Added index alias test
Mikep86 773c33a
Renamed SimplifiedInnerRetrieverUtils to MultiFieldsInnerRetrieverUtils
Mikep86 6ff461d
Merge branch 'main' into simplified-linear-retriever
Mikep86 1c36d33
Renamed and moved cluster feature
Mikep86 bb2807c
Removed references to simplified query format from error messages
Mikep86 030968a
Merge branch 'main' into simplified-linear-retriever
Mikep86 5717076
Added javadocs for MultiFieldsInnerRetrieverUtils
Mikep86 caf0742
Added comment to LinearRetrieverBuilderParsingTests
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: 129200 | ||
| summary: Simplified Linear Retriever | ||
| 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
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
125 changes: 125 additions & 0 deletions
125
...t/java/org/elasticsearch/xpack/inference/queries/SemanticMultiMatchQueryBuilderTests.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,125 @@ | ||
| /* | ||
| * 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.apache.lucene.index.Term; | ||
| import org.apache.lucene.search.DisjunctionMaxQuery; | ||
| import org.apache.lucene.search.Query; | ||
| import org.apache.lucene.search.TermQuery; | ||
| import org.elasticsearch.cluster.ClusterChangedEvent; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.core.IOUtils; | ||
| import org.elasticsearch.index.mapper.MapperService; | ||
| import org.elasticsearch.index.mapper.MapperServiceTestCase; | ||
| import org.elasticsearch.index.mapper.ParsedDocument; | ||
| import org.elasticsearch.index.query.MultiMatchQueryBuilder; | ||
| import org.elasticsearch.index.query.SearchExecutionContext; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.test.ClusterServiceUtils; | ||
| import org.elasticsearch.test.client.NoOpClient; | ||
| import org.elasticsearch.threadpool.TestThreadPool; | ||
| import org.elasticsearch.xpack.inference.InferencePlugin; | ||
| import org.elasticsearch.xpack.inference.registry.ModelRegistry; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
|
|
||
| public class SemanticMultiMatchQueryBuilderTests extends MapperServiceTestCase { | ||
| private static TestThreadPool threadPool; | ||
| private static ModelRegistry modelRegistry; | ||
|
|
||
| private static class InferencePluginWithModelRegistry extends InferencePlugin { | ||
| InferencePluginWithModelRegistry(Settings settings) { | ||
| super(settings); | ||
| } | ||
|
|
||
| @Override | ||
| protected Supplier<ModelRegistry> getModelRegistry() { | ||
| return () -> modelRegistry; | ||
| } | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void startModelRegistry() { | ||
| threadPool = new TestThreadPool(SemanticMultiMatchQueryBuilderTests.class.getName()); | ||
| var clusterService = ClusterServiceUtils.createClusterService(threadPool); | ||
| modelRegistry = new ModelRegistry(clusterService, new NoOpClient(threadPool)); | ||
| modelRegistry.clusterChanged(new ClusterChangedEvent("init", clusterService.state(), clusterService.state()) { | ||
| @Override | ||
| public boolean localNodeMaster() { | ||
| return false; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void stopModelRegistry() { | ||
| IOUtils.closeWhileHandlingException(threadPool); | ||
| } | ||
|
|
||
| @Override | ||
| protected Collection<? extends Plugin> getPlugins() { | ||
| return List.of(new InferencePluginWithModelRegistry(Settings.EMPTY)); | ||
| } | ||
|
|
||
| public void testResolveSemanticTextFieldFromWildcard() throws Exception { | ||
| MapperService mapperService = createMapperService(""" | ||
| { | ||
| "_doc" : { | ||
| "properties": { | ||
| "text_field": { "type": "text" }, | ||
| "keyword_field": { "type": "keyword" }, | ||
| "inference_field": { "type": "semantic_text", "inference_id": "test_service" } | ||
| } | ||
| } | ||
| } | ||
| """); | ||
|
|
||
| ParsedDocument doc = mapperService.documentMapper().parse(source(""" | ||
| { | ||
| "text_field" : "foo", | ||
| "keyword_field" : "foo", | ||
| "inference_field" : "foo", | ||
| "_inference_fields": { | ||
| "inference_field": { | ||
| "inference": { | ||
| "inference_id": "test_service", | ||
| "model_settings": { | ||
| "task_type": "sparse_embedding" | ||
| }, | ||
| "chunks": { | ||
| "inference_field": [ | ||
| { | ||
| "start_offset": 0, | ||
| "end_offset": 3, | ||
| "embeddings": { | ||
| "foo": 1.0 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """)); | ||
|
|
||
| withLuceneIndex(mapperService, iw -> iw.addDocument(doc.rootDoc()), ir -> { | ||
| SearchExecutionContext context = createSearchExecutionContext(mapperService, newSearcher(ir)); | ||
| Query query = new MultiMatchQueryBuilder("foo", "*_field").toQuery(context); | ||
| Query expected = new DisjunctionMaxQuery( | ||
| List.of(new TermQuery(new Term("text_field", "foo")), new TermQuery(new Term("keyword_field", "foo"))), | ||
| 0f | ||
| ); | ||
| assertEquals(expected, query); | ||
| }); | ||
| } | ||
| } |
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.
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.
Does this need to be updated? Probably something like
Add simplified syntax and hybrid support to linear retriever.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.
I think this description is still succinct and accurate, good as is