Skip to content
Start here

Query Vectors

client.vectorize.indexes.query(stringindexName, IndexQueryParams { account_id, vector, filter, 3 more } params, RequestOptionsoptions?): IndexQueryResponse { count, matches } | null
POST/accounts/{account_id}/vectorize/v2/indexes/{index_name}/query

Finds vectors closest to a given vector in an index.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Vectorize WriteVectorize Read
ParametersExpand Collapse
indexName: string
params: IndexQueryParams { account_id, vector, filter, 3 more }
account_id: string

Path param: Identifier

maxLength32
vector: Array<number>

Body param: The search vector that will be used to find the nearest neighbors.

filter?: unknown

Body param: A metadata filter expression used to limit nearest neighbor results.

returnMetadata?: "none" | "indexed" | "all"

Body param: Whether to return no metadata, indexed metadata or all metadata associated with the closest vectors.

One of the following:
"none"
"indexed"
"all"
returnValues?: boolean

Body param: Whether to return the values associated with the closest vectors.

topK?: number

Body param: The number of nearest neighbors to find.

ReturnsExpand Collapse
IndexQueryResponse { count, matches }
count?: number

Specifies the count of vectors returned by the search

matches?: Array<Match>

Array of vectors matched by the search

id?: string

Identifier for a Vector

maxLength64
metadata?: unknown
namespace?: string | null
score?: number

The score of the vector according to the index's distance metric

values?: Array<number> | null

Query Vectors

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const response = await client.vectorize.indexes.query('example-index', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  vector: [0.5, 0.5, 0.5],
});

console.log(response.count);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "count": 0,
    "matches": [
      {
        "id": "some-vector-id-023e105f4ecef8ad9ca31a8372d0c353",
        "metadata": {},
        "namespace": "namespace",
        "score": 0,
        "values": [
          0
        ]
      }
    ]
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "count": 0,
    "matches": [
      {
        "id": "some-vector-id-023e105f4ecef8ad9ca31a8372d0c353",
        "metadata": {},
        "namespace": "namespace",
        "score": 0,
        "values": [
          0
        ]
      }
    ]
  },
  "success": true
}