Skip to content

Commit 813814b

Browse files
kderussoelasticsearchmachineMikep86
authored
Add index_options to semantic_text field mappings (#119967)
* Add index_options parameter to semantic_text field mapping * Cleanup & tests * Update docs * Update docs/changelog/119967.yaml * Addressed some PR feedbak * Update yaml tests * Refactoring * Cleanup * Fix some tests * Hack in inferring text_embedding task type from index options * [CI] Auto commit changes from spotless * Fix error inferring model settings * Update docs * Update tests * Update docs/reference/mapping/types/semantic-text.asciidoc Co-authored-by: Mike Pellegrini <[email protected]> * Address some minor PR feedback * Remove partial model_settings with inferred task type * Cleanup * Remove unnecessary changes * Fix errors from merge * [CI] Auto commit changes from spotless * Cleanup * Checkpoint, saving changes before merge * Update parsing * [CI] Auto commit changes from spotless * Stash changes * Fix compile errors * [CI] Auto commit changes from spotless * Cleanup error * fix test * fix test * Fix another test * A bit of cleanup * Fix tests * Spotless * Respect index options if set over defaults * Cleanup * [CI] Auto commit changes from spotless * Support updating to compatible versions, add some cleanup and validation * Remove test that can't be done here - needs to be unit test * Add validation * Cleanup * Fix some yaml tests * [CI] Auto commit changes from spotless * Happy path early index validation works now; edge cases surrounding default BBQ remain * Always emit index options, even when using defaults * Minor cleanup * Fix test compilation failures * Fix some tests * Continue to iterate on test failures * Remove index options from inference field metadata as it is only needed at field creation time * Fix some tests * Remove transport version, no longer needed * Fix yaml tests * Add tests * IndexOptions don't need to implement Writeable * [CI] Auto commit changes from spotless * Refactor - move SemanticTextIndexOptions * Remove writeable * Move index_options parsing to semantic text field mapper * Cleanup * Fix test compilation issue * Cleanup * Remove whitespace * Remove writeables from index options * Disable merging null options? * Add docs * [CI] Auto commit changes from spotless * Revert "Disable merging null options?" This reverts commit 2ef8b1d. * Remove default serialization * Include default index option type to defaults * [CI] Auto commit changes from spotless * Go back to allowing null updateS * Cleanup * Fix validation error * Revert "Include default index option type to defaults" This reverts commit b08e2a1. * Update tests * Revert "Update tests" This reverts commit aedfafe. * Better fix for null inputs * Remove redundant merge validation --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Mike Pellegrini <[email protected]>
1 parent d0b74df commit 813814b

File tree

12 files changed

+1537
-182
lines changed

12 files changed

+1537
-182
lines changed

docs/changelog/119967.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 119967
2+
summary: Add `index_options` to `semantic_text` field mappings
3+
area: Mapping
4+
type: enhancement
5+
issues: [ ]

docs/reference/elasticsearch/mapping-reference/semantic-text.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ service.
2828

2929
Using `semantic_text`, you won’t need to specify how to generate embeddings for
3030
your data, or how to index it. The {{infer}} endpoint automatically determines
31-
the embedding generation, indexing, and query to use.
31+
the embedding generation, indexing, and query to use.
3232
Newly created indices with `semantic_text` fields using dense embeddings will be
3333
[quantized](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-quantization)
3434
to `bbq_hnsw` automatically.
@@ -111,6 +111,33 @@ the [Create {{infer}} API](https://www.elastic.co/docs/api/doc/elasticsearch/ope
111111
to create the endpoint. If not specified, the {{infer}} endpoint defined by
112112
`inference_id` will be used at both index and query time.
113113

114+
`index_options`
115+
: (Optional, string) Specifies the index options to override default values
116+
for the field. Currently, `dense_vector` index options are supported.
117+
For text embeddings, `index_options` may match any allowed
118+
[dense_vector index options](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-index-options).
119+
120+
An example of how to set index_options for a `semantic_text` field:
121+
122+
```console
123+
PUT my-index-000004
124+
{
125+
"mappings": {
126+
"properties": {
127+
"inference_field": {
128+
"type": "semantic_text",
129+
"inference_id": "my-text-embedding-endpoint",
130+
"index_options": {
131+
"dense_vector": {
132+
"type": "int4_flat"
133+
}
134+
}
135+
}
136+
}
137+
}
138+
}
139+
```
140+
114141
`chunking_settings`
115142
: (Optional, object) Settings for chunking text into smaller passages.
116143
If specified, these will override the chunking settings set in the {{infer-cap}}
@@ -138,8 +165,10 @@ To completely disable chunking, use the `none` chunking strategy.
138165
or `1`. Required for `sentence` type chunking settings
139166

140167
::::{warning}
141-
If the input exceeds the maximum token limit of the underlying model, some services (such as OpenAI) may return an
142-
error. In contrast, the `elastic` and `elasticsearch` services will automatically truncate the input to fit within the
168+
If the input exceeds the maximum token limit of the underlying model, some
169+
services (such as OpenAI) may return an
170+
error. In contrast, the `elastic` and `elasticsearch` services will
171+
automatically truncate the input to fit within the
143172
model's limit.
144173
::::
145174

@@ -173,7 +202,8 @@ For more details on chunking and how to configure chunking settings,
173202
see [Configuring chunking](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-inference)
174203
in the Inference API documentation.
175204

176-
You can pre-chunk the input by sending it to Elasticsearch as an array of strings.
205+
You can pre-chunk the input by sending it to Elasticsearch as an array of
206+
strings.
177207
Example:
178208

179209
```console
@@ -203,15 +233,20 @@ PUT test-index/_doc/1
203233
```
204234

205235
1. The text is pre-chunked and provided as an array of strings.
206-
Each element in the array represents a single chunk that will be sent directly to the inference service without further chunking.
236+
Each element in the array represents a single chunk that will be sent
237+
directly to the inference service without further chunking.
207238

208239
**Important considerations**:
209240

210-
* When providing pre-chunked input, ensure that you set the chunking strategy to `none` to avoid additional processing.
211-
* Each chunk should be sized carefully, staying within the token limit of the inference service and the underlying model.
212-
* If a chunk exceeds the model's token limit, the behavior depends on the service:
213-
* Some services (such as OpenAI) will return an error.
214-
* Others (such as `elastic` and `elasticsearch`) will automatically truncate the input.
241+
* When providing pre-chunked input, ensure that you set the chunking strategy to
242+
`none` to avoid additional processing.
243+
* Each chunk should be sized carefully, staying within the token limit of the
244+
inference service and the underlying model.
245+
* If a chunk exceeds the model's token limit, the behavior depends on the
246+
service:
247+
* Some services (such as OpenAI) will return an error.
248+
* Others (such as `elastic` and `elasticsearch`) will automatically truncate
249+
the input.
215250

216251
Refer
217252
to [this tutorial](docs-content://solutions/search/semantic-search/semantic-search-semantic-text.md)

0 commit comments

Comments
 (0)