# SemanticSearchNode

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/ast/query/SemanticSearchNode.java+class:androidx.appsearch.ast.query.SemanticSearchNode) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@ExperimentalAppSearchApi
class SemanticSearchNode : FunctionNode
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode` that represents the semanticSearch function.

The semanticSearch function matches all documents that have at least one embedding vector with a matching model signature (see `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#getModelSignature()`) and a similarity score within the range specified. The similarity score is calculated by determining the distance between the document embedding vector with a matching model signature and the embedding vector indexed at the list of vectors returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getEmbeddingParameters()`. How this distance is defined is based on what distance metric set.

This node can be used to build a query that contains the semanticSearch function. For example, the node `SemanticSearchNode(0, -0.5, 0.5, DOT_PRODUCT)` is equivalent to the query \`semanticSearch(getEmbeddingParameter(0), -0.5, 0.5, "DOT_PRODUCT")\`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int)(vectorIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int,float)(vectorIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, lowerBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int,float,float)(vectorIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, lowerBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, upperBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int,float,float,int)( vectorIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, lowerBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, upperBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, distanceMetric: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#equals(java.lang.Object)(o: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#getDistanceMetric()()` Returns the distance metric used to calculated similarity between embedding vectors. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#getFunctionName()()` Returns the name of the function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#getLowerBound()()` Returns the lower bound of the range of values similarity scores must fall in. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#getUpperBound()()` Returns the upper bound of the range of values similarity scores must fall in. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#getVectorIndex()()` Returns the index of the embedding vector to be retrieved from the list of embedding vectors returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getEmbeddingParameters()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#setBounds(float,float)(lowerBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, upperBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Sets the bounds of the range of values that semanticSearch will search against. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#setDistanceMetric(int)(distanceMetric: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets how similarity is calculated between embedding vectors. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#setVectorIndex(int)(vectorIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the index of the embedding vector that semanticSearch will use. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#toString()()` Get the query string representation of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode`. |

| ### Inherited Constants |
|---|
| From [androidx.appsearch.ast.FunctionNode](https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode) |---|---| | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_GET_SEARCH_STRING_PARAMETER() = "getSearchStringParameter"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/GetSearchStringParameterNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_HAS_PROPERTY() = "hasProperty"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/HasPropertyNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_PROPERTY_DEFINED() = "propertyDefined"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/PropertyDefinedNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_SEARCH() = "search"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_SEMANTIC_SEARCH() = "semanticSearch"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode`. | |

| ### Inherited functions |
|---|
| From [androidx.appsearch.ast.Node](https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node) |---|---| | `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node#getChildren()()` Get a list of the node's child `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node`s. | |

## Public constructors

### SemanticSearchNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
SemanticSearchNode(vectorIndex: Int)
```

Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query.

By default:

- The default set by the user and returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getDefaultEmbeddingSearchMetricType()` will be used to determine similarity between embedding vectors. If no default is set, cosine similarity will be used.
- The upper bound on similarity scores for an embedding vector such that the associated document will be returned is positive infinity.
- The lower bound on similarity scores for an embedding vector such that the associated document will be returned is negative infinity.

See `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int,float,float,int)` for an explanation of the parameters.

### SemanticSearchNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
SemanticSearchNode(vectorIndex: Int, lowerBound: Float)
```

Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query.

By default:

- The default set by the user and returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getDefaultEmbeddingSearchMetricType()` will be used to determine similarity between embedding vectors. If no default is set, cosine similarity will be used.
- The upper bound on similarity scores for an embedding vector such that the associated document will be returned is positive infinity.

See `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int,float,float,int)` for an explanation of the parameters.

### SemanticSearchNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
SemanticSearchNode(vectorIndex: Int, lowerBound: Float, upperBound: Float)
```

Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query.

By default:

- The default set by the user and returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getDefaultEmbeddingSearchMetricType()` will be used to determine similarity between embedding vectors. If no default is set, cosine similarity will be used.

See `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode#SemanticSearchNode(int,float,float,int)` for an explanation of the parameters.

### SemanticSearchNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
SemanticSearchNode(
    vectorIndex: Int,
    lowerBound: Float,
    upperBound: Float,
    distanceMetric: Int
)
```

Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` representing the semanticSearch function in a query.

| Parameters |
|---|---|
| `vectorIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the embedding vector in the list of vectors returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getEmbeddingParameters()` to use in the search. |
| `lowerBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The lower bound on similarity score for a embedding vector such that the associated document will be returned. |
| `upperBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The upper bound on similarity score for a embedding vector such that the associated document will be returned. |
| `distanceMetric: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | How distance between embedding vectors will be calculated. |

## Public functions

### equals

```
fun equals(o: Any!): Boolean
```

### getDistanceMetric

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getDistanceMetric(): Int
```

Returns the distance metric used to calculated similarity between embedding vectors.

### getFunctionName

```
fun getFunctionName(): String
```

Returns the name of the function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode`.

### getLowerBound

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getLowerBound(): Float
```

Returns the lower bound of the range of values similarity scores must fall in.

### getUpperBound

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getUpperBound(): Float
```

Returns the upper bound of the range of values similarity scores must fall in.

### getVectorIndex

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getVectorIndex(): Int
```

Returns the index of the embedding vector to be retrieved from the list of embedding vectors returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getEmbeddingParameters()`.

### hashCode

```
fun hashCode(): Int
```

### setBounds

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun setBounds(lowerBound: Float, upperBound: Float): Unit
```

Sets the bounds of the range of values that semanticSearch will search against.

| Parameters |
|---|---|
| `lowerBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The lower bound of the range of values. |
| `upperBound: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The upper bound of the range of values. |

### setDistanceMetric

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun setDistanceMetric(distanceMetric: Int): Unit
```

Sets how similarity is calculated between embedding vectors.

| Parameters |
|---|---|
| `distanceMetric: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | How similarity is calculated between embedding vectors. |

### setVectorIndex

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun setVectorIndex(vectorIndex: Int): Unit
```

Sets the index of the embedding vector that semanticSearch will use.

### toString

```
fun toString(): String
```

Get the query string representation of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode`.

The query string representation will be the function name, followed by the fields of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode` as arguments, surrounded by parentheses, but formatted in the following way:

- The vector index will appear as an argument to the function \`getEmbeddingParameter\`.
- The lower bound and upper bound will appear unchanged.
- The distance metric will be mapped to its corresponding string literal representation. For example, if the distance metric is 1, then the corresponding string literal would be `"COSINE"`.

For example, the node `SemanticSearchNode(0, -1.5f, 2, SearchSpec.EMBEDDING_SEARCH_METRIC_TYPE_COSINE)` will look like \`semanticSearch(getEmbeddingParameter(0), -1.5, 2, "COSINE")\`

If possible, default parameters will be left out of the query string. For example the node `SemanticSearchNode(0)` will look like \`semanticSearch(getEmbeddingParameter(0))\`. However if some defaults are set and unset, the defaults will be included in the query string. For example, if the user does something like this:

```kotlin
SemanticSearchNode semanticSearchNode = new SemanticSearchNode(0, -1, 1);
semanticSearchNode.setBounds(Float.NEGATIVE_INFINITY, 1);
```
Then the query string will look like \`semanticSearch(getEmbeddingParameter(0), -Float.MAX_VALUE, 1)\` where `Float.MAX_VALUE` is the max value of float.