Content Lake (Datastore)

Create and query an embeddings index (deprecated)

To get started with the Embeddings Index API, you first need to create an index.

Deprecation notice

You can create an embeddings index in one of the following ways:

This guide walks you through configuring an embeddings index for a Sanity project using the Embeddings Index CLI.

Prerequisites

  • The Sanity CLI. The CLI ships with the main Sanity package. The Embeddings Index CLI runs its commands through the Sanity CLI and authenticates with your Sanity login. Run sanity login before you start, or set a SANITY_EMBEDDINGS_TOKEN environment variable.
  • Run the commands from the root directory of a Sanity project that contains a sanity.cli.ts or sanity.cli.js file.
  • A user or token with permission to create webhooks, create tokens, and read datasets. The create command uses these permissions to set up a robot token and a webhook that keeps the index in sync with the dataset.

Gotcha

Create an embeddings index

To create an embeddings index, open a terminal session, and then run the command that matches how you plan to create an index:

# Create an embeddings index by passing arguments
npx @sanity/embeddings-index-cli create --indexName "INDEX_NAME" --dataset "DATASET_NAME" --filter "GROQ_FILTER" --projection "GROQ_PROJECTION"

# Alternatively, create an embeddings index by passing a JSON manifest
npx @sanity/embeddings-index-cli create --manifest MANIFEST_FILE_NAME.json

Creating an index can take time, depending on the number of existing documents and the indexer load.

You can define the configuration of an embeddings index in one of the following ways:

  • By passing configuration arguments when you create the index in the CLI.
  • By storing the configuration details in a JSON manifest file.

Define the index in the CLI

To define a new embeddings index in the root directory of a Sanity project, pass the following arguments with the embeddings-index create command:

  • --indexName: Assign a descriptive name to the index.
  • --dataset: Specify the name of an existing dataset. This is the target dataset to index. If you omit it, the CLI uses the dataset in your sanity.cli.ts or sanity.cli.js file.
  • --filter: Specify the filtering criteria to include in the index only the selected subset of documents from the dataset.
    The filter must be a valid GROQ filter without the square brackets that wrap the filter in a full query such as *[_type=='tutorial'].
    Example: _type=='tutorial'
  • --projection: Specify the projection criteria to include in the index only the selected subset of properties from the filtered documents.
    The projection must be a valid GROQ projection, including curly brackets.
    Example: {title, author}

Alternatively, you can create an embeddings index by passing a JSON manifest file with the --manifest argument:

  • --manifest MANIFEST_FILE_NAME.json

Example

# Create embeddings index with arguments
# 'filter' has no '[]' square brackets
# 'projection' keeps '{}' curly brackets
npx @sanity/embeddings-index-cli create --indexName "my-embeddings-index" --dataset "production" --filter "_type=='myDocumentType'" --projection "{...}"

# Create embeddings index with JSON manifest
# The JSON manifest is in the project root directory
npx @sanity/embeddings-index-cli create --manifest embeddings-index-manifest.json

Define the index in a JSON manifest

To store, reuse, and manage embeddings indexes with source code control and versioning, define their configuration in a JSON manifest file. Save the manifest file, for example manifest.json, in the root directory of your Sanity project.

A JSON manifest file defining an embeddings index must contain the following required fields:

{
  indexName: string,
  dataset: string,
  filter: string,
  projection: string
}

Example

{
  "indexName": "my-embeddings-index",
  "dataset": "production",
  "filter": "_type=='myType'",
  "projection": "{...}"
}

The manifest must be valid JSON, so it can't contain comments. The filter value has no surrounding square brackets, and the projection value keeps its curly brackets.

To create a JSON manifest file, invoke the manifest command:

npx @sanity/embeddings-index-cli manifest --out manifest.json --indexName "INDEX_NAME" --dataset "DATASET_NAME" --filter "GROQ_FILTER" --projection "GROQ_PROJECTION"

To change the configuration of an existing index, run the delete command, and then run the create command again.

Check the status of an embeddings index

You can check the status of your embeddings indexes to monitor the creation progress or the completeness of the indexes.

To check the status of all embeddings indexes in a dataset, run the following command. Add --dataset to target a dataset other than the one in your Sanity CLI configuration:

npx @sanity/embeddings-index-cli list

To check the status of a specific embeddings index in a Sanity project, run:

npx @sanity/embeddings-index-cli get --indexName "INDEX_NAME"

Query an index

To query an index, make a request with the Embeddings Index HTTP API.

import { createClient } from '@sanity/client'
const client = createClient({
  projectId: '',
  dataset: 'DATASET_NAME',
  apiVersion: 'vX', // vX is required for embeddings API calls
  token: process.env.SANITY_API_TOKEN,
  useCdn: false,
});
const dataset = 'DATASET_NAME'
const indexName = 'INDEX_NAME'

const response = await client.request({
  url: `/embeddings-index/query/${dataset}/${indexName}`,
  method: 'POST',
  body: {
    query: 'sci-fi adventure with cowboys and aliens',
    maxResults: 10,
    filter: {
      type: ['summary', 'synopsis', 'userReview'],
    },
  },
})

This example uses the query endpoint to search against an index and filter by document type. Learn more about querying the API.

Next steps

Was this page helpful?

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme