forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: zhengxiu <zhengxiu@huawei.com> Co-committed-by: zhengxiu <zhengxiu@huawei.com>
497 lines
54 KiB
HTML
497 lines
54 KiB
HTML
<a name="EN-US_TOPIC_0000001955726494"></a><a name="EN-US_TOPIC_0000001955726494"></a>
|
||
|
||
<h1 class="topictitle1">Performing Vector Search</h1>
|
||
<div id="body0000001955726494"><div class="p" id="EN-US_TOPIC_0000001955726494__p2536314165316">The CSS vector database supports a variety of query methods, including standard query, hybrid query, script_score query, rescore query, and painless syntax extension. They enable efficient vector data search by accommodating diverse search needs.<ul id="EN-US_TOPIC_0000001955726494__ul1415819211585"><li id="EN-US_TOPIC_0000001955726494__li11581826586"><a href="#EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section344710865418">Standard Query</a>: retrieves documents that are most similar to the query vector.</li><li id="EN-US_TOPIC_0000001955726494__li1915815215814"><a href="#EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section102341611718">Hybrid Query</a>: combines vector search with traditional OpenSearch queries, such as pre-filtering and Boolean queries.</li><li id="EN-US_TOPIC_0000001955726494__li91581921580"><a href="#EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section4946246546">Script Score Query</a>: enables custom similarity calculations for vector searches by executing a custom script.</li><li id="EN-US_TOPIC_0000001955726494__li11158920581"><a href="#EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section107953451661">Rescore Query</a>: rescores and reranks the top results returned by an initial query to improve recall.</li><li id="EN-US_TOPIC_0000001955726494__li121593215820"><a href="#EN-US_TOPIC_0000001955726494__section102071126171611">Painless Syntax Extension</a>: allows the use of vector distance or similarity calculation functions in custom scripts.</li></ul>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section344710865418"><a name="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section344710865418"></a><a name="en-us_topic_0000001268154489_section344710865418"></a><h4 class="sectiontitle">Standard Query</h4><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p116718237114">Standard query is used to retrieve documents that are most similar to the query vector.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p10699133014548">The following command will return <em id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_i15619747289542">k</em> (specified by <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b19427032809542">size</strong>/<strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b15868144189542">topk</strong>) records that are the closest matches to the query vector.</p>
|
||
<pre class="screen" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_screen1466920229569">POST <i><span class="varname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_varname47651948195211">my_index</span></i>/_search
|
||
{
|
||
"size":2,
|
||
"_source": false,
|
||
"query": {
|
||
"vector": {
|
||
"my_vector": {
|
||
"vector": [1, 1],
|
||
"topk":2
|
||
}
|
||
}
|
||
}
|
||
}</pre>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_table112016411577" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters for standard query</caption><thead align="left"><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row120119417572"><th align="left" class="cellrowborder" valign="top" width="23%" id="mcps1.3.2.5.2.5.1.1"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p152017415713">Parameter</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.2.5.2.5.1.2"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1763712241312">Mandatory</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.2.5.2.5.1.3"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p166237264313">Type</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="48%" id="mcps1.3.2.5.2.5.1.4"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p02013445711">Description</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row26533154"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1881333553">size</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1482331954">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p69203313518">Integer</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p13915331450">Number of search results to return.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p12477204662018">Default value: <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b8755580319542">10</strong></p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row18131348871"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p31321448473">_source</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p513313481179">No</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p171331448370">Boolean</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p2013311481677">Whether to return the source text in documents. To reduce data transmission and improve query performance, set this parameter to <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b139371755131414">false</strong>.</p>
|
||
<div class="p" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p0836919144516">Value range:<ul id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_ul74052714513"><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li1540927154519"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b36642032104917">true</strong> (default): Returns the source text.</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li940627184516"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b20329739135016">false</strong>: Not to return the source text.</li></ul>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row12407401962"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p124014401260">query</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p22407408610">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p2024014018611">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p569812262249">Specifies the query vector.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p986113011243">Parameters:</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p16849539192517"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b18181755355">vector</strong> (mandatory): indicates a vector query (vector similarity-based search), including the vector field and query vector value.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p816801552413"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b913132365619">my_vector</strong> (mandatory): queried vector field (for example, <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmvalue159302219283"><b>my_vector</b></span>).</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row83814321817"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p123913324819">vector (sub-parameter)</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p23983212812">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p73918321187">Array/String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p647564453011">Query vector value. It is used to calculate the similarity between indexed vectors and the query vector.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p88291013103120">The value can be an array (for example, [1, 1]) or Base64-encoded value (for example, <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmvalue182541985329"><b>AAABAAACAAAD</b></span>).</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row16292516818"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p56213291915">topk</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1829125116816">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p42955110814">Integer</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p267231613315">The number of the most similar or relevant results to be returned.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p8820452331">Default value: same as <span class="parmname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmname1929142716339"><b>size</b></span>.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row842795112810"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p193995513415">ef</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p2428185118818">No</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p121017815399">Integer</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1887713228362">How many nearest neighbors to explore when inserting a new vector into the graph. A larger value indicates a higher query accuracy yet slower query speed.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1225115180408">This parameter is available only when <span class="parmname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmname13251218184015"><b>algorithm</b></span> is set to GRAPH, GRAPH_PQ, GRAPH_SQ8, or GRAPH_SQ4.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p976082693617">Value range: 0–100000</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p2042813511386">Default value: <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b1931737559542">200</strong></p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row39015465716"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p143905523418">max_scan_num</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p149563544119">No</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1195614519418">Integer</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p144561915404">Maximum number of graph nodes to scan during search. A larger value indicates a higher query accuracy yet slower query speed.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p635195504010">This parameter is available only when <span class="parmname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmname17541532168"><b>algorithm</b></span> is set to GRAPH, GRAPH_PQ, GRAPH_SQ8, or GRAPH_SQ4.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1967361116406">Value range: 0–1000000</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p155710277406">Default value: <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b18571901969542">10000</strong></p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row0480125417579"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.2.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p139165513419">nprobe</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.2.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p145620913410">No</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p05659104120">Integer</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.2.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p20228184614120">Number of centroids to explore during an IVF index query. A larger value indicates a higher query accuracy yet slower query speed.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p12507171516424">This parameter is available only when <span class="parmname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmname92321423544"><b>algorithm</b></span> is IVF_GRAPH or IVF_GRAPH_PQ.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p065916559416">Value range: 0–100000</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1250395714415">Default value: <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b3918288929542">100</strong></p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section102341611718"><a name="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section102341611718"></a><a name="en-us_topic_0000001268154489_section102341611718"></a><h4 class="sectiontitle">Hybrid Query</h4><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_p364401311819">Hybrid query combines vector search with traditional OpenSearch queries, such as pre-filtering and Boolean queries.</p>
|
||
<div class="warning" id="EN-US_TOPIC_0000001955726494__note7315184563620"><span class="warningtitle"><img src="public_sys-resources/warning_3.0-en-us.png"> </span><div class="warningbody"><p id="EN-US_TOPIC_0000001955726494__p242820500615">Only OpenSearch 2.19.0 clusters support pre-filtering.</p>
|
||
</div></div>
|
||
<p id="EN-US_TOPIC_0000001955726494__p7992115142212">In the following example, the top 10 records whose <span class="parmname" id="EN-US_TOPIC_0000001955726494__parmname11430986972555"><b>my_label</b></span> value is <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__parmvalue123669469372555"><b>red</b></span> are returned.</p>
|
||
<ul id="EN-US_TOPIC_0000001955726494__ul238620710614"><li id="EN-US_TOPIC_0000001955726494__li1583916257117"><strong id="EN-US_TOPIC_0000001955726494__b11651131413530">Pre-filtering query</strong><p id="EN-US_TOPIC_0000001955726494__p1325573345319">First, filters are applied to retrieve matching results. Then, vector search is performed on these results to retrieve the most relevant vectors based on similarity.</p>
|
||
<div class="p" id="EN-US_TOPIC_0000001955726494__p5328926115">The following is an example:<pre class="screen" id="EN-US_TOPIC_0000001955726494__screen2076214231683">POST <i><span class="varname" id="EN-US_TOPIC_0000001955726494__varname126175665219">my_index</span></i>/_search
|
||
{
|
||
"size": 10,
|
||
"query": {
|
||
"vector": {
|
||
"my_vector": {
|
||
"vector": [1, 2],
|
||
"topk": 10,
|
||
"filter": {
|
||
"term": { "my_label": "red" }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}</pre>
|
||
</div>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001955726494__table1727921614417" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Parameters for pre-filtering query</caption><thead align="left"><tr id="EN-US_TOPIC_0000001955726494__row127941634111"><th align="left" class="cellrowborder" valign="top" width="23%" id="mcps1.3.3.5.1.4.2.5.1.1"><p id="EN-US_TOPIC_0000001955726494__p2279141644111">Parameter</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.3.5.1.4.2.5.1.2"><p id="EN-US_TOPIC_0000001955726494__p727920162416">Mandatory</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.3.5.1.4.2.5.1.3"><p id="EN-US_TOPIC_0000001955726494__p52791416144118">Type</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="48%" id="mcps1.3.3.5.1.4.2.5.1.4"><p id="EN-US_TOPIC_0000001955726494__p627919166416">Description</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001955726494__row1727941624115"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.3.5.1.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__p116788306416">filter</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.5.1.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__p06786301414">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.5.1.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__p5678630124110">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.3.5.1.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__p19369920101116">Vector query filters. Standard OpenSearch query filters are supported, such as term and range.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__p3804104416172">If <span class="parmname" id="EN-US_TOPIC_0000001955726494__parmname861943373112542"><b>filter</b></span> is too restrictive, leading to a small intermediate result set, you can set the <span class="parmname" id="EN-US_TOPIC_0000001955726494__parmname1283754579112542"><b>index.vector.exact_search_threshold</b></span> parameter, so that when the intermediate result set is smaller than this threshold, pre-filtering query automatically switches over to brute-force query (FLAT algorithm), which ensures a high recall rate. For more information, see <a href="css_01_0121.html#EN-US_TOPIC_0000002319559898__en-us_topic_0000001309709789_section137344225249">Creating a Vector Index</a>.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__row127911160415"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.3.5.1.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__p967633017417">term</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.5.1.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__p106769306410">No</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.5.1.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__p667563010417">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.3.5.1.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__p8674193064111">Term query is a type of exact query. Documents that contain the exact term will be returned. For example, <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__parmvalue1368864033112542"><b>{"term": {"my_label": "red"}}</b></span> means only to return documents whose <span class="parmname" id="EN-US_TOPIC_0000001955726494__parmname1913556673112542"><b>my_label</b></span> value is <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__parmvalue1470353066112542"><b>red</b></span>.</p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</li><li id="EN-US_TOPIC_0000001955726494__li01282063320"><strong id="EN-US_TOPIC_0000001955726494__b1573843155318">Boolean query</strong><p id="EN-US_TOPIC_0000001955726494__p121371053132020">A Boolean query is in fact a post-filtering query method. Filtering and vector similarity-based search are performed separately. Then, the results of the two are combined using Boolean logic defined by clauses like must, should, and filter.</p>
|
||
<div class="p" id="EN-US_TOPIC_0000001955726494__p413711536208">The following is an example:<pre class="screen" id="EN-US_TOPIC_0000001955726494__screen1213875342014">POST <i><span class="varname" id="EN-US_TOPIC_0000001955726494__varname151381353172016">my_index</span></i>/_search
|
||
{
|
||
"size": 10,
|
||
"query": {
|
||
"bool": {
|
||
"must": {
|
||
"vector": {
|
||
"my_vector": {
|
||
"vector": [1, 2],
|
||
"topk": 10
|
||
}
|
||
}
|
||
},
|
||
"filter": {
|
||
"term": { "my_label": "red" }
|
||
}
|
||
}
|
||
}
|
||
}</pre>
|
||
</div>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001955726494__table8138145312208" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Boolean query parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001955726494__row813815311204"><th align="left" class="cellrowborder" valign="top" width="23%" id="mcps1.3.3.5.2.4.2.5.1.1"><p id="EN-US_TOPIC_0000001955726494__p13138125312011">Parameter</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.3.5.2.4.2.5.1.2"><p id="EN-US_TOPIC_0000001955726494__p20138115342013">Mandatory</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.3.5.2.4.2.5.1.3"><p id="EN-US_TOPIC_0000001955726494__p1213865314209">Type</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="48%" id="mcps1.3.3.5.2.4.2.5.1.4"><p id="EN-US_TOPIC_0000001955726494__p0138105382019">Description</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001955726494__row51393531207"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.3.5.2.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__p813919536205">bool</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.5.2.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__p181391553172011">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.5.2.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__p3139135362019">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.3.5.2.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__p413995392019">A compound query clause that combines subqueries using configured Boolean logic.</p>
|
||
<div class="p" id="EN-US_TOPIC_0000001955726494__p6139195372010">Parameter description:<ul id="EN-US_TOPIC_0000001955726494__ul813985362010"><li id="EN-US_TOPIC_0000001955726494__li1413965372011"><strong id="EN-US_TOPIC_0000001955726494__b202353775172555">must</strong>: Clauses that must match for documents to be included in the results.</li><li id="EN-US_TOPIC_0000001955726494__li5139175310203"><strong id="EN-US_TOPIC_0000001955726494__b183099655672555">filter</strong>: It is similar to <strong id="EN-US_TOPIC_0000001955726494__b14110526572555">must</strong>, but do not contribute to the relevance score.</li><li id="EN-US_TOPIC_0000001955726494__li1813935317202"><strong id="EN-US_TOPIC_0000001955726494__b151803119572555">should</strong>: Clauses that should match, but are not required. They are like nice-to-haves.</li><li id="EN-US_TOPIC_0000001955726494__li1913925311208"><strong id="EN-US_TOPIC_0000001955726494__b188129203072555">must_not</strong>: Clauses that must not match for documents to be included in the results.</li></ul>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__row1413975310201"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.3.5.2.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__p15139175362011">bool.must</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.5.2.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__p121391953182013">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.5.2.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__p191391753152020">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.3.5.2.4.2.5.1.4 "><div class="p" id="EN-US_TOPIC_0000001955726494__p15139155316200">Clauses that must match for documents to be included in the results. Parameter description:<ul id="EN-US_TOPIC_0000001955726494__ul15139135372019"><li id="EN-US_TOPIC_0000001955726494__li151395537204"><strong id="EN-US_TOPIC_0000001955726494__b139861179972555">vector</strong>: query vector</li><li id="EN-US_TOPIC_0000001955726494__li114065382016"><strong id="EN-US_TOPIC_0000001955726494__b3244359572555">my_vector</strong>: vector field</li><li id="EN-US_TOPIC_0000001955726494__li114085316201"><strong id="EN-US_TOPIC_0000001955726494__b85620321872555">topk</strong>: number of results to return</li></ul>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__row0140105317205"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.3.5.2.4.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__p1214020537201">bool.filter</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.3.5.2.4.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__p914065362016">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.5.2.4.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__p814055315207">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.3.5.2.4.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__p6140553142011">Clauses that must match, but do not contribute to the relevance score. Standard OpenSearch query filters are supported, such as term and range.</p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</li></ul>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section4946246546"><a name="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section4946246546"></a><a name="en-us_topic_0000001268154489_section4946246546"></a><h4 class="sectiontitle">Script Score Query</h4><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p191338162050">Script_score query enables custom similarity calculations for vector searches by executing a user-defined script. It works as follows:</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p1512359042">Pre-filtering works with any query. <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b13024816099542">script_score</strong> then calculates vector similarity on the pre-filtered results, and ranks the results. This query method does not use vector indexes. Its performance depends on the size of the intermediate result set after the pre-filtering. If the pre-filtering condition is set to <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b560736449542">match_all</strong>, a brute-force search is performed on all data.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p27367195718">The following is an example:</p>
|
||
<pre class="screen" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_screen3512185915411">POST <i><span class="varname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_varname573812415551">my_index</span></i>/_search
|
||
{
|
||
"size":2,
|
||
"query": {
|
||
"script_score": {
|
||
"query": {
|
||
"match_all": {}
|
||
},
|
||
"script": {
|
||
"source": "vector_score",
|
||
"lang": "vector",
|
||
"params": {
|
||
"field": "my_vector",
|
||
"vector": [1.0, 2.0],
|
||
"metric": "euclidean"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}</pre>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_table95121659546" frame="border" border="1" rules="all"><caption><b>Table 4 </b>script_score query parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row1451214594419"><th align="left" class="cellrowborder" valign="top" width="23%" id="mcps1.3.4.6.2.5.1.1"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p551216591840">Parameter</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.4.6.2.5.1.2"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p86491300215">Mandatory</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.4.6.2.5.1.3"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p435082812112">Type</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="48%" id="mcps1.3.4.6.2.5.1.4"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p105128591413">Description</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row13141161515111"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.4.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p101415158511">script_score</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.4.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p41414159512">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.4.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p121411415185118">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.4.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p139226675218">A root parameter for the script_score query.</p>
|
||
<div class="p" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p155441642526">Parameter description:<ul id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_ul17141133935314"><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li81411039205320"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b1587905217328">query</strong>: pre-filtering criteria. When it is set to <span class="parmname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmname94292115576"><b>match_all</b></span>, a brute-force search is performed on all data.</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li151411639165319"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b323565123315">script</strong>: custom script that calculates similarity scores.</li></ul>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row135121591243"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.4.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p651218591747">source</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.4.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p106491830112116">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.4.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p11350182872118">String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.4.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p1351225910417">Script name. The value is fixed to <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmvalue8308162616239"><b>vector_score</b></span>, indicating that a built-in script is used for calculating similarity.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row175123599411"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.4.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p75121759143">lang</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.4.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p76493308212">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.4.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1035018283215">String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.4.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p1651235910417">Script language type. The value is fixed to <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmvalue15555036162313"><b>vector</b></span>.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row1651219599413"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.4.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p1451211592047">field</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.4.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p76492030162114">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.4.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1350428202120">String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.4.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p1351218596418">Queried vector field, for example, <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b1216171414377">my_vector</strong>.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row1551285917417"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.4.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p165129591342">vector</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.4.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p17936101012612">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.4.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p19936210463">Array/String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.4.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p8936610961">Query vector value. It is used to calculate the similarity between indexed vectors and the query vector.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p093613101067">The value can be an array (for example, [1, 1]) or Base64-encoded value (for example, <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmvalue18217336145"><b>AAABAAACAAAD</b></span>).</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row751218591947"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.4.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p18512659244">metric</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.4.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p917382645416">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.4.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p19173526175411">String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.4.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1417320262542">Vector distance metric, which measures the similarity or distance between vectors.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p517362613541">Value range:</p>
|
||
<ul id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_ul717332685413"><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li4173192616544"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b19047695919542">euclidean</strong> (default): Euclidean distance</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li1717392611548"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b10735702739542">inner_product</strong>: inner product distance</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li117317263542"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b19701872639542">cosine</strong>: cosine distance</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li8173102615546"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b4243944119542">hamming</strong>: Hamming distance, which can be used only when <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b13693234849542">dim_type</strong> is set to <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b3714137629542">binary</strong>.</li></ul>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section107953451661"><a name="EN-US_TOPIC_0000001955726494__en-us_topic_0000001268154489_section107953451661"></a><a name="en-us_topic_0000001268154489_section107953451661"></a><h4 class="sectiontitle">Rescore Query</h4><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p176783181260">Rescore query rescores and reranks the top results returned by an initial query to improve recall.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p147213301172">When the GRAPH_PQ or IVF_GRAPH_PQ indexing algorithm is used, query results are ranked based on the asymmetric distance calculated by PQ. Rescore query then rescores and reranks the initial search results to improve recall.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p1567411217323">The following is an example of rescore query on a PQ index named <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b4350133823010">my_index</strong>:</p>
|
||
<pre class="screen" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_screen1639814155510">GET <i><span class="varname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_varname19581841103214">my_index</span></i>/_search
|
||
{
|
||
"size": 10,
|
||
"query": {
|
||
"vector": {
|
||
"my_vector": {
|
||
"vector": [1.0, 2.0],
|
||
"topk": 100
|
||
}
|
||
}
|
||
},
|
||
"rescore": {
|
||
"window_size": 100,
|
||
"vector_rescore": {
|
||
"field": "my_vector",
|
||
"vector": [1.0, 2.0],
|
||
"metric": "euclidean"
|
||
}
|
||
}
|
||
}</pre>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_table165271512103218" frame="border" border="1" rules="all"><caption><b>Table 5 </b>Rescore query parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row96748123320"><th align="left" class="cellrowborder" valign="top" width="23%" id="mcps1.3.5.6.2.5.1.1"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p467481273214">Parameter</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.3.5.6.2.5.1.2"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p3133837113020">Mandatory</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.5.6.2.5.1.3"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p19858163823019">Type</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="48%" id="mcps1.3.5.6.2.5.1.4"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p7674111213212">Description</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row168165751714"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.5.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p681618741715">rescore</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.5.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1381610711711">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p188166711177">Map</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.5.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p20222933111715">Defines rescoring parameters.</p>
|
||
<div class="p" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p17550845141716">Key parameters:<ul id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_ul4101105851713"><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li111011458141719">window_size: rescoring/reranking window size.</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li20101358161711">vector_rescore: other vector rescoring settings.</li></ul>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row4674161215326"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.5.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p136741112123210">window_size</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.5.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p16133123716300">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p285810386306">Integer</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.5.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p116742129325">Rescoring/reranking window size. The vector search returns the top k results, but only the first <em id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_i189817341712">window_size</em> results are rescored and reranked. A larger value indicates a larger reranking scope and hence a higher recall rate, but it also leads to higher computational overhead.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p52661033192">Default value: <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b7097594119542">100</strong></p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row19674612133213"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.5.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p16674171213212">field</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.5.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1710022896">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p20100621913">String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.5.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p6100142799">Queried vector field, for example, <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b1631516241913">my_vector</strong>.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row6674151212329"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.5.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p14674171273210">vector</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.5.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p270335312817">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p17036534810">Array/String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.5.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1270414536812">Query vector value. It is used to calculate the similarity between indexed vectors and the query vector.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p19704453986">The value can be an array (for example, [1, 1]) or Base64-encoded value (for example, <span class="parmvalue" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_parmvalue02201531147"><b>AAABAAACAAAD</b></span>).</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_row7674121216327"><td class="cellrowborder" valign="top" width="23%" headers="mcps1.3.5.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_en-us_topic_0000001268154489_p167419129328">metric</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.3.5.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p16988342781">Yes</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p198854213819">String</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="48%" headers="mcps1.3.5.6.2.5.1.4 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p39889421985">Vector distance metric, which measures the similarity or distance between vectors.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1298864217818">Value range:</p>
|
||
<ul id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_ul189881742384"><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li13988104218818"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b2261639249542">euclidean</strong> (default): Euclidean distance</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li159881042988"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b7131293759542">inner_product</strong>: inner product distance</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li39881442989"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b1061157679542">cosine</strong>: cosine distance</li><li id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_li8988124220820"><strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b0103526801">hamming</strong>: Hamming distance, which can be used only when <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b8103326302">dim_type</strong> is set to <strong id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_b5103192611013">binary</strong>.</li></ul>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001955726494__section102071126171611"><a name="EN-US_TOPIC_0000001955726494__section102071126171611"></a><a name="section102071126171611"></a><h4 class="sectiontitle">Painless Syntax Extension</h4><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p177861335101615">Painless syntax extension allows the use of vector distance or similarity calculation functions in custom scripts. CSS extension supports several vector distance/similarity calculation functions, which users can use readily in custom Painless scripts to build flexible rescoring formulas.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p18965620112713">The following is an example:</p>
|
||
<pre class="screen" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_screen11315195710305">POST <i><span class="varname" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_varname14606636193214">my_index</span></i>/_search
|
||
{
|
||
"size": 10,
|
||
"query": {
|
||
"script_score": {
|
||
"query": {
|
||
"match_all": {}
|
||
},
|
||
"script": {
|
||
"source": "1 / (1 + euclidean(params.vector, doc[params.field]))",
|
||
"params": {
|
||
"field": "my_vector",
|
||
"vector": [1, 2]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}</pre>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_table17610185023516" frame="border" border="1" rules="all"><caption><b>Table 6 </b>Supported vector distance/similarity calculation functions</caption><thead align="left"><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row461012507354"><th align="left" class="cellrowborder" valign="top" width="34.32%" id="mcps1.3.6.5.2.3.1.1"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p196101850203512">Function Signature</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="65.68%" id="mcps1.3.6.5.2.3.1.2"><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1061095020358">Description</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row1261045014357"><td class="cellrowborder" valign="top" width="34.32%" headers="mcps1.3.6.5.2.3.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p13610450103520">euclidean(Float[], DocValues)</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="65.68%" headers="mcps1.3.6.5.2.3.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p2610125033511">Euclidean distance</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row961085053513"><td class="cellrowborder" valign="top" width="34.32%" headers="mcps1.3.6.5.2.3.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p1610205014351">cosine(Float[], DocValues)</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="65.68%" headers="mcps1.3.6.5.2.3.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p6610750143515">Cosine similarity</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row1961015501351"><td class="cellrowborder" valign="top" width="34.32%" headers="mcps1.3.6.5.2.3.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p46101950163517">innerproduct(Float[], DocValues)</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="65.68%" headers="mcps1.3.6.5.2.3.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p461015012354">Inner product</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_row98852044174013"><td class="cellrowborder" valign="top" width="34.32%" headers="mcps1.3.6.5.2.3.1.1 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p13885174412404">hamming(String, DocValues)</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="65.68%" headers="mcps1.3.6.5.2.3.1.2 "><p id="EN-US_TOPIC_0000001955726494__en-us_topic_0000002319719730_p18852044114019">Hamming distance Only vectors whose <strong id="EN-US_TOPIC_0000001955726494__b898334319112542">dim_type</strong> is <strong id="EN-US_TOPIC_0000001955726494__b1865793899112542">binary</strong> are supported. The input query vector must be a Base64-encoded character string.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__p422195073115">Only OpenSearch 1.3.6 clusters support this function.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001955726494__row19222131811313"><td class="cellrowborder" valign="top" width="34.32%" headers="mcps1.3.6.5.2.3.1.1 "><p id="EN-US_TOPIC_0000001955726494__p1487113113111">hammings(String, DocValues)</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="65.68%" headers="mcps1.3.6.5.2.3.1.2 "><p id="EN-US_TOPIC_0000001955726494__p6871183133117">Hamming distance Only vectors whose <strong id="EN-US_TOPIC_0000001955726494__b601122893112542">dim_type</strong> is <strong id="EN-US_TOPIC_0000001955726494__b1990165018112542">binary</strong> are supported. The input query vector must be a Base64-encoded character string.</p>
|
||
<p id="EN-US_TOPIC_0000001955726494__p231916518323">Only OpenSearch 2.19.0 clusters support this function.</p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<div class="familylinks">
|
||
<div class="parentlink"><strong>Parent topic:</strong> <a href="css_01_0101.html">Configuring Vector Search for OpenSearch Clusters</a></div>
|
||
</div>
|
||
</div>
|
||
|