|
| 1 | +--- |
| 2 | +navigation_title: "Reference" |
| 3 | +mapped_pages: |
| 4 | + - https://www.elastic.co/guide/en/elasticsearch/reference/current/semantic-text.html |
| 5 | +applies_to: |
| 6 | + stack: ga 9.0 |
| 7 | + serverless: ga |
| 8 | +--- |
| 9 | + |
| 10 | +# Semantic text field type reference [semantic-text] |
| 11 | + |
| 12 | +This page provides reference content for the `semantic_text` field type, including parameter descriptions, {{infer}} endpoint configuration options, chunking behavior, update operations, querying options, and limitations. |
| 13 | + |
| 14 | +## Parameters for `semantic_text` [semantic-text-params] |
| 15 | + |
| 16 | +The `semantic_text` field type uses default indexing settings based on the [{{infer}} endpoint](#configuring-inference-endpoints) specified, enabling you to get started without providing additional configuration details. You can override these defaults by customizing the parameters described below. |
| 17 | + |
| 18 | +`inference_id` |
| 19 | +: (Optional, string) {{infer-cap}} endpoint that will be used to generate |
| 20 | +embeddings for the field. If `search_inference_id` is specified, the {{infer}} |
| 21 | +endpoint will only be used at index time. Learn more about [configuring this parameter](#configuring-inference-endpoints). |
| 22 | + |
| 23 | +**Updating the `inference_id` parameter** |
| 24 | + |
| 25 | +::::{applies-switch} |
| 26 | + |
| 27 | +:::{applies-item} { "stack": "ga 9.0" } |
| 28 | +This parameter cannot be updated. |
| 29 | +::: |
| 30 | + |
| 31 | +:::{applies-item} { "stack": "ga 9.3" } |
| 32 | + |
| 33 | +You can update this parameter by using |
| 34 | +the [Update mapping API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-mapping). |
| 35 | +You can update the {{infer}} endpoint if no values have been indexed or if the new endpoint is compatible with the current one. |
| 36 | + |
| 37 | +::::{important} |
| 38 | +When updating an `inference_id` it is important to ensure the new {{infer}} endpoint produces embeddings compatible with those already indexed. This typically means using the same underlying model. |
| 39 | +:::: |
| 40 | + |
| 41 | +::: |
| 42 | + |
| 43 | +:::: |
| 44 | + |
| 45 | +`search_inference_id` |
| 46 | +: (Optional, string) The {{infer}} endpoint that will be used to generate |
| 47 | +embeddings at query time. Use the [Create {{infer}} API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) to create the endpoint. If not specified, the {{infer}} endpoint defined by |
| 48 | +`inference_id` will be used at both index and query time. |
| 49 | + |
| 50 | + You can update this parameter by using |
| 51 | +the [Update mapping API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-mapping). |
| 52 | + |
| 53 | + Learn how to [use dedicated endpoints for ingestion and search](./semantic-text-setup-configuration.md#dedicated-endpoints-for-ingestion-and-search). |
| 54 | + |
| 55 | +`index_options` {applies_to}`stack: ga 9.1` |
| 56 | +: (Optional, object) Specifies the index options to override default values |
| 57 | +for the field. Currently, `dense_vector` and `sparse_vector` index options are supported. For text embeddings, `index_options` may match any allowed. |
| 58 | + |
| 59 | +- [dense_vector index options](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-index-options) |
| 60 | + |
| 61 | +- [sparse_vector index options](/reference/elasticsearch/mapping-reference/sparse-vector.md#sparse-vectors-params) {applies_to}`stack: ga 9.2` |
| 62 | + |
| 63 | +`chunking_settings` {applies_to}`stack: ga 9.1` |
| 64 | +: (Optional, object) Settings for chunking text into smaller passages. |
| 65 | +If specified, these will override the chunking settings set in the {{infer-cap}} |
| 66 | +endpoint associated with `inference_id`. |
| 67 | + |
| 68 | + If chunking settings are updated, they will not be applied to existing documents |
| 69 | +until they are reindexed. Defaults to the optimal chunking settings for [Elastic Rerank](docs-content://explore-analyze/machine-learning/nlp/ml-nlp-rerank.md). |
| 70 | + |
| 71 | + To completely disable chunking, use the `none` chunking strategy. |
| 72 | + |
| 73 | + ::::{important} |
| 74 | + When using the `none` chunking strategy, if the input exceeds the maximum token limit of the underlying model, |
| 75 | + some services (such as OpenAI) may return an error. In contrast, the `elastic` and `elasticsearch` services will |
| 76 | + automatically truncate the input to fit within the model's limit. |
| 77 | + :::: |
| 78 | + |
| 79 | +### Customizing semantic_text indexing |
| 80 | + |
| 81 | +The following example shows how to configure `inference_id`, `index_options` and `chunking_settings` for a `semantic_text` field type: |
| 82 | + |
| 83 | +```console |
| 84 | +PUT my-index-000004 |
| 85 | +{ |
| 86 | + "mappings": { |
| 87 | + "properties": { |
| 88 | + "inference_field": { |
| 89 | + "type": "semantic_text", |
| 90 | + "inference_id": "my-text-embedding-endpoint", <1> |
| 91 | + "index_options": { <2> |
| 92 | + "dense_vector": { |
| 93 | + "type": "int4_flat" |
| 94 | + } |
| 95 | + }, |
| 96 | + "chunking_settings": { <3> |
| 97 | + "type": "none" |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | +} |
| 103 | +``` |
| 104 | +% TEST[skip:Requires {{infer}} endpoint] |
| 105 | + |
| 106 | +1. The `inference_id` of the {{infer}} endpoint to use for generating embeddings. |
| 107 | +2. Overrides default index options by specifying `int4_flat` quantization for dense vector embeddings. |
| 108 | +3. Disables automatic chunking by setting the chunking strategy to `none`. |
| 109 | + |
| 110 | +::::{note} |
| 111 | +{applies_to}`stack: ga 9.1` Newly created indices with `semantic_text` fields using dense embeddings will be |
| 112 | +[quantized](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-quantization) |
| 113 | +to `bbq_hnsw` automatically as long as they have a minimum of 64 dimensions. |
| 114 | +:::: |
| 115 | + |
| 116 | +## {{infer-cap}} endpoints [configuring-inference-endpoints] |
| 117 | + |
| 118 | +The `semantic_text` field type specifies an {{infer}} endpoint identifier (`inference_id`) that is used to generate embeddings. |
| 119 | + |
| 120 | +The following {{infer}} endpoint configurations are available: |
| 121 | + |
| 122 | +- [Default and preconfigured endpoints](./semantic-text-setup-configuration.md#default-and-preconfigured-endpoints): Use `semantic_text` without creating an {{infer}} endpoint manually. |
| 123 | + |
| 124 | +- [ELSER on EIS](./semantic-text-setup-configuration.md#using-elser-on-eis): Use the ELSER model through the Elastic {{infer-cap}} Service. |
| 125 | + |
| 126 | +- [Custom endpoints](./semantic-text-setup-configuration.md#using-custom-endpoint): Create your own {{infer}} endpoint using the [Create {{infer}} API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) to use custom models or third-party services. |
| 127 | + |
| 128 | +If you use a [custom {{infer}} endpoint](./semantic-text-setup-configuration.md#using-custom-endpoint) through your ML node and not through Elastic {{infer-cap}} Service (EIS), the recommended method is to [use dedicated endpoints for ingestion and search](./semantic-text-setup-configuration.md#dedicated-endpoints-for-ingestion-and-search). |
| 129 | + |
| 130 | +{applies_to}`stack: ga 9.1.0` If you use EIS, you don't have to set up dedicated endpoints. |
| 131 | + |
| 132 | +::::{warning} |
| 133 | +Removing an {{infer}} endpoint will cause ingestion of documents and semantic |
| 134 | +queries to fail on indices that define `semantic_text` fields with that |
| 135 | +{{infer}} endpoint as their `inference_id`. Trying |
| 136 | +to [delete an {{infer}} endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-delete) |
| 137 | +that is used on a `semantic_text` field will result in an error. |
| 138 | +:::: |
| 139 | + |
| 140 | +## Chunking [chunking-behavior] |
| 141 | + |
| 142 | +{{infer-cap}} endpoints have a limit on the amount of text they can process. To |
| 143 | +allow for large amounts of text to be used in semantic search, `semantic_text` |
| 144 | +automatically generates smaller passages if needed, called chunks. |
| 145 | + |
| 146 | +Each chunk refers to a passage of the text and the corresponding embedding |
| 147 | +generated from it. When querying, the individual passages will be automatically |
| 148 | +searched for each document, and the most relevant passage will be used to |
| 149 | +compute a score. |
| 150 | + |
| 151 | +Chunks are stored as start and end character offsets rather than as separate |
| 152 | +text strings. These offsets point to the exact location of each chunk within the |
| 153 | +original input text. |
| 154 | + |
| 155 | +You can [pre-chunk content](./semantic-text-ingestions.md#pre-chunking) by providing text as arrays before indexing. |
| 156 | + |
| 157 | +Refer to the [{{infer-cap}} API documentation](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put#operation-inference-put-body-application-json-chunking_settings) for values for `chunking_settings` and to [Configuring chunking](docs-content://explore-analyze/elastic-inference/inference-api.md#infer-chunking-config) to learn about different chunking strategies. |
| 158 | + |
| 159 | + |
| 160 | +## Limitations [limitations] |
| 161 | + |
| 162 | +`semantic_text` field types have the following limitations: |
| 163 | + |
| 164 | +* `semantic_text` fields are not currently supported as elements |
| 165 | + of [nested fields](/reference/elasticsearch/mapping-reference/nested.md). |
| 166 | +* `semantic_text` fields can't currently be set as part |
| 167 | + of [dynamic templates](docs-content://manage-data/data-store/mapping/dynamic-templates.md). |
| 168 | +* `semantic_text` fields are not supported in indices created prior to 8.11.0. |
| 169 | +* `semantic_text` fields do not support [Cross-Cluster Search (CCS)](docs-content://solutions/search/cross-cluster-search.md) when [`ccs_minimize_roundtrips`](docs-content://solutions/search/cross-cluster-search.md#ccs-network-delays) is set to `false`. |
| 170 | +* `semantic_text` fields do not support [Cross-Cluster Search (CCS)](docs-content://solutions/search/cross-cluster-search.md) in [ES|QL](/reference/query-languages/esql.md). |
| 171 | +* `semantic_text` fields do not support [Cross-Cluster Replication (CCR)](docs-content://deploy-manage/tools/cross-cluster-replication.md). |
| 172 | + |
| 173 | + |
| 174 | +## Document count discrepancy in `_cat/indices` [document-count-discrepancy] |
| 175 | + |
| 176 | +When an index contains a `semantic_text` field, the `docs.count` value returned by the [`_cat/indices`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cat-indices) API may be higher than the number of documents you indexed. |
| 177 | +This occurs because `semantic_text` stores embeddings in [nested documents](/reference/elasticsearch/mapping-reference/nested.md), one per chunk. The `_cat/indices` API counts all documents in the Lucene index, including these hidden nested documents. |
| 178 | + |
| 179 | +To count only top-level documents, excluding the nested documents that store embeddings, use one of the following APIs: |
| 180 | + |
| 181 | +* `GET /<index>/_count` |
| 182 | +* `GET _cat/count/<index>` |
0 commit comments