Database
Inference
- Embed
Assistant
- Assistants
- Files
- Chat
- Evaluation
- Context snippets
Vectors
Upsert vectors
The upsert
operation writes vectors into a namespace. If a new value is upserted for an existing vector ID, it will overwrite the previous value.
For guidance and examples, see Upsert data.
POST
/
vectors
/
upsert
# pip install pinecone[grpc]
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("example-index")
upsert_response = index.upsert(
vectors=[
{
"id": "vec1",
"values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
"sparse_values": {
"indices": [1, 5],
"values": [0.5, 0.5]
},
"metadata": {
"genre": "drama"
}
},
{
"id": "vec2",
"values": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"sparse_values": {
"indices": [5, 6],
"values": [0.4, 0.5]
},
"metadata": {
"genre": "action"
}
}
],
namespace="example-namespace"
)
{"upsertedCount":2}
# pip install pinecone[grpc]
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("example-index")
upsert_response = index.upsert(
vectors=[
{
"id": "vec1",
"values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
"sparse_values": {
"indices": [1, 5],
"values": [0.5, 0.5]
},
"metadata": {
"genre": "drama"
}
},
{
"id": "vec2",
"values": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"sparse_values": {
"indices": [5, 6],
"values": [0.4, 0.5]
},
"metadata": {
"genre": "action"
}
}
],
namespace="example-namespace"
)
{"upsertedCount":2}
Body
application/json
The request for the upsert
operation.
An array containing the vectors to upsert. Recommended batch limit is 100 vectors.
This is the vector's unique id.
Required string length:
1 - 512
This is the vector data included in the request.
Vector sparse data. Represented as a list of indices and a list of corresponded values, which must be with the same length.
This is the metadata included in the request.
The namespace where you upsert vectors.
Response
200
application/json
A successful response.
The response for the upsert
operation.
The number of vectors upserted.
Was this page helpful?
# pip install pinecone[grpc]
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
index = pc.Index("example-index")
upsert_response = index.upsert(
vectors=[
{
"id": "vec1",
"values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
"sparse_values": {
"indices": [1, 5],
"values": [0.5, 0.5]
},
"metadata": {
"genre": "drama"
}
},
{
"id": "vec2",
"values": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"sparse_values": {
"indices": [5, 6],
"values": [0.4, 0.5]
},
"metadata": {
"genre": "action"
}
}
],
namespace="example-namespace"
)
{"upsertedCount":2}