Upsert data
This page shows you how to use the upsert
operation to write records into a namespace in an index. Namespaces let you partition records within an index and are essential for implementing multitenancy when you need to isolate the data of each customer/user.
If a record ID already exists, upsert
overwrites the entire record. To update only part of a record, use the update
operation instead.
Pinecone is eventually consistent, so there can be a slight delay before new or changed records are visible to queries. See Understanding data freshness to learn about data freshness in Pinecone and how to check the freshness of your data.
Upsert limits
Metric | Limit |
---|---|
Max upsert size | 2MB or 1000 records |
Max metadata size per record | 40 KB |
Max length for a record ID | 512 characters |
Max dimensionality for dense vectors | 20,000 |
Max non-zero values for sparse vectors | 1000 |
Max dimensionality for sparse vectors | 4.2 billion |
When upserting larger amounts of data, it is recommended to upsert records in large batches. A batch of upserts should be as large as possible (up to 1000 records) without exceeding the maximum request size of 2MB.
To understand the number of records you can fit into one batch based on the vector dimensions and metadata size, see the following table:
Dimension | Metadata (bytes) | Max batch size |
---|---|---|
386 | 0 | 1000 |
768 | 500 | 559 |
1536 | 2000 | 245 |
Upsert records
Dense vectors
To upsert a record in an index namespace, provide the record ID and the dense vector value and specify the namesapce. If the specified namespace doesn’t exist, it is created. To use the default namespace, set the namespace to an empty string (""
).
Dense vectors and metadata
You can optionally attach metadata key-value pairs to records to store additional information or context. When you query the index, you can then filter by metadata to ensure only relevant records are scanned. This can reduce latency and improve the accuracy of results. For more information, see Metadata Filtering.
Dense and sparse vectors
You can optionally include sparse vector values alongside dense vector values. This allows you to perform hybrid search, or semantic and keyword search, in one query for more relevant results.
See Upsert sparse-dense vectors.
This feature is in public preview.
Upsert records in batches
When upserting larger amounts of data, it is recommended to upsert records in large batches. This should be as large as possible (up to 1000 records) without exceeding the maximum request size of 2MB. To understand the number of records you can fit into one batch, see the Upsert limits section.
Send upserts in parallel
Send multiple upserts in parallel to help increase throughput. Vector operations block until the response has been received. However, they can be made asynchronously as follows:
Python SDK with gRPC
Using the Python SDK with gRPC extras can provide higher upsert speeds. Through multiplexing, gRPC is able to handle large amounts of requests in parallel without slowing down the rest of the system (HoL blocking), unlike REST. Moreover, you can pass various retry strategies to the gRPC SDK, including exponential backoffs.
To install the gRPC version of the SDK:
To use the gRPC SDK, import the pinecone.grpc
subpackage and target an index as usual:
To launch multiple read and write requests in parallel, pass async_req
to the upsert
operation:
It is possible to get write-throttled faster when upserting using the gRPC SDK. If you see this often, we recommend you use a backoff algorithm(e.g., exponential backoffs)
while upserting.
The syntax for upsert, query, fetch, and delete with the gRPC SDK remain the same as the standard SDK.
Upsert a dataset as a dataframe
To quickly ingest data when using the Python SDK, use the upsert_from_dataframe
method. The method includes retry logic andbatch_size
, and is performant especially with Parquet file data sets.
The following example upserts the uora_all-MiniLM-L6-bm25
dataset as a dataframe.
Upsert records with integrated embedding
To automatically embed data as part of the upsert process, use integrated inference.
Troubleshoot index fullness errors
Serverless indexes automatically scale as needed.
However, pod-based indexes can run out of capacity. When that happens, upserting new records will fail with the following error:
While a full pod-based index can still serve queries, you need to scale your index to accommodate more records.
Was this page helpful?