semantic-search.asciidoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. [[semantic-search-api]]
  2. === Semantic search API
  3. ++++
  4. <titleabbrev>Semantic search</titleabbrev>
  5. ++++
  6. experimental::[]
  7. Semantic search uses a text embedding NLP model to generate a dense vector from the input query string.
  8. The resulting dense vector is then used in a <<knn-search,k-nearest neighbor (knn) search>> against an index containing dense vectors
  9. created with the same text embedding model. The search results are semantically similar as learned
  10. by the model.
  11. [source,console]
  12. ----
  13. GET my-index/_semantic_search
  14. {
  15. "query_string": "A picture of a snow capped mountain",
  16. "model_id": "my-text-embedding-model",
  17. "knn": {
  18. "field": "text_embedding",
  19. "k": 10,
  20. "num_candidates": 100
  21. }
  22. }
  23. ----
  24. // TEST[skip:TBD]
  25. [[semantic-search-api-request]]
  26. ==== {api-request-title}
  27. `GET <target>/_semantic_search`
  28. `POST <target>/_semantic_search`
  29. [[semantic-search-api-prereqs]]
  30. ==== {api-prereq-title}
  31. * If the {es} {security-features} are enabled, you must have the `read`
  32. <<privileges-list-indices,index privilege>> for the target data stream, index,
  33. or alias.
  34. [[semantic-search-api-desc]]
  35. ==== {api-description-title}
  36. The semantic search API uses a text embedding model to create a dense vector
  37. representation of the query string.
  38. [[semantic-search-api-path-params]]
  39. ==== {api-path-parms-title}
  40. `<target>`::
  41. (Optional, string) Comma-separated list of data streams, indices, and aliases
  42. to search. Supports wildcards (`*`). To search all data streams and indices,
  43. use `*` or `_all`.
  44. [role="child_attributes"]
  45. [[semantic-search-api-query-params]]
  46. ==== {api-query-parms-title}
  47. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=routing]
  48. [role="child_attributes"]
  49. [[semantic-search-api-request-body]]
  50. ==== {api-request-body-title}
  51. `model_id`::
  52. (Required, string)
  53. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id]
  54. `query_string`::
  55. (Required, string) The input text to embed.
  56. `knn`::
  57. (Required, object)
  58. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=knn]
  59. `query`::
  60. (Optional, <<query-dsl,query object>>) Defines the search definition using the
  61. <<query-dsl,Query DSL>>.
  62. `text_embedding_config`::
  63. (Object, optional) Override certain setting of the text embedding model's configuration
  64. .Properties of text_embedding inference
  65. [%collapsible%open]
  66. =====
  67. `results_field`::::
  68. (Optional, string)
  69. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  70. `tokenization`::::
  71. (Optional, object)
  72. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  73. +
  74. .Properties of tokenization
  75. [%collapsible%open]
  76. ======
  77. `bert`::::
  78. (Optional, object)
  79. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  80. +
  81. .Properties of bert
  82. [%collapsible%open]
  83. =======
  84. `truncate`::::
  85. (Optional, string)
  86. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  87. =======
  88. `roberta`::::
  89. (Optional, object)
  90. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  91. +
  92. .Properties of roberta
  93. [%collapsible%open]
  94. =======
  95. `truncate`::::
  96. (Optional, string)
  97. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  98. =======
  99. `mpnet`::::
  100. (Optional, object)
  101. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  102. +
  103. .Properties of mpnet
  104. [%collapsible%open]
  105. =======
  106. `truncate`::::
  107. (Optional, string)
  108. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  109. =======
  110. ======
  111. =====
  112. include::{es-repo-dir}/search/search.asciidoc[tag=docvalue-fields-def]
  113. include::{es-repo-dir}/search/search.asciidoc[tag=fields-param-def]
  114. include::{es-repo-dir}/search/search.asciidoc[tag=source-filtering-def]
  115. include::{es-repo-dir}/search/search.asciidoc[tag=stored-fields-def]
  116. [role="child_attributes"]
  117. [[semantic-search-api-response-body]]
  118. ==== {api-response-body-title}
  119. The semantic search response has the same structure as a kNN search response.