# pip install "pinecone[grpc]"
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index(host="INDEX_HOST")
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"
)
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone'
const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
const index = pc.index("INDEX_NAME", "INDEX_HOST")
await index.namespace('example-namespace').upsert([
{
id: 'vec1',
values: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
sparseValues: {
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],
metadata: {'genre': 'action'},
sparseValues: {
indices: [5, 6],
values: [0.4, 0.5]
}
}
])
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import io.pinecone.clients.Index;
import io.pinecone.configs.PineconeConfig;
import io.pinecone.configs.PineconeConnection;
import java.util.Arrays;
import java.util.List;
public class UpsertExample {
public static void main(String[] args) {
PineconeConfig config = new PineconeConfig("YOUR_API_KEY");
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
config.setHost("INDEX_HOST");
PineconeConnection connection = new PineconeConnection(config);
Index index = new Index(connection, "INDEX_NAME");
List<Float> values1 = Arrays.asList(0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f);
List<Float> values2 = Arrays.asList(0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f);
Struct metaData1 = Struct.newBuilder()
.putFields("genre", Value.newBuilder().setStringValue("drama").build())
.build();
Struct metaData2 = Struct.newBuilder()
.putFields("genre", Value.newBuilder().setStringValue("action").build())
.build();
index.upsert("A", values1, null, null, metaData1, null);
index.upsert("B", values2, null, null, metaData2, null);
}
}
package main
import (
"context"
"fmt"
"log"
"github.com/pinecone-io/go-pinecone/v2/pinecone"
"google.golang.org/protobuf/types/known/structpb"
)
func main() {
ctx := context.Background()
pc, err := pinecone.NewClient(pinecone.NewClientParams{
ApiKey: "YOUR_API_KEY",
})
if err != nil {
log.Fatalf("Failed to create Client: %v", err)
}
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: "INDEX_HOST"})
if err != nil {
log.Fatalf("Failed to create IndexConnection for Host: %v", err)
}
sparseValues1 := pinecone.SparseValues{
Indices: []uint32{1, 5},
Values: []float32{0.5, 0.5},
}
sparseValues2 := pinecone.SparseValues{
Indices: []uint32{5, 6},
Values: []float32{0.4, 0.5},
}
metadataMap1 := map[string]interface{}{
"genre": "comedy",
"year": 2020,
}
metadata1, err := structpb.NewStruct(metadataMap1)
if err != nil {
log.Fatalf("Failed to create metadata map: %v", err)
}
metadataMap2 := map[string]interface{}{
"genre": "documentary",
"year": 2019,
}
metadata2, err := structpb.NewStruct(metadataMap2)
if err != nil {
log.Fatalf("Failed to create metadata map: %v", err)
}
vectors := []*pinecone.Vector{
{
Id: "vec1",
Values: []float32{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
SparseValues: &sparseValues1,
Metadata: metadata1,
},
{
Id: "vec2",
Values: []float32{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9},
SparseValues: &sparseValues2,
Metadata: metadata2,
},
}
count, err := idxConnection.UpsertVectors(ctx, vectors)
if err != nil {
log.Fatalf("Failed to upsert vectors: %v", err)
} else {
fmt.Printf("Successfully upserted %d vector(s)!\n", count)
}
}
using Pinecone;
var pinecone = new PineconeClient("YOUR_API_KEY");
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
var index = pinecone.Index(host: "INDEX_HOST");
var upsertResponse = await index.UpsertAsync(new UpsertRequest {
Vectors = new[]
{
new Vector
{
Id = "vec1",
Values = new[] { 1.0f, 1.5f },
SparseValues = new SparseValues
{
Indices = [1, 5],
Values = new[] { 0.5f, 0.5f },
},
Metadata = new Metadata {
["genre"] = new("comedy"),
["year"] = new(2020),
}
},
new Vector
{
Id = "vec2",
Values = new[] { 2.0f, 1.0f },
SparseValues = new SparseValues
{
Indices = [5, 6],
Values = new[] { 0.4f, 0.5f },
},
Metadata = new Metadata {
["genre"] = new("documentary"),
["year"] = new(2019),
},
}
},
Namespace = "example-namespace",
});
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"
curl "https://$INDEX_HOST/vectors/upsert" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2024-10" \
-d '{
"vectors": [
{
"id": "vec1",
"values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
"sparseValues": {
"indices": [2, 7],
"values": [0.4, 0.5]
},
"metadata": {
"genre": "drama"
}
},
{
"id": "vec2",
"values": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"sparseValues": {
"indices": [1, 4],
"values": [0.1, 0.2]
},
"metadata": {
"genre": "action"
}
}
],
"namespace": "example-namespace"
}'
{"upsertedCount":2}
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, examples, and limits, see Upsert data.
POST
/
vectors
/
upsert
# pip install "pinecone[grpc]"
from pinecone.grpc import PineconeGRPC as Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index(host="INDEX_HOST")
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"
)
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone'
const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
const index = pc.index("INDEX_NAME", "INDEX_HOST")
await index.namespace('example-namespace').upsert([
{
id: 'vec1',
values: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
sparseValues: {
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],
metadata: {'genre': 'action'},
sparseValues: {
indices: [5, 6],
values: [0.4, 0.5]
}
}
])
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import io.pinecone.clients.Index;
import io.pinecone.configs.PineconeConfig;
import io.pinecone.configs.PineconeConnection;
import java.util.Arrays;
import java.util.List;
public class UpsertExample {
public static void main(String[] args) {
PineconeConfig config = new PineconeConfig("YOUR_API_KEY");
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
config.setHost("INDEX_HOST");
PineconeConnection connection = new PineconeConnection(config);
Index index = new Index(connection, "INDEX_NAME");
List<Float> values1 = Arrays.asList(0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f);
List<Float> values2 = Arrays.asList(0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f);
Struct metaData1 = Struct.newBuilder()
.putFields("genre", Value.newBuilder().setStringValue("drama").build())
.build();
Struct metaData2 = Struct.newBuilder()
.putFields("genre", Value.newBuilder().setStringValue("action").build())
.build();
index.upsert("A", values1, null, null, metaData1, null);
index.upsert("B", values2, null, null, metaData2, null);
}
}
package main
import (
"context"
"fmt"
"log"
"github.com/pinecone-io/go-pinecone/v2/pinecone"
"google.golang.org/protobuf/types/known/structpb"
)
func main() {
ctx := context.Background()
pc, err := pinecone.NewClient(pinecone.NewClientParams{
ApiKey: "YOUR_API_KEY",
})
if err != nil {
log.Fatalf("Failed to create Client: %v", err)
}
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: "INDEX_HOST"})
if err != nil {
log.Fatalf("Failed to create IndexConnection for Host: %v", err)
}
sparseValues1 := pinecone.SparseValues{
Indices: []uint32{1, 5},
Values: []float32{0.5, 0.5},
}
sparseValues2 := pinecone.SparseValues{
Indices: []uint32{5, 6},
Values: []float32{0.4, 0.5},
}
metadataMap1 := map[string]interface{}{
"genre": "comedy",
"year": 2020,
}
metadata1, err := structpb.NewStruct(metadataMap1)
if err != nil {
log.Fatalf("Failed to create metadata map: %v", err)
}
metadataMap2 := map[string]interface{}{
"genre": "documentary",
"year": 2019,
}
metadata2, err := structpb.NewStruct(metadataMap2)
if err != nil {
log.Fatalf("Failed to create metadata map: %v", err)
}
vectors := []*pinecone.Vector{
{
Id: "vec1",
Values: []float32{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
SparseValues: &sparseValues1,
Metadata: metadata1,
},
{
Id: "vec2",
Values: []float32{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9},
SparseValues: &sparseValues2,
Metadata: metadata2,
},
}
count, err := idxConnection.UpsertVectors(ctx, vectors)
if err != nil {
log.Fatalf("Failed to upsert vectors: %v", err)
} else {
fmt.Printf("Successfully upserted %d vector(s)!\n", count)
}
}
using Pinecone;
var pinecone = new PineconeClient("YOUR_API_KEY");
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
var index = pinecone.Index(host: "INDEX_HOST");
var upsertResponse = await index.UpsertAsync(new UpsertRequest {
Vectors = new[]
{
new Vector
{
Id = "vec1",
Values = new[] { 1.0f, 1.5f },
SparseValues = new SparseValues
{
Indices = [1, 5],
Values = new[] { 0.5f, 0.5f },
},
Metadata = new Metadata {
["genre"] = new("comedy"),
["year"] = new(2020),
}
},
new Vector
{
Id = "vec2",
Values = new[] { 2.0f, 1.0f },
SparseValues = new SparseValues
{
Indices = [5, 6],
Values = new[] { 0.4f, 0.5f },
},
Metadata = new Metadata {
["genre"] = new("documentary"),
["year"] = new(2019),
},
}
},
Namespace = "example-namespace",
});
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"
curl "https://$INDEX_HOST/vectors/upsert" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2024-10" \
-d '{
"vectors": [
{
"id": "vec1",
"values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
"sparseValues": {
"indices": [2, 7],
"values": [0.4, 0.5]
},
"metadata": {
"genre": "drama"
}
},
{
"id": "vec2",
"values": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"sparseValues": {
"indices": [1, 4],
"values": [0.1, 0.2]
},
"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")
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
index = pc.Index(host="INDEX_HOST")
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"
)
// npm install @pinecone-database/pinecone
import { Pinecone } from '@pinecone-database/pinecone'
const pc = new Pinecone({ apiKey: "YOUR_API_KEY" })
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
const index = pc.index("INDEX_NAME", "INDEX_HOST")
await index.namespace('example-namespace').upsert([
{
id: 'vec1',
values: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
sparseValues: {
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],
metadata: {'genre': 'action'},
sparseValues: {
indices: [5, 6],
values: [0.4, 0.5]
}
}
])
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import io.pinecone.clients.Index;
import io.pinecone.configs.PineconeConfig;
import io.pinecone.configs.PineconeConnection;
import java.util.Arrays;
import java.util.List;
public class UpsertExample {
public static void main(String[] args) {
PineconeConfig config = new PineconeConfig("YOUR_API_KEY");
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
config.setHost("INDEX_HOST");
PineconeConnection connection = new PineconeConnection(config);
Index index = new Index(connection, "INDEX_NAME");
List<Float> values1 = Arrays.asList(0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f);
List<Float> values2 = Arrays.asList(0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f);
Struct metaData1 = Struct.newBuilder()
.putFields("genre", Value.newBuilder().setStringValue("drama").build())
.build();
Struct metaData2 = Struct.newBuilder()
.putFields("genre", Value.newBuilder().setStringValue("action").build())
.build();
index.upsert("A", values1, null, null, metaData1, null);
index.upsert("B", values2, null, null, metaData2, null);
}
}
package main
import (
"context"
"fmt"
"log"
"github.com/pinecone-io/go-pinecone/v2/pinecone"
"google.golang.org/protobuf/types/known/structpb"
)
func main() {
ctx := context.Background()
pc, err := pinecone.NewClient(pinecone.NewClientParams{
ApiKey: "YOUR_API_KEY",
})
if err != nil {
log.Fatalf("Failed to create Client: %v", err)
}
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: "INDEX_HOST"})
if err != nil {
log.Fatalf("Failed to create IndexConnection for Host: %v", err)
}
sparseValues1 := pinecone.SparseValues{
Indices: []uint32{1, 5},
Values: []float32{0.5, 0.5},
}
sparseValues2 := pinecone.SparseValues{
Indices: []uint32{5, 6},
Values: []float32{0.4, 0.5},
}
metadataMap1 := map[string]interface{}{
"genre": "comedy",
"year": 2020,
}
metadata1, err := structpb.NewStruct(metadataMap1)
if err != nil {
log.Fatalf("Failed to create metadata map: %v", err)
}
metadataMap2 := map[string]interface{}{
"genre": "documentary",
"year": 2019,
}
metadata2, err := structpb.NewStruct(metadataMap2)
if err != nil {
log.Fatalf("Failed to create metadata map: %v", err)
}
vectors := []*pinecone.Vector{
{
Id: "vec1",
Values: []float32{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
SparseValues: &sparseValues1,
Metadata: metadata1,
},
{
Id: "vec2",
Values: []float32{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9},
SparseValues: &sparseValues2,
Metadata: metadata2,
},
}
count, err := idxConnection.UpsertVectors(ctx, vectors)
if err != nil {
log.Fatalf("Failed to upsert vectors: %v", err)
} else {
fmt.Printf("Successfully upserted %d vector(s)!\n", count)
}
}
using Pinecone;
var pinecone = new PineconeClient("YOUR_API_KEY");
// To get the unique host for an index,
// see https://docs.pinecone.io/guides/manage-data/target-an-index
var index = pinecone.Index(host: "INDEX_HOST");
var upsertResponse = await index.UpsertAsync(new UpsertRequest {
Vectors = new[]
{
new Vector
{
Id = "vec1",
Values = new[] { 1.0f, 1.5f },
SparseValues = new SparseValues
{
Indices = [1, 5],
Values = new[] { 0.5f, 0.5f },
},
Metadata = new Metadata {
["genre"] = new("comedy"),
["year"] = new(2020),
}
},
new Vector
{
Id = "vec2",
Values = new[] { 2.0f, 1.0f },
SparseValues = new SparseValues
{
Indices = [5, 6],
Values = new[] { 0.4f, 0.5f },
},
Metadata = new Metadata {
["genre"] = new("documentary"),
["year"] = new(2019),
},
}
},
Namespace = "example-namespace",
});
# To get the unique host for an index,
# see https://docs.pinecone.io/guides/manage-data/target-an-index
PINECONE_API_KEY="YOUR_API_KEY"
INDEX_HOST="INDEX_HOST"
curl "https://$INDEX_HOST/vectors/upsert" \
-H "Api-Key: $PINECONE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Pinecone-Api-Version: 2024-10" \
-d '{
"vectors": [
{
"id": "vec1",
"values": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
"sparseValues": {
"indices": [2, 7],
"values": [0.4, 0.5]
},
"metadata": {
"genre": "drama"
}
},
{
"id": "vec2",
"values": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
"sparseValues": {
"indices": [1, 4],
"values": [0.1, 0.2]
},
"metadata": {
"genre": "action"
}
}
],
"namespace": "example-namespace"
}'
{"upsertedCount":2}
Authorizations
Body
application/json
Response
A successful response.
The response for the upsert operation.
The number of vectors upserted.
Example:
2
Was this page helpful?
⌘I