Upstash Vector provides embedding models that can automatically generate vector embeddings for you.
You can read more about Embedding Models on our docs.
Upsert Data
We’ll use the upsertData() method to instruct the SDK to upsert data that generates vectors from one of our embedding models, as demonstrated below:
use Upstash\Vector\Index;
use Upstash\Vector\DataUpsert;
$index = new Index(
  url: "<UPSTASH_VECTOR_REST_URL>",
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
);
$index->upsertData(new DataUpsert(
  id: '1',
  data: 'The capital of Japan is Tokyo',
));
Upsert Data Many
Building on the previous section, Upstash Vector also supports generating multiple vectors at once.
To do this, we’ll use the upsertDataMany() method, which enables you to efficiently insert or update multiple vectors in an index, as shown below:
use Upstash\Vector\Index;
use Upstash\Vector\DataUpsert;
$index = new Index(
  url: "<UPSTASH_VECTOR_REST_URL>",
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
);
$index->upsertDataMany([
  new DataUpsert(id: '1', data: 'The capital of Japan is Tokyo'),
  new DataUpsert(id: '2', data: 'The capital of France is Paris'),
  new DataUpsert(id: '3', data: 'The capital of Germany is Berlin'),
]);
For optimal results, we recommend limiting each batch to no more than 1,000 records at a time.
Sparse Indexes & Hybrid Indexes
Sparse and hybrid indexes do not require a different API. They will generate their vectors and sparse vectors
based on the models you selected when creating your vector index.
You can read more about Sparse Indexes and Hybrid Indexes on our docs.