Vector search

OpenSearch vector search provides a complete vector database solution for building efficient AI applications. Store and search vector embeddings alongside your existing data, making it easy to implement semantic search, retrieval-augmented generation (RAG), recommendation systems, and other AI-powered applications.

Overview

Watch this video to learn about key vector search features in OpenSearch and discover how to use OpenSearch as a vector database through a step-by-step demo.

To follow the demo, use these steps.

Steps

Prerequisites

Download the sample data for this demo:

  1. wget https://amazon-pqa.s3.amazonaws.com/amazon_pqa_headsets.json

copy

Prepare data for bulk indexing into OpenSearch:

  1. head -n 5000 amazon_pqa_headsets.json | awk '{ print "{\"index\":{\"_index\":\"neural_search_pqa\"}}"; print;}' > neural_search_amazon_pqa_headsets.json

copy

Enable running machine learning (ML) models on data nodes (not recommended for production environments):

  1. PUT /_cluster/settings
  2. {
  3. "persistent": {
  4. "plugins.ml_commons.only_run_on_ml_node": false
  5. }
  6. }

copy

Step 1: Register and deploy a model

Register and deploy an ML model provided by OpenSearch:

  1. POST /_plugins/_ml/models/_register?deploy=true
  2. {
  3. "name": "huggingface/sentence-transformers/all-distilroberta-v1",
  4. "version": "1.0.2",
  5. "model_format": "TORCH_SCRIPT"
  6. }

copy

Registering a model is an asynchronous task. OpenSearch returns a task ID for this task. Check the status of the task by using the Tasks API:

  1. GET /_plugins/_ml/tasks/<task_id>

copy

Once the task is complete, the task state will change to COMPLETED and the Tasks API response will contain a model ID for the registered model. Note the model ID; you’ll use it in the following steps.

Step 2: Create an ingest pipeline

Create an ingest pipeline that will generate vector embeddings from text:

  1. PUT _ingest/pipeline/nlp-index-pipeline
  2. {
  3. "processors" : [
  4. {
  5. "text_embedding": {
  6. "model_id": "<model_id>",
  7. "field_map": {
  8. "question_text": "question_vector"
  9. }
  10. }
  11. }
  12. ]
  13. }

copy

Test the ingest pipeline:

  1. POST /_plugins/_ml/_predict/text_embedding/<model_id>
  2. {
  3. "text_docs":[ "what does the package contain?"],
  4. "return_number": true,
  5. "target_response": ["sentence_embedding"]
  6. }

copy

Step 3: Create an index

Create a vector index and set the default ingest pipeline to the ingest pipeline created in the previous step:

  1. PUT /neural_search_pqa
  2. {
  3. "settings": {
  4. "index.knn": true,
  5. "default_pipeline": "nlp-index-pipeline"
  6. },
  7. "mappings": {
  8. "properties": {
  9. "question_vector": {
  10. "type": "knn_vector",
  11. "dimension": 768
  12. }
  13. }
  14. }
  15. }

copy

Step 4: Ingest data

Ingest the data you prepared in the Prerequisites section:

  1. curl -XPOST -u "<username>:<password>" -k https://localhost:9200/_bulk --data-binary @neural_search_amazon_pqa_headsets.json -H 'Content-Type: application/json'

copy

If you’re not running the Security plugin, omit the username and password:

  1. curl -XPOST http://localhost:9200/_bulk --data-binary @neural_search_amazon_pqa_headsets.json -H 'Content-Type: application/json'

copy

Test the vector generation:

  1. GET /neural_search_pqa/_search

copy

Step 5: Search the data

Now search the data using the following search methods.

To run a semantic search, send the following request:

  1. GET /neural_search_pqa/_search
  2. {
  3. "size": 5,
  4. "query": {
  5. "neural": {
  6. "question_vector": {
  7. "query_text": "what does the package contain?",
  8. "model_id": "<model_id>",
  9. "k": 5
  10. }
  11. }
  12. }
  13. }

copy

To run a raw vector search using test embeddings, send the following request:

Request

  1. GET /neural_search_pqa/_search
  2. {
  3. "query": {
  4. "knn": {
  5. "question_vector": {
  6. "vector": [
  7. 0.002710069,
  8. -0.009941524,
  9. -0.010563275,
  10. -0.0010122135,
  11. -0.01606663,
  12. 0.035004564,
  13. -0.024301449,
  14. 0.036937017,
  15. 0.0021445795,
  16. -0.018301377,
  17. 0.028222118,
  18. 0.03426478,
  19. 0.06526259,
  20. -0.11439706,
  21. -0.05570727,
  22. -0.013401183,
  23. 0.07173271,
  24. -0.008754317,
  25. -0.003892538,
  26. -0.04069254,
  27. -0.007873223,
  28. 0.043676812,
  29. 0.07628463,
  30. 0.006414452,
  31. 0.017962739,
  32. 0.015939584,
  33. 0.0035662137,
  34. -0.025271492,
  35. 0.0003880734,
  36. -0.07922912,
  37. -0.055034645,
  38. -0.005235041,
  39. 0.016212236,
  40. -0.0027856824,
  41. 0.015833888,
  42. -0.008724626,
  43. 0.07955987,
  44. -0.015250193,
  45. 0.043985505,
  46. 0.0161295,
  47. 0.043298006,
  48. 0.045120195,
  49. 0.0008796525,
  50. 0.025070759,
  51. 0.02620675,
  52. 0.0008109898,
  53. 0.03925882,
  54. 0.0014451992,
  55. -0.0106107555,
  56. 0.01826351,
  57. 0.03323938,
  58. -0.045674287,
  59. -0.0070893173,
  60. 0.022116413,
  61. -0.04267077,
  62. -0.07391224,
  63. -0.007829025,
  64. -0.027157241,
  65. 0.02210903,
  66. 0.03281591,
  67. 0.03863423,
  68. 0.019042324,
  69. -0.008937828,
  70. -0.00822864,
  71. -0.0013345153,
  72. -0.012705528,
  73. 0.024063895,
  74. 0.06755618,
  75. -0.026645413,
  76. -0.044332504,
  77. -0.009713288,
  78. 0.07448414,
  79. -0.037496917,
  80. -0.059190735,
  81. 0.00071719656,
  82. 0.054966882,
  83. -0.014735149,
  84. -0.012903547,
  85. -0.07329577,
  86. 0.032558594,
  87. -0.0065674637,
  88. 0.030938147,
  89. -0.000380445,
  90. 0.03772217,
  91. 0.065343246,
  92. -0.03851167,
  93. 0.021905331,
  94. -0.031275578,
  95. -0.03284647,
  96. -0.0039149136,
  97. 0.033011954,
  98. -0.015860643,
  99. 0.056815848,
  100. 0.018801196,
  101. 0.036051515,
  102. 0.030969055,
  103. -0.06881828,
  104. -0.07299447,
  105. 0.011791604,
  106. 0.036003478,
  107. 0.085550085,
  108. -0.030811753,
  109. 0.008854608,
  110. -0.00115729,
  111. 0.058123615,
  112. 0.031589605,
  113. -0.04637206,
  114. 0.052185714,
  115. -0.008147512,
  116. -0.009668442,
  117. -0.020753473,
  118. -0.044140838,
  119. 0.007126401,
  120. 0.018284583,
  121. 0.026957503,
  122. -0.06066957,
  123. 0.005663597,
  124. -0.00054079125,
  125. -0.007547787,
  126. 0.038137276,
  127. 0.029036777,
  128. -0.050400596,
  129. -0.04595853,
  130. 0.019300641,
  131. 0.0750706,
  132. 0.06053001,
  133. 0.05319831,
  134. -0.040328506,
  135. -0.026151964,
  136. 0.017703054,
  137. -0.009880278,
  138. -0.02431335,
  139. -0.016003195,
  140. 0.017467672,
  141. -0.028064456,
  142. 0.010797431,
  143. 0.04620068,
  144. -0.035007767,
  145. -0.05585064,
  146. 0.053512778,
  147. 0.033208907,
  148. 0.008550426,
  149. -0.0388121,
  150. -0.043947462,
  151. 0.041298136,
  152. 0.00632402,
  153. 0.050902393,
  154. 0.025355011,
  155. 0.049950752,
  156. 0.05057344,
  157. -0.030225132,
  158. 0.068390064,
  159. 0.011451242,
  160. 0.022812577,
  161. -0.04050082,
  162. 0.04564967,
  163. 0.02095755,
  164. -0.008775425,
  165. 0.02742215,
  166. 0.0045154644,
  167. -0.022773914,
  168. -0.023864053,
  169. 0.048423547,
  170. -0.02743273,
  171. 0.023161013,
  172. -0.085432865,
  173. -0.027781866,
  174. 0.045083255,
  175. -0.024330953,
  176. 0.051298082,
  177. -0.014561553,
  178. 0.019947212,
  179. -0.04762156,
  180. -0.08161497,
  181. -0.02915204,
  182. -0.05000734,
  183. 0.016844928,
  184. 0.06842721,
  185. -0.07254415,
  186. 0.023711553,
  187. -0.065741085,
  188. -0.02294238,
  189. 0.026964355,
  190. 0.023867974,
  191. -0.036694836,
  192. 0.031053912,
  193. -0.029109096,
  194. 0.03979944,
  195. 0.0066577485,
  196. -0.04632492,
  197. -0.002852599,
  198. 0.104205936,
  199. -0.0015289283,
  200. -0.0031528969,
  201. -0.067211226,
  202. 0.038498618,
  203. -0.044048615,
  204. 0.07784984,
  205. -0.00019098066,
  206. -0.073304884,
  207. -0.025518911,
  208. -0.044625603,
  209. -0.015586972,
  210. 0.029835561,
  211. 0.012194141,
  212. -0.015629057,
  213. -0.020035604,
  214. -0.06611267,
  215. -0.011576042,
  216. -0.018833332,
  217. -0.0058776387,
  218. 0.0015687104,
  219. 0.042071432,
  220. 0.035765655,
  221. 0.036961976,
  222. -0.06410254,
  223. 0.0069225053,
  224. 0.009306832,
  225. -0.033220366,
  226. -0.0011623797,
  227. -0.05273565,
  228. -0.05313439,
  229. 0.0040645716,
  230. 0.015500928,
  231. -0.031550664,
  232. 0.052280493,
  233. 0.0037078348,
  234. -0.021173084,
  235. 0.0150960395,
  236. 0.078733385,
  237. 0.0028686044,
  238. -0.005216703,
  239. -0.0036014854,
  240. 0.050795995,
  241. -0.041090492,
  242. -0.04149299,
  243. -0.042463295,
  244. 0.004432829,
  245. 0.019274198,
  246. 0.02163699,
  247. -0.009603396,
  248. -0.0049729077,
  249. -0.04318596,
  250. -0.087209016,
  251. -0.018899467,
  252. -0.010470672,
  253. -0.030606175,
  254. 0.002642825,
  255. 0.0075506642,
  256. 0.021283865,
  257. 0.02029468,
  258. -0.020240186,
  259. 0.021211915,
  260. 0.013999255,
  261. 0.061195884,
  262. 0.04166171,
  263. -0.052985657,
  264. -0.025418852,
  265. 0.053535376,
  266. 0.0052670254,
  267. 0.00996464,
  268. 0.022772988,
  269. -0.0067050382,
  270. 0.011592934,
  271. 0.00048262937,
  272. 0.056712538,
  273. 0.04335854,
  274. -0.018352322,
  275. 0.021396462,
  276. -0.062193274,
  277. -0.07501798,
  278. -0.043138392,
  279. 0.029762914,
  280. 0.0022764541,
  281. -0.021794599,
  282. 0.020765148,
  283. 0.09824474,
  284. -0.0021401478,
  285. 0.07763454,
  286. -0.0071393973,
  287. 0.048322372,
  288. -0.0068628914,
  289. -0.01169711,
  290. 0.0369351,
  291. 0.056131776,
  292. 0.007255264,
  293. 0.014164492,
  294. 0.047250435,
  295. 0.037673194,
  296. -0.032006253,
  297. 0.0064754435,
  298. -0.029092291,
  299. 0.10371859,
  300. -0.04414858,
  301. -0.04181647,
  302. 0.031237667,
  303. 0.06330435,
  304. 0.0009903753,
  305. 0.015501904,
  306. -0.043972794,
  307. -0.07873341,
  308. -0.034613512,
  309. 0.0045046876,
  310. 0.02307906,
  311. 0.000025955713,
  312. -0.026988667,
  313. -0.021876179,
  314. -0.061864477,
  315. -0.03174992,
  316. -0.020722676,
  317. -0.013450134,
  318. -0.07542003,
  319. 0.032319948,
  320. -0.024602456,
  321. -0.0333397,
  322. 0.012231298,
  323. 0.041405365,
  324. 0.038915142,
  325. -0.015581544,
  326. -0.019906731,
  327. 0.05896227,
  328. -0.041462217,
  329. -0.017148478,
  330. 0.026938373,
  331. 0.016844902,
  332. 0.04285087,
  333. -0.017774548,
  334. 0.020407137,
  335. -0.051100556,
  336. 0.020812236,
  337. 0.07045972,
  338. -0.0051538153,
  339. 0.0011321488,
  340. -0.011617311,
  341. 0.022422142,
  342. -0.118273415,
  343. 0.036936108,
  344. -0.0006845923,
  345. -0.020841764,
  346. -0.03182234,
  347. 0.057517555,
  348. -0.033479884,
  349. -0.027451057,
  350. -0.043103144,
  351. 0.008880055,
  352. -0.041282106,
  353. 0.055030968,
  354. -0.04702203,
  355. 0.056501582,
  356. 0.014168417,
  357. 0.02385893,
  358. -0.015406,
  359. 0.02182121,
  360. -0.016413651,
  361. -0.010580059,
  362. -0.032921027,
  363. 0.0029189822,
  364. -0.02338612,
  365. -0.022606278,
  366. 0.04826292,
  367. -0.004382977,
  368. 0.025545042,
  369. 0.02886143,
  370. -0.060381353,
  371. -0.028612776,
  372. -0.07493492,
  373. 0.00719094,
  374. 0.015079185,
  375. -0.042235136,
  376. -0.01738928,
  377. -0.0015764751,
  378. 0.0080654705,
  379. 0.00045899878,
  380. 0.02290927,
  381. -0.044065766,
  382. -0.027154867,
  383. 0.019949641,
  384. 0.024834728,
  385. 0.035529647,
  386. -0.02206892,
  387. 0.010913105,
  388. 0.010024395,
  389. -0.029580403,
  390. 0.02561486,
  391. -0.009437026,
  392. 0.031584535,
  393. -0.03349992,
  394. 0.017479446,
  395. 0.03321881,
  396. 0.04470709,
  397. -0.051657267,
  398. 0.014068284,
  399. 0.028261097,
  400. 0.006924192,
  401. 0.015599272,
  402. 0.024204262,
  403. 0.017719362,
  404. -0.009957364,
  405. 0.042847835,
  406. -0.023584707,
  407. 0.045098092,
  408. -0.023444502,
  409. -0.0037809366,
  410. -0.03454478,
  411. 0.021056872,
  412. -0.043912865,
  413. -0.0390931,
  414. 0.009994628,
  415. -0.045420606,
  416. -0.010205209,
  417. 0.0022059593,
  418. -0.0064243795,
  419. 0.0058772936,
  420. -0.01227864,
  421. -0.028449906,
  422. 0.05086825,
  423. 0.011771748,
  424. 0.029447777,
  425. -0.00488326,
  426. -0.00972601,
  427. -0.0038806763,
  428. 0.012304249,
  429. 0.048176277,
  430. -0.044568717,
  431. -0.046164848,
  432. -0.040474243,
  433. -0.010306429,
  434. 0.0070577585,
  435. 0.050434314,
  436. -0.047979098,
  437. -0.032600895,
  438. 0.004446253,
  439. 0.043626312,
  440. 0.006991633,
  441. -0.008693645,
  442. 0.03655107,
  443. -0.010262025,
  444. 0.061423175,
  445. -0.041305497,
  446. 0.049218614,
  447. 0.024470096,
  448. 0.008277926,
  449. 0.023871863,
  450. -0.0680525,
  451. -0.01373448,
  452. -0.019403461,
  453. 0.01457673,
  454. 0.020989386,
  455. -0.012840103,
  456. 0.04480477,
  457. -0.012785204,
  458. 0.05274674,
  459. 0.00044528328,
  460. -0.03250745,
  461. -0.034448665,
  462. -0.021306505,
  463. -0.006346044,
  464. 0.03572138,
  465. -0.005664647,
  466. 0.007930765,
  467. 0.05546037,
  468. 0.08555072,
  469. 0.0052049863,
  470. 0.005712941,
  471. 0.0069970684,
  472. -0.07032658,
  473. -0.021292446,
  474. -0.043971684,
  475. 0.033561017,
  476. 0.0078121717,
  477. -0.01232355,
  478. 0.04682774,
  479. -0.012410457,
  480. -0.024060972,
  481. 0.026366811,
  482. 0.02424469,
  483. -0.003813699,
  484. 0.007787949,
  485. 0.030725611,
  486. -0.018421294,
  487. 0.024292007,
  488. 0.02683838,
  489. 0.018937135,
  490. 0.024167754,
  491. -0.012694116,
  492. -0.04747225,
  493. -0.018581947,
  494. 0.04490841,
  495. 0.010850694,
  496. 0.013474754,
  497. -0.053915884,
  498. -0.0157288,
  499. -0.035485156,
  500. 0.002554162,
  501. 1.9480496e-33,
  502. 0.026267078,
  503. -0.0005050934,
  504. 0.056276474,
  505. -0.04939255,
  506. -0.042061917,
  507. 0.017516103,
  508. -0.0347885,
  509. 0.0056415154,
  510. 0.028010717,
  511. 0.037564415,
  512. -0.010455965,
  513. -0.0016442607,
  514. 0.01223653,
  515. -0.0033323513,
  516. 0.04782389,
  517. 0.016800124,
  518. -0.07022924,
  519. -0.06512625,
  520. -0.0020572834,
  521. -0.01184387,
  522. 0.02217141,
  523. -0.024825176,
  524. -0.0015173266,
  525. -0.0269819,
  526. 0.019096063,
  527. 0.017777557,
  528. 0.017873168,
  529. 0.039785545,
  530. -0.046805847,
  531. 0.021698391,
  532. -0.06269843,
  533. 0.019622149,
  534. 0.007864404,
  535. 0.008894206,
  536. 0.0038650148,
  537. 0.042388596,
  538. -0.009941635,
  539. -0.023884028,
  540. -0.035126317,
  541. 0.0005930202,
  542. 0.006001224,
  543. -0.024304975,
  544. -0.025708912,
  545. 0.04936831,
  546. 0.0016331291,
  547. -0.040760614,
  548. 0.030479766,
  549. 0.05206152,
  550. -0.00443369,
  551. 0.10088473,
  552. 0.011507102,
  553. -0.023531357,
  554. -0.040234685,
  555. -0.01877001,
  556. 0.009172026,
  557. -0.03114441,
  558. -0.04349409,
  559. -0.017874151,
  560. 0.034953598,
  561. -0.008358288,
  562. 0.018915119,
  563. 0.07711077,
  564. 0.023954341,
  565. 0.002415601,
  566. 0.008599011,
  567. 0.010966408,
  568. 0.060247257,
  569. -0.0024354062,
  570. 0.029591061,
  571. -0.028959572,
  572. -0.036631253,
  573. -0.021705143,
  574. 0.030625504,
  575. -0.0047654426,
  576. 0.014964073,
  577. 0.037887104,
  578. 0.015323633,
  579. 0.037921626,
  580. -0.025576469,
  581. 0.055206805,
  582. -0.029262222,
  583. -0.01962374,
  584. -0.03655967,
  585. 0.027075786,
  586. -0.081109434,
  587. 0.02449199,
  588. -0.0011163651,
  589. 0.023110788,
  590. 0.027611898,
  591. 0.008880572,
  592. -0.016672952,
  593. 0.054573104,
  594. 0.0668384,
  595. 0.0016800691,
  596. -0.026792923,
  597. -0.007083326,
  598. -0.02166146,
  599. -0.05414477,
  600. 0.034420814,
  601. -0.014911138,
  602. -0.015938187,
  603. 0.0024109697,
  604. 0.018606238,
  605. -0.0068018483,
  606. 0.007229771,
  607. -0.07069912,
  608. 0.005073739,
  609. -0.02377225,
  610. 0.025782589,
  611. -0.023521125,
  612. -0.009433753,
  613. 0.001846642,
  614. 0.039006367,
  615. 0.058460444,
  616. 0.0073873056,
  617. 0.007734639,
  618. 0.04332041,
  619. -0.02951278,
  620. -0.025803477,
  621. 0.046294205,
  622. 0.02037022,
  623. 0.017971495,
  624. -0.07894564,
  625. 0.035865154,
  626. -0.0019950685,
  627. 0.0058006193,
  628. -0.016100215,
  629. -0.032027755,
  630. -0.015766902,
  631. 0.0036303538,
  632. 0.036353722,
  633. -0.012345974,
  634. -0.052974723,
  635. -0.018639334,
  636. -0.023760993,
  637. -0.039711308,
  638. 0.011242891,
  639. 0.019980058,
  640. 0.0056355395,
  641. -0.034353167,
  642. 0.035260357,
  643. 0.0017268837,
  644. 0.026457984,
  645. -0.027261587,
  646. -0.0083769085,
  647. 0.013137794,
  648. 0.06074834,
  649. -0.03966026,
  650. 0.015282993,
  651. -0.03137165,
  652. -0.0018508149,
  653. 0.0006249257,
  654. -0.088941485,
  655. -0.016475422,
  656. -0.061206434,
  657. 0.02161922,
  658. 0.04977918,
  659. -0.012738911,
  660. 0.029521877,
  661. 0.019252038,
  662. 0.0060790903,
  663. -0.019414661,
  664. -0.0037854896,
  665. 0.0035633324,
  666. 0.0012202597,
  667. -0.0025355266,
  668. -0.013203971,
  669. 0.03394517,
  670. 0.055446833,
  671. -0.056813966,
  672. -0.017438352,
  673. -0.0025512646,
  674. 0.0015061953,
  675. -0.014893743,
  676. 0.01575938,
  677. 0.0137350615,
  678. 0.021631295,
  679. -0.011761018,
  680. 0.003874792,
  681. -0.033888955,
  682. 0.034087986,
  683. 0.007129588,
  684. -0.054342985,
  685. -0.08680173,
  686. -0.002967837,
  687. 0.025510576,
  688. 0.021943994,
  689. 0.012099311,
  690. -0.04670378,
  691. -0.0052654264,
  692. -0.018963156,
  693. 0.041973554,
  694. -0.028053606,
  695. -0.08092634,
  696. 0.01265107,
  697. -0.054788973,
  698. 0.09400683,
  699. -0.06417367,
  700. -0.027034711,
  701. -0.039408244,
  702. 0.023176627,
  703. -0.01461873,
  704. 0.03884634,
  705. -0.036304634,
  706. -0.017949235,
  707. -0.057132546,
  708. 0.01646405,
  709. 0.0404744,
  710. -0.0027004834,
  711. -0.00041886698,
  712. -0.0028203563,
  713. 0.008831913,
  714. -0.0040895687,
  715. -0.012310025,
  716. 0.05664932,
  717. 0.017413152,
  718. 0.0068459054,
  719. 0.018910537,
  720. 0.019317543,
  721. 0.0020133136,
  722. -0.017052755,
  723. 0.005844975,
  724. 0.010338119,
  725. 0.020037401,
  726. 0.013349168,
  727. -0.05482043,
  728. -0.066234104,
  729. -0.02689704,
  730. -0.035874642,
  731. -0.050699547,
  732. -0.05060031,
  733. -0.04085721,
  734. -0.027676092,
  735. -0.0981729,
  736. -0.02701008,
  737. 0.050626777,
  738. 0.04092506,
  739. 0.029677482,
  740. 0.05753057,
  741. 0.10218166,
  742. 0.024896685,
  743. -0.030231407,
  744. -0.04353669,
  745. -0.005995228,
  746. -0.0033289846,
  747. 0.029730862,
  748. -0.10618225,
  749. 0.020681499,
  750. -0.024290795,
  751. 0.022039287,
  752. 0.043326188,
  753. -0.05395758,
  754. -0.025439745,
  755. 0.03492537,
  756. -0.027676322,
  757. -0.00053507305,
  758. 0.02218165,
  759. 0.09227446,
  760. -0.023444649,
  761. -0.06172415,
  762. 0.018731289,
  763. -0.01790614,
  764. 0.006927564,
  765. -0.025528973,
  766. -0.009136651,
  767. -0.009685557,
  768. 0.017786622,
  769. 0.023883764,
  770. 0.011552316,
  771. 0.06438146,
  772. 0.0033594605,
  773. 0.022067433,
  774. -0.035531327
  775. ],
  776. "k": 5
  777. }
  778. }
  779. }
  780. }

copy

To run a lexical search, send the following request:

  1. GET /neural_search_pqa/_search
  2. {
  3. "query": {
  4. "match": {
  5. "question_text": "what does the package contain?"
  6. }
  7. }
  8. }

copy

Create a search pipeline for hybrid search:

  1. PUT /_search/pipeline/hybrid-search-pipeline
  2. {
  3. "phase_results_processors": [
  4. {
  5. "normalization-processor": {
  6. "normalization": {
  7. "technique": "min_max"
  8. },
  9. "combination": {
  10. "technique": "arithmetic_mean",
  11. "parameters": {
  12. "weights": [
  13. 0.3,
  14. 0.7
  15. ]
  16. }
  17. }
  18. }
  19. }
  20. ]
  21. }

copy

Set this pipeline as the default search pipeline for the index:

  1. PUT /neural_search_pqa/_settings
  2. {
  3. "index.search.default_pipeline": "hybrid-search-pipeline"
  4. }

copy

To run a hybrid search, send the following request:

  1. GET /neural_search_pqa/_search
  2. {
  3. "_source": "question_text",
  4. "query": {
  5. "hybrid": {
  6. "queries": [
  7. {
  8. "match": {
  9. "question_text":"what does the package contain?"
  10. }
  11. },
  12. {
  13. "neural": {
  14. "question_vector": {
  15. "query_text": "what does the package contain?",
  16. "model_id": "<model_id>",
  17. "k": 5
  18. }
  19. }
  20. }
  21. ]
  22. }
  23. }
  24. }

copy

Clean up

Undeploy the model:

  1. POST /_plugins/_ml/models/<model_id>/_undeploy

copy

Delete the model:

  1. DELETE /_plugins/_ml/models/<model_id>

copy

Delete the index:

  1. DELETE /neural_search_pqa

copy

Interactive demos

Explore AI search and RAG demos

Try interactive Hugging Face demos showcasing AI search, multimodal RAG, and agentic RAG

Getting started

You can bring your own vectors or let OpenSearch generate embeddings automatically from your data. See Preparing vectors.

Get started with vector search

Build powerful similarity search applications using your existing vectors or embeddings

Generate embeddings automatically

Streamline your vector search using OpenSearch’s built-in embedding generation

1

Create an index

Create a vector index for storing your embeddings.

2

Ingest data

Ingest your data into the index.

3

Search data

Use raw vector search or AI-powered methods like semantic, hybrid, multimodal, or neural sparse search. Add RAG to build conversational search.

Get started

Build your solution

AI search

Discover AI search, from semantic, hybrid, and multimodal search to RAG

Tutorials

Follow step-by-step tutorials to build AI-powered search for your applications

Advanced filtering

Refine search results while maintaining semantic relevance

Memory-efficient search

Reduce memory footprint using vector compression methods

Sparse vector support

Combine semantic understanding with traditional search efficiency using neural sparse search

Multi-vector support

Store and search multiple vectors per document using nested fields