You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solutions/search/vector/dense-versus-sparse-ingest-pipelines.md
+25-27Lines changed: 25 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,31 +11,27 @@ products:
11
11
12
12
# Tutorial: Dense and sparse workflows using ingest pipelines [semantic-search-deployed-nlp-model]
13
13
14
-
15
14
::::{important}
16
-
* For the easiest way to perform semantic search in the {{stack}}, refer to the [`semantic_text`](../semantic-search/semantic-search-semantic-text.md) end-to-end tutorial.
17
-
* This tutorial was written before the [{{infer}} endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-inference) and [`semantic_text` field type](elasticsearch://reference/elasticsearch/mapping-reference/semantic-text.md) was introduced. Today we have simpler options for performing semantic search.
18
15
16
+
* For the easiest way to perform semantic search in the {{stack}}, refer to the [`semantic_text`](../semantic-search/semantic-search-semantic-text.md) end-to-end tutorial.
17
+
* This tutorial predates the [{{infer}} endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-inference) and the [`semantic_text` field type](elasticsearch://reference/elasticsearch/mapping-reference/semantic-text.md). Today there are simpler, higher-level options for semantic search than the ones outlined in this tutorial. The semantic text workflow is the recommended way to perform semantic search for most use cases.
19
18
::::
20
19
21
-
22
-
This guide shows you how to implement semantic search with models deployed in {{es}}: from selecting an NLP model, to writing queries.
23
-
20
+
**This guide shows how to implement semantic search in {{es}} with deployed NLP models: from selecting a model, to configuring ingest pipelines, to running queries.**
24
21
25
22
## Select an NLP model [deployed-select-nlp-model]
26
23
27
-
{{es}} offers the usage of a [wide range of NLP models](/explore-analyze/machine-learning/nlp/ml-nlp-model-ref.md#ml-nlp-model-ref-text-embedding), including both dense and sparse vector models. Your choice of the language model is critical for implementing semantic search successfully.
28
-
29
-
While it is possible to bring your own text embedding model, achieving good search results through model tuning is challenging. Selecting an appropriate model from our third-party model list is the first step. Training the model on your own data is essential to ensure better search results than using only BM25. However, the model training process requires a team of data scientists and ML experts, making it expensive and time-consuming.
24
+
{{es}} supports a [wide range of NLP models](/explore-analyze/machine-learning/nlp/ml-nlp-model-ref.md#ml-nlp-model-ref-text-embedding), including **dense** and **sparse** vector models. Choosing the right model is critical for good relevance.
30
25
31
-
To address this issue, Elastic provides a pre-trained representational model called [Elastic Learned Sparse EncodeR (ELSER)](/explore-analyze/machine-learning/nlp/ml-nlp-elser.md). ELSER, currently available only for English, is an out-of-domain sparse vector model that does not require fine-tuning. This adaptability makes it suitable for various NLP use cases out of the box. Unless you have a team of ML specialists, it is highly recommended to use the ELSER model.
26
+
While bringing your own text embedding model is possible, achieving strong results typically requires tuning and evaluation. Selecting a well-performing third-party model from our list is a good start. Training the model on your own data is essential to ensure better search results than using only BM25. However, the model training process requires a team of data scientists and ML experts, making it expensive and time-consuming.
32
27
33
-
In the case of sparse vector representation, the vectors mostly consist of zero values, with only a small subset containing non-zero values. This representation is commonly used for textual data. In the case of ELSER, each document in an index and the query text itself are represented by high-dimensional sparse vectors. Each non-zero element of the vector corresponds to a term in the model vocabulary. The ELSER vocabulary contains around 30000 terms, so the sparse vectors created by ELSER contain about 30000 values, the majority of which are zero. Effectively the ELSER model is replacing the terms in the original query with other terms that have been learnt to exist in the documents that best match the original search terms in a training dataset, and weights to control how important each is.
28
+
To lower the barrier, Elastic provides [**Elastic Learned Sparse EncodeR (ELSER)**](/explore-analyze/machine-learning/nlp/ml-nlp-elser.md), a pre-trained sparse vector model (English-only) that delivers strong out-of-the-box relevance without fine-tuning. This adaptability makes it suitable for various NLP use cases out of the box. Unless you have an ML team, we recommend starting with ELSER.
34
29
30
+
Sparse vectors are mostly zeros with a small number of non-zero values. This representation is commonly used for textual data. With ELSER, both documents and queries are represented as high-dimensional sparse vectors. Each non-zero element of the vector corresponds to a term in the model vocabulary. The ELSER vocabulary contains around 30000 terms, so the sparse vectors created by ELSER contain about 30000 values, the majority of which are zero. The ELSER model replaces the terms in the original query with other terms learned from the training dataset that appear in documents matching the original search terms, and assigns weights to control their importance.
35
31
36
-
## Deploy the model [deployed-deploy-nlp-model]
32
+
## Deploy the model in {{es}} [deployed-deploy-nlp-model]
37
33
38
-
After you decide which model you want to use for implementing semantic search, you need to deploy the model in {{es}}.
34
+
After you choose a model, deploy it in {{es}}.
39
35
40
36
:::::::{tab-set}
41
37
@@ -51,14 +47,15 @@ To deploy a third-party text embedding model, refer to [Deploy a text embedding
51
47
52
48
## Map a field for the text embeddings [deployed-field-mappings]
53
49
54
-
Before you start using the deployed model to generate embeddings based on your input text, you need to prepare your index mapping first. The mapping of the index depends on the type of model.
50
+
Before generating embeddings, prepare your **index mapping**. The mapping depends on whether you use a **sparse** (ELSER) or **dense** model.
55
51
56
52
:::::::{tab-set}
57
53
58
54
::::::{tab-item} ELSER
59
-
ELSER produces token-weight pairs as output from the input text and the query. The {{es}} [`sparse_vector`](elasticsearch://reference/elasticsearch/mapping-reference/sparse-vector.md) field type can store these token-weight pairs as numeric feature vectors. The index must have a field with the `sparse_vector` field type to index the tokens that ELSER generates.
55
+
ELSER outputs token-weight pairs. Use the [`sparse_vector`](elasticsearch://reference/elasticsearch/mapping-reference/sparse-vector.md) field to store them.
60
56
61
-
To create a mapping for your ELSER index, refer to the [Create the index mapping section](../semantic-search/semantic-search-elser-ingest-pipelines.md#elser-mappings) of the tutorial. The example shows how to create an index mapping for `my-index` that defines the `my_embeddings.tokens` field - which will contain the ELSER output - as a `sparse_vector` field.
57
+
To create a mapping for your ELSER index, refer to the [Create the index mapping section](../semantic-search/semantic-search-elser-ingest-pipelines.md#elser-mappings) of the tutorial.
58
+
Create a mapping with a `sparse_vector` field for the tokens and a `text` field for the source content. For example:
62
59
63
60
```console
64
61
PUT my-index
@@ -76,16 +73,16 @@ PUT my-index
76
73
}
77
74
```
78
75
79
-
1. The name of the field that will contain the tokens generated by ELSER.
76
+
1. The field that will contain ELSER-generated tokens.
80
77
2. The field that contains the tokens must be a `sparse_vector` field.
81
-
3. The name of the field from which to create the sparse vector representation. In this example, the name of the field is `my_text_field`.
78
+
3. The source field used to create the sparse vector representation. In this example, the name of the field is `my_text_field`.
82
79
4. The field type is `text` in this example.
83
80
::::::
84
81
85
82
::::::{tab-item} Dense vector models
86
-
The models compatible with {{es}} NLP generate dense vectors as output. The [`dense_vector`](elasticsearch://reference/elasticsearch/mapping-reference/dense-vector.md) field type is suitable for storing dense vectors of numeric values. The index must have a field with the `dense_vector` field type to index the embeddings that the supported third-party model that you selected generates. Keep in mind that the model produces embeddings with a certain number of dimensions. The `dense_vector` field must be configured with the same number of dimensions using the `dims` option. Refer to the respective model documentation to get information about the number of dimensions of the embeddings.
83
+
Dense vector models output numeric embeddings. Use the [`dense_vector`](elasticsearch://reference/elasticsearch/mapping-reference/dense-vector.md) field type for storing dense vectors that the supported third-party model you selected generates. Keep in mind that the model produces embeddings with a certain number of dimensions. The `dense_vector` field must be configured with the same number of dimensions using the `dims` option. Refer to the respective model documentation to get information about the number of dimensions of the embeddings.
87
84
88
-
To review a mapping of an index for an NLP model, refer to the mapping code snippet in the [Add the text embedding model to an ingest inference pipeline](/explore-analyze/machine-learning/nlp/ml-nlp-text-emb-vector-search-example.md#ex-text-emb-ingest) section of the tutorial. The example shows how to create an index mapping that defines the `my_embeddings.predicted_value` field - which will contain the model output - as a `dense_vector` field.
85
+
To review a mapping of an index for an NLP model, refer to the mapping code snippet in the [Add the text embedding model to an ingest inference pipeline](/explore-analyze/machine-learning/nlp/ml-nlp-text-emb-vector-search-example.md#ex-text-emb-ingest) section of the related tutorial. The example shows how to create an index mapping that defines the `my_embeddings.predicted_value` field - which will contain the model output - as a `dense_vector` field.
89
86
90
87
```console
91
88
PUT my-index
@@ -107,15 +104,15 @@ PUT my-index
107
104
1. The name of the field that will contain the embeddings generated by the model.
108
105
2. The field that contains the embeddings must be a `dense_vector` field.
109
106
3. The model produces embeddings with a certain number of dimensions. The `dense_vector` field must be configured with the same number of dimensions by the `dims` option. Refer to the respective model documentation to get information about the number of dimensions of the embeddings.
110
-
4. The name of the field from which to create the dense vector representation. In this example, the name of the field is `my_text_field`.
107
+
4. The source field used to create the dense vector representation. In this example, the name of the field is `my_text_field`.
111
108
5. The field type is `text` in this example.
112
109
::::::
113
110
114
111
:::::::
115
112
116
113
## Generate text embeddings [deployed-generate-embeddings]
117
114
118
-
Once you have created the mappings for the index, you can generate text embeddings from your input text. This can be done by using an [ingest pipeline](../../../manage-data/ingest/transform-enrich/ingest-pipelines.md) with an [inference processor](elasticsearch://reference/enrich-processor/inference-processor.md). The ingest pipeline processes the input data and indexes it into the destination index. At index time, the inference ingest processor uses the trained model to infer against the data ingested through the pipeline. After you created the ingest pipeline with the inference processor, you can ingest your data through it to generate the model output.
115
+
Use an [ingest pipeline](../../../manage-data/ingest/transform-enrich/ingest-pipelines.md) with an [inference processor](elasticsearch://reference/enrich-processor/inference-processor.md) to generate embeddings at ingest time. The ingest pipeline processes the input data and indexes it into the destination index. At index time, the inference ingest processor uses the trained model to infer against the data ingested through the pipeline. After you created the ingest pipeline with the inference processor, you can ingest your data through it to generate the model output.
119
116
120
117
:::::::{tab-set}
121
118
@@ -144,12 +141,11 @@ PUT _ingest/pipeline/my-text-embeddings-pipeline
144
141
145
142
1. Configuration object that defines the `input_field` for the {{infer}} process and the `output_field` that will contain the {{infer}} results.
146
143
147
-
148
144
To ingest data through the pipeline to generate tokens with ELSER, refer to the [Ingest the data through the {{infer}} ingest pipeline](/solutions/search/semantic-search/semantic-search-elser-ingest-pipelines.md#reindexing-data-elser) section of the tutorial. After you successfully ingested documents by using the pipeline, your index will contain the tokens generated by ELSER. Tokens are learned associations capturing relevance, they are not synonyms. To learn more about what tokens are, refer to [this page](/explore-analyze/machine-learning/nlp/ml-nlp-elser.md#elser-tokens).
149
145
::::::
150
146
151
147
::::::{tab-item} Dense vector models
152
-
This is how an ingest pipeline that uses a text embedding model is created:
148
+
Example ingest pipeline using a text embedding model:
153
149
154
150
```console
155
151
PUT _ingest/pipeline/my-text-embeddings-pipeline
@@ -172,15 +168,13 @@ PUT _ingest/pipeline/my-text-embeddings-pipeline
172
168
1. The model ID of the text embedding model you want to use.
173
169
2. The `field_map` object maps the input document field name (which is `my_text_field` in this example) to the name of the field that the model expects (which is always `text_field`).
174
170
175
-
176
171
To ingest data through the pipeline to generate text embeddings with your chosen model, refer to the [Add the text embedding model to an inference ingest pipeline](/explore-analyze/machine-learning/nlp/ml-nlp-text-emb-vector-search-example.md#ex-text-emb-ingest) section. The example shows how to create the pipeline with the inference processor and reindex your data through the pipeline. After you successfully ingested documents by using the pipeline, your index will contain the text embeddings generated by the model.
177
172
::::::
178
173
179
174
:::::::
180
175
Now it is time to perform semantic search!
181
176
182
-
183
-
## Search the data [deployed-search]
177
+
## Search the data with vector search [deployed-search]
184
178
185
179
Depending on the type of model you have deployed, you can query rank features with a [sparse vector](elasticsearch://reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md) query, or dense vectors with a kNN search.
Copy file name to clipboardExpand all lines: solutions/search/vector/sparse-vector.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,29 +3,29 @@ applies_to:
3
3
stack:
4
4
serverless:
5
5
---
6
-
# Sparse vector [sparse-vector-foo]
6
+
# Sparse vector search in {{es}} [sparse-vector-search]
7
7
8
-
When working with sparse vectors in {{es}}, you'll be using the Elastic learned sparse encoder (ELSER) model at index and query time to expand content with semantically related terms.
8
+
When working with sparse vectors in {{es}}, you'll use the [**Elastic Learned Sparse Encoder (ELSER)**](/explore-analyze/machine-learning/nlp/ml-nlp-elser.md)at index and query time to expand content into semantically related, weighted terms.
9
9
10
10
This approach preserves explainability while adding semantic understanding, with each document or query expanded into a set of weighted terms.
11
11
12
12
Sparse vector search with ELSER is ideal for:
13
13
14
-
- Enhanced keyword search
15
-
-Cases requiring explainable results
14
+
- Enhanced keyword search with semantic expansion
15
+
-Use cases requiring explainable results
16
16
- Domain-specific search
17
17
- Large-scale deployments
18
18
19
-
## Working with sparse vectors in Elasticsearch
19
+
## Working with sparse vectors in {{es}}
20
20
21
21
:::{tip}
22
22
Using the `semantic_text` field type provides automatic model management and sensible defaults. [Learn more](../semantic-search/semantic-search-semantic-text.md).
23
23
:::
24
24
25
25
Sparse vector search with ELSER expands both documents and queries into weighted terms. To use sparse vectors in {{es}}:
26
26
27
-
1. Index documents with ELSER
27
+
1.**Index documents with ELSER**
28
28
- Deploy and configure the ELSER model
29
29
- Use the `sparse_vector` field type
30
30
- See [this overview](../semantic-search.md#using-nlp-models) for implementation options
31
-
2. Query the index using [`sparse_vector` query](elasticsearch://reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md).
31
+
2.**Query the index** using the[`sparse_vector` query](elasticsearch://reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md).
0 commit comments