Inserting and Updating Vectors: Upsert Operations
In Pinecone, you do not write traditional SQL INSERT commands. Instead, you perform Upsert operations. If a vector with the provided ID already exists, it is updated; otherwise, a new record is created.
1. Structuring the Vector Payload
Every record inserted into Pinecone contains:
- id: A unique string identifier.
- values: An array of decimal numbers representing the vector embedding.
- metadata: An optional JSON object containing data fields (such as text content or categories).
2. Executing an Upsert Operation
To upload vector records, reference your target index and call the .upsert() method:
import { pc } from "../lib/pinecone";
async function populateIndex() {
const index = pc.index("knowledge-base");
console.log("Preparing vector payloads...");
const records = [
{
id: "doc_1",
values: [0.015, -0.024, 0.089, 0.012], // Reduced dimension representation
metadata: {
title: "Introduction to React",
category: "frontend",
lines: 45,
},
},
{
id: "doc_2",
values: [-0.008, 0.045, -0.012, 0.096],
metadata: {
title: "State Management with Zustand",
category: "frontend",
lines: 32,
},
},
];
await index.upsert(records);
console.log("Vectors uploaded successfully!");
}3. Data Type Constraints
- ID size: Maximum of 64 characters.
- Vector values: Must match the dimensions defined when the index was created.
- Metadata size: Maximum of 40KB per vector record.
Published on Last updated: