Skip to content

Commit 40409bf

Browse files
abdonpijpelinkszabosteveDavid Roberts
authored
[DOCS] Semantic search page (elastic#97715)
Co-authored-by: István Zoltán Szabó <[email protected]> Co-authored-by: David Roberts <[email protected]>
1 parent b4fd3c8 commit 40409bf

16 files changed

+665
-12
lines changed
914 KB
Loading

docs/reference/search/search-your-data/knn-search.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ nearest documents. If the search also includes a `query`, then aggregations are
333333
calculated on the combined set of `knn` and `query` matches.
334334

335335
[discrete]
336-
[[semantic-search]]
336+
[[knn-semantic-search]]
337337
==== Perform semantic search
338338

339339
kNN search enables you to perform semantic search by using a previously deployed

docs/reference/search/search-your-data/search-your-data.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,4 @@ include::search-shard-routing.asciidoc[]
531531
include::search-template.asciidoc[]
532532
include::sort-search-results.asciidoc[]
533533
include::knn-search.asciidoc[]
534-
include::semantic-search-elser.asciidoc[]
534+
include::semantic-search.asciidoc[]

docs/reference/search/search-your-data/semantic-search-elser.asciidoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[semantic-search-elser]]
2-
== Tutorial: semantic search with ELSER
2+
=== Tutorial: semantic search with ELSER
33
++++
44
<titleabbrev>Semantic search with ELSER</titleabbrev>
55
++++
@@ -21,7 +21,7 @@ information.
2121

2222
[discrete]
2323
[[requirements]]
24-
=== Requirements
24+
==== Requirements
2525

2626
To perform semantic search by using ELSER, you must have the NLP model deployed
2727
in your cluster. Refer to the
@@ -40,7 +40,7 @@ you must provide suitably sized nodes yourself.
4040

4141
[discrete]
4242
[[elser-mappings]]
43-
=== Create the index mapping
43+
==== Create the index mapping
4444

4545
First, the mapping of the destination index - the index that contains the tokens
4646
that the model created based on your text - must be created. The destination
@@ -82,7 +82,7 @@ To learn how to optimize space, refer to the <<save-space>> section.
8282

8383
[discrete]
8484
[[inference-ingest-pipeline]]
85-
=== Create an ingest pipeline with an inference processor
85+
==== Create an ingest pipeline with an inference processor
8686

8787
Create an <<ingest,ingest pipeline>> with an
8888
<<inference-processor,{infer} processor>> to use ELSER to infer against the data
@@ -120,7 +120,7 @@ processor.
120120

121121
[discrete]
122122
[[load-data]]
123-
=== Load data
123+
==== Load data
124124

125125
In this step, you load the data that you later use in the {infer} ingest
126126
pipeline to extract tokens from it.
@@ -140,7 +140,7 @@ can see an index named `test-data` with 182469 documents.
140140

141141
[discrete]
142142
[[reindexing-data-elser]]
143-
=== Ingest the data through the {infer} ingest pipeline
143+
==== Ingest the data through the {infer} ingest pipeline
144144

145145
Create the tokens from the text by reindexing the data throught the {infer}
146146
pipeline that uses ELSER as the inference model.
@@ -178,7 +178,7 @@ follow the progress. It may take a couple of minutes to complete the process.
178178

179179
[discrete]
180180
[[text-expansion-query]]
181-
=== Semantic search by using the `text_expansion` query
181+
==== Semantic search by using the `text_expansion` query
182182

183183
To perform semantic search, use the `text_expansion` query, and provide the
184184
query text and the ELSER model ID. The example below uses the query text "How to
@@ -251,7 +251,7 @@ To learn about optimizing your `text_expansion` query, refer to
251251

252252
[discrete]
253253
[[text-expansion-compound-query]]
254-
=== Combining semantic search with other queries
254+
==== Combining semantic search with other queries
255255

256256
You can combine `text_expansion` with other queries in a
257257
<<compound-queries,compound query>>. For example using a filter clause in a
@@ -356,7 +356,7 @@ PUT my-index
356356

357357
[discrete]
358358
[[further-reading]]
359-
=== Further reading
359+
==== Further reading
360360

361361
* {ml-docs}/ml-nlp-elser.html[How to download and deploy ELSER]
362362
* {ml-docs}/ml-nlp-limitations.html#ml-nlp-elser-v1-limit-512[ELSER v1 limitation]
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
[[semantic-search]]
2+
== Semantic search
3+
4+
Semantic search is a search method that helps you find data based on the intent
5+
and contextual meaning of a search query, instead of a match on query terms
6+
(lexical search).
7+
8+
{es} provides semantic search capabilities using {ml-docs}/ml-nlp.html[natural
9+
language processing (NLP)] and vector search. Deploying an NLP model to {es}
10+
enables it to extract text embeddings out of text. Embeddings are vectors that
11+
provide a numeric representation of a text. Pieces of content with similar
12+
meaning have similar representations.
13+
14+
[[semantic-search-diagram]]
15+
.A simplified representation of encoding textual concepts as vectors
16+
image::images/search/vector-search-oversimplification.png[A simplified representation of encoding textual concepts as vectors,align="center"]
17+
18+
At query time, {es} can use the same NLP model to convert a query into
19+
embeddings, enabling you to find documents with similar text embeddings.
20+
21+
This guide shows you how to implement semantic search with {es}, from selecting
22+
an NLP model, to writing queries.
23+
24+
[discrete]
25+
[[semantic-search-select-nlp-model]]
26+
=== Select an NLP model
27+
28+
{es} offers the usage of a
29+
{ml-docs}/ml-nlp-model-ref.html#ml-nlp-model-ref-text-embedding[wide range of NLP models],
30+
including both dense and sparse vector models. Your choice of the language model
31+
is critical for implementing semantic search successfully.
32+
33+
While it is possible to bring your own text embedding model, achieving good
34+
search results through model tuning is challenging. Selecting an appropriate
35+
model from our third-party model list is the first step. Training the model on
36+
your own data is essential to ensure better search results than using only BM25.
37+
However, the model training process requires a team of data scientists and ML
38+
experts, making it expensive and time-consuming.
39+
40+
To address this issue, Elastic provides a pre-trained representational model
41+
called {ml-docs}/ml-nlp-elser.html[Elastic Learned Sparse EncodeR (ELSER)].
42+
ELSER, currently available only for English, is an out-of-domain sparse vector
43+
model that does not require fine-tuning. This adaptability makes it suitable for
44+
various NLP use cases out of the box. Unless you have a team of ML specialists,
45+
it is highly recommended to use the ELSER model.
46+
47+
In the case of sparse vector representation, the vectors mostly consist of zero
48+
values, with only a small subset containing non-zero values. This representation
49+
is commonly used for textual data. In the case of ELSER, each document in an
50+
index and the query text itself are represented by high-dimensional sparse
51+
vectors. Each non-zero element of the vector corresponds to a term in the model
52+
vocabulary. The ELSER vocabulary contains around 30000 terms, so the sparse
53+
vectors created by ELSER contain about 30000 values, the majority of which are
54+
zero. Effectively the ELSER model is replacing the terms in the original query
55+
with other terms that have been learnt to exist in the documents that best match
56+
the original search terms in a training dataset, and weights to control how
57+
important each is.
58+
59+
60+
[discrete]
61+
[[semantic-search-deploy-nlp-model]]
62+
=== Deploy the model
63+
64+
After you decide which model you want to use for implementing semantic search,
65+
you need to deploy the model in {es}.
66+
67+
include::{es-repo-dir}/tab-widgets/semantic-search/deploy-nlp-model-widget.asciidoc[]
68+
69+
[discrete]
70+
[[semantic-search-field-mappings]]
71+
=== Map a field for the text embeddings
72+
73+
Before you start using the deployed model to generate embeddings based on your
74+
input text, you need to prepare your index mapping first. The mapping of the
75+
index depends on the type of model.
76+
77+
include::{es-repo-dir}/tab-widgets/semantic-search/field-mappings-widget.asciidoc[]
78+
79+
[discrete]
80+
[[semantic-search-generate-embeddings]]
81+
=== Generate text embeddings
82+
83+
Once you have created the mappings for the index, you can generate text
84+
embeddings from your input text. This can be done by using an
85+
<<ingest,ingest pipeline>> with an <<inference-processor,inference processor>>.
86+
The ingest pipeline processes the input data and indexes it into the destination
87+
index. At index time, the inference ingest processor uses the trained model to
88+
infer against the data ingested through the pipeline. After you created the
89+
ingest pipeline with the inference processor, you can ingest your data through
90+
it to generate the model output.
91+
92+
include::{es-repo-dir}/tab-widgets/semantic-search/generate-embeddings-widget.asciidoc[]
93+
94+
Now it is time to perform semantic search!
95+
96+
[discrete]
97+
[[semantic-search-search]]
98+
=== Search the data
99+
100+
Depending on the type of model you have deployed, you can query rank features
101+
with a text expansion query, or dense vectors with a kNN search.
102+
103+
include::{es-repo-dir}/tab-widgets/semantic-search/search-widget.asciidoc[]
104+
105+
[discrete]
106+
[[semantic-search-hybrid-search]]
107+
=== Beyond semantic search with hybrid search
108+
109+
In some situations, lexical search may perform better than semantic search. For
110+
example, when searching for single words or IDs, like product numbers.
111+
112+
Combining semantic and lexical search into one hybrid search request using
113+
<<rrf,reciprocal rank fusion>> provides the best of both worlds. Not only that,
114+
but hybrid search using reciprocal rank fusion {blog-ref}improving-information-retrieval-elastic-stack-hybrid[has been shown to perform better
115+
in general].
116+
117+
include::{es-repo-dir}/tab-widgets/semantic-search/hybrid-search-widget.asciidoc[]
118+
119+
[discrete]
120+
[[semantic-search-read-more]]
121+
=== Read more
122+
123+
* Tutorials:
124+
** <<semantic-search-elser,Semantic search with ELSER>>
125+
** {ml-docs}/ml-nlp-text-emb-vector-search-example.html[Semantic search with the msmarco-MiniLM-L-12-v3 sentence-transformer model]
126+
* Blogs:
127+
** {blog-ref}may-2023-launch-sparse-encoder-ai-model[Introducing Elastic Learned Sparse Encoder: Elastic's AI model for semantic search]
128+
** {blog-ref}lexical-ai-powered-search-elastic-vector-database[How to get the best of lexical and AI-powered search with Elastic's vector database]
129+
** Information retrieval blog series:
130+
*** {blog-ref}improving-information-retrieval-elastic-stack-search-relevance[Part 1: Steps to improve search relevance]
131+
*** {blog-ref}improving-information-retrieval-elastic-stack-benchmarking-passage-retrieval[Part 2: Benchmarking passage retrieval]
132+
*** {blog-ref}may-2023-launch-information-retrieval-elasticsearch-ai-model[Part 3: Introducing Elastic Learned Sparse Encoder, our new retrieval model]
133+
*** {blog-ref}improving-information-retrieval-elastic-stack-hybrid[Part 4: Hybrid retrieval]
134+
135+
include::semantic-search-elser.asciidoc[]

docs/reference/search/search.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=knn-query-vector]
515515
(Optional, object)
516516
A configuration object indicating how to build a query_vector before executing
517517
the request. You must provide a `query_vector_builder` or `query_vector`, but
518-
not both. Refer to <<semantic-search>> to learn more.
518+
not both. Refer to <<knn-semantic-search>> to learn more.
519519
520520
`similarity`::
521521
(Optional, float)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
++++
2+
<div class="tabs" data-tab-group="model">
3+
<div role="tablist" aria-label="model">
4+
<button role="tab"
5+
aria-selected="true"
6+
aria-controls="elser-tab-deploy-nlp-model"
7+
id="elser-deploy-nlp-model">
8+
ELSER
9+
</button>
10+
<button role="tab"
11+
aria-selected="false"
12+
aria-controls="dense-vector-tab-deploy-nlp-model"
13+
id="dense-vector-deploy-nlp-model">
14+
Dense vector models
15+
</button>
16+
</div>
17+
<div tabindex="0"
18+
role="tabpanel"
19+
id="elser-tab-deploy-nlp-model"
20+
aria-labelledby="elser-deploy-nlp-model">
21+
++++
22+
23+
include::deploy-nlp-model.asciidoc[tag=elser]
24+
25+
++++
26+
</div>
27+
<div tabindex="0"
28+
role="tabpanel"
29+
id="dense-vector-tab-deploy-nlp-model"
30+
aria-labelledby="dense-vector-deploy-nlp-model"
31+
hidden="">
32+
++++
33+
34+
include::deploy-nlp-model.asciidoc[tag=dense-vector]
35+
36+
++++
37+
</div>
38+
</div>
39+
++++
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// tag::elser[]
2+
3+
To deploy ELSER, refer to
4+
{ml-docs}/ml-nlp-elser.html#download-deploy-elser[Download and deploy ELSER].
5+
6+
// end::elser[]
7+
8+
9+
// tag::dense-vector[]
10+
11+
To deploy a third-party text embedding model, refer to
12+
{ml-docs}/ml-nlp-text-emb-vector-search-example.html#ex-te-vs-deploy[Deploy a text embedding model].
13+
14+
// end::dense-vector[]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
++++
2+
<div class="tabs" data-tab-group="model">
3+
<div role="tablist" aria-label="model">
4+
<button role="tab"
5+
aria-selected="true"
6+
aria-controls="elser-tab-field-mappings"
7+
id="elser-field-mappings">
8+
ELSER
9+
</button>
10+
<button role="tab"
11+
aria-selected="false"
12+
aria-controls="dense-vector-tab-field-mappings"
13+
id="dense-vector-field-mappings">
14+
Dense vector models
15+
</button>
16+
</div>
17+
<div tabindex="0"
18+
role="tabpanel"
19+
id="elser-tab-field-mappings"
20+
aria-labelledby="elser-field-mappings">
21+
++++
22+
23+
include::field-mappings.asciidoc[tag=elser]
24+
25+
++++
26+
</div>
27+
<div tabindex="0"
28+
role="tabpanel"
29+
id="dense-vector-tab-field-mappings"
30+
aria-labelledby="dense-vector-field-mappings"
31+
hidden="">
32+
++++
33+
34+
include::field-mappings.asciidoc[tag=dense-vector]
35+
36+
++++
37+
</div>
38+
</div>
39+
++++

0 commit comments

Comments
 (0)