Upstash Documentation

Query Vectors

Queries the approximate nearest neighbors of a vector.
3 min read
posthttps://{endpoint}/query/{namespace}
posthttps://{endpoint}/query/{namespace}
Tip

Query will run against the default namespace by default. You can use a different namespace by specifying it in the request path.

Request#

It is also possible to send a batch query request by providing an array of fields below.

vectornumber[]required#
The query vector
Note
The query vector should have the same dimensions as your index.
topKnumber#

The total number of the vectors that you want to receive as a query result. The response will be sorted based on the distance metric score, and at most topK many vectors will be returned.

Default: "10"

includeMetadataboolean#

Whether to include the metadata of the vectors in the response, if any. It is recommended to set this to true to easily identify vectors.

Default: "false"

includeVectorsboolean#

Whether to include the vector values in the response. It is recommended to set this to false as the vector values can be quite big, and not needed most of the time.

Default: "false"

includeDataboolean#

Whether to include the data of the vectors in the response, if any.

Default: "false"

filterstring#

Metadata filter to apply.

Default: ""

weightingStrategystring#

For sparse vectors of sparse and hybrid indexes, specifies what kind of weighting strategy should be used while querying the matching non-zero dimension values of the query vector with the documents.

If not provided, no weighting will be used.

Only possible value is IDF (inverse document frequency).

fusionAlgorithmstring#

Fusion algorithm to use while fusing scores from dense and sparse components of a hybrid index.

If not provided, defaults to RRF (Reciprocal Rank Fusion).

Other possible value is DBSF (Distribution-Based Score Fusion).

Path#

namespacestring#

The namespace to use. When no namespace is specified, the default namespace will be used.

Default: ""

Response#

If the request was an array of a single element, or a JSON object, an object with the following fields is returned.

If the request was an array of more than one items, an array of objects below is returned, one for each query item.

Note

For dense indexes, the score is normalized to always be between 0 and 1. The closer the score is to 1, the more similar the vector is to the query vector. This does not depend on the distance metric you use.

For sparse and hybrid indexes, scores can be arbitrary values, but the score will be higher for more similar vectors.

ScoresObject[]#
Show properties
idstringrequired#

The id of the vector.

scorenumberrequired#

The similarity score of the vector, calculated based on the distance metric of your index.

vectornumber[]#

The dense vector value for dense and hybrid indexes.

sparseVectorObject[]#

The sparse vector value for sparse and hybrid indexes.

Show properties
indicesnumber[]#

Indices of the non-zero valued dimensions.

valuesnumber[]#

Values of the non-zero valued dimensions.

metadataObject#

The metadata of the vector, if any.

datastring#

The unstructured data of the vector, if any.