SemanticSearchNode


@ExperimentalAppSearchApi
class SemanticSearchNode : FunctionNode


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 getModelSignature) and a similarity score within the range specified based on the provided metric.

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

SemanticSearchNode(vectorIndex: Int)

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

SemanticSearchNode(vectorIndex: Int, lowerBound: Float)

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

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

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

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

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

Public functions

Boolean
equals(o: Any!)
Int

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

String

Returns the name of the function represented by SemanticSearchNode.

Float

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

Float

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

Int

Returns the index of the embedding vector used in semanticSearch.

Int
Unit
setBounds(lowerBound: Float, upperBound: Float)

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

Unit
setDistanceMetric(distanceMetric: Int)

Sets how similarity is calculated between embedding vectors.

Unit
setVectorIndex(vectorIndex: Int)

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

String

Get the query string representation of SemanticSearchNode.

Inherited Constants

From androidx.appsearch.ast.FunctionNode
const String!
FUNCTION_NAME_GET_SEARCH_STRING_PARAMETER = "getSearchStringParameter"

Name of the query function represented by androidx.appsearch.ast.query.GetSearchStringParameterNode.

const String!

Name of the query function represented by androidx.appsearch.ast.query.HasPropertyNode.

const String!
FUNCTION_NAME_PROPERTY_DEFINED = "propertyDefined"

Name of the query function represented by androidx.appsearch.ast.query.PropertyDefinedNode.

const String!

Name of the query function represented by androidx.appsearch.ast.query.SearchNode.

const String!

Name of the query function represented by androidx.appsearch.ast.query.SemanticSearchNode.

Inherited functions

From androidx.appsearch.ast.Node
(Mutable)List<Node!>

Get a list of the node's child Nodes.

Public constructors

SemanticSearchNode

Added in 1.1.0-alpha07
SemanticSearchNode(vectorIndex: Int)

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

By default:

  • The default set by the user and returned by 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 SemanticSearchNode for an explanation of the parameters.

SemanticSearchNode

Added in 1.1.0-alpha07
SemanticSearchNode(vectorIndex: Int, lowerBound: Float)

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

By default:

  • The default set by the user and returned by 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 SemanticSearchNode for an explanation of the parameters.

SemanticSearchNode

Added in 1.1.0-alpha07
SemanticSearchNode(vectorIndex: Int, lowerBound: Float, upperBound: Float)

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

By default:

  • The default set by the user and returned by getDefaultEmbeddingSearchMetricType will be used to determine similarity between embedding vectors. If no default is set, cosine similarity will be used.

See SemanticSearchNode for an explanation of the parameters.

SemanticSearchNode

Added in 1.1.0-alpha07
SemanticSearchNode(
    vectorIndex: Int,
    lowerBound: Float,
    upperBound: Float,
    distanceMetric: Int
)

Constructor for SemanticSearchNode representing the semanticSearch function in a query.

Parameters
vectorIndex: Int

The index of the embedding vector in the list of vectors returned by getEmbeddingParameters to use in the search.

lowerBound: Float

The lower bound on similarity score for a embedding vector such that the associated document will be returned.

upperBound: Float

The upper bound on similarity score for a embedding vector such that the associated document will be returned.

distanceMetric: Int

How distance between embedding vectors will be calculated.

Public functions

equals

fun equals(o: Any!): Boolean

getDistanceMetric

Added in 1.1.0-alpha07
fun getDistanceMetric(): Int

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

getFunctionName

Added in 1.1.0-alpha07
fun getFunctionName(): String

Returns the name of the function represented by SemanticSearchNode.

getLowerBound

Added in 1.1.0-alpha07
fun getLowerBound(): Float

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

getUpperBound

Added in 1.1.0-alpha07
fun getUpperBound(): Float

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

getVectorIndex

Added in 1.1.0-alpha07
fun getVectorIndex(): Int

Returns the index of the embedding vector used in semanticSearch.

hashCode

fun hashCode(): Int

setBounds

Added in 1.1.0-alpha07
fun setBounds(lowerBound: Float, upperBound: Float): Unit

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

Parameters
lowerBound: Float

The lower bound of the range of values.

upperBound: Float

The upper bound of the range of values.

setDistanceMetric

Added in 1.1.0-alpha07
fun setDistanceMetric(distanceMetric: Int): Unit

Sets how similarity is calculated between embedding vectors.

Parameters
distanceMetric: Int

How similarity is calculated between embedding vectors.

setVectorIndex

Added in 1.1.0-alpha07
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 SemanticSearchNode.

The query string representation will be the function name, followed by the fields of 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:

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.