Sometimes, you’re not just searching for something—you know exactly which vector you want to retrieve.

In such cases, you can directly fetch specific vectors from your database.

Fetch

Each record in Upstash Vector is assigned a unique ID, which you can use to retrieve a specific vector from your database.

Let’s use the fetch() method to retrieve a vector from Upstash Vector.

use Upstash\Vector\Index;
use Upstash\Vector\VectorFetch;

$index = new Index(
  url: "<UPSTASH_VECTOR_REST_URL>",
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
);

$results = $index->fetch(new VectorFetch(
  ids: ['1', '2'],
  includeMetadata: true, // (optional) if true the fetch results will contain metadata.
  includeVectors: true, // (optional) if true the fetch results will contain the indexed vectors.
  includeData: true, // (optional) if true the fetch results will contain the string data.
));

The fetch() method returns a Upstash\Vector\VectorFetchResult object, which allows you to access the results of the query.