Introduction
In Pinecone, there are two APIs available for updating vector data: upsert
, which performs full updates, and update
, which performs partial updates. This article explains the distinction between these APIs.
Creating an Index
Execute the following commands or code to create an index in Pinecone.
bash
$ pip install -U pinecone-client
python
import pinecone
pinecone.init(
api_key="API_KEY",
environment="ENVIRONMENT"
)
if "sample" not in pinecone.list_indexes():
pinecone.create_index("sample", dimension=1536)
index = pinecone.Index("sample")
Adding Data
Register vector data.
python
index.upsert(
vectors=[{
"id": "1",
"values': [0.0] * 1536,
"metadata": {
"content": "This is a sample vector"
}
}],
namespace='my_namespace'
)
res = index.fetch(
ids=["1"],
namespace="my_namespace"
)
print(res["vectors"]["1"]["metadata"])
{'content': 'This is a sample vector'}
Updating Data
To update data, you can specify the id
using the update
or upsert
API. When using upsert
, it can be done as follows:
python
index.upsert(
vectors=[{
"id": "1",
"values": [0.0] * 1536,
"metadata": {
"content": "Updated"
}
}],
namespace="my_namespace"
)
res = index.fetch(
ids=["1"],
namespace="my_namespace"
)
print(res["vectors"]["1"]["metadata"])
{'content': 'Updated'}
Creating vectors consumes computing resources. If vector regeneration is unnecessary, it is advisable to use update
to update only the metadata
.
python
index.update(
id="1",
setMetadata={
"content": "Only metatada updated"
},
namespace="my_namespace"
)
res = index.fetch(
ids=["1"],
namespace="my_namespace"
)
print(res["vectors"]["1"]["metadata"])
{'content': 'Only metatada updated'}
AlloyDB
Amazon Cognito
Amazon EC2
Amazon ECS
Amazon QuickSight
Amazon RDS
Amazon Redshift
Amazon S3
API
Autonomous Vehicle
AWS
AWS API Gateway
AWS Chalice
AWS Control Tower
AWS IAM
AWS Lambda
AWS VPC
BERT
BigQuery
Causal Inference
ChatGPT
Chrome Extension
CircleCI
Classification
Cloud Functions
Cloud IAM
Cloud Run
Cloud Storage
Clustering
CSS
Data Engineering
Data Modeling
Database
dbt
Decision Tree
Deep Learning
Descriptive Statistics
Differential Equation
Dimensionality Reduction
Discrete Choice Model
Docker
Economics
FastAPI
Firebase
GIS
git
GitHub
GitHub Actions
Google
Google Cloud
Google Search Console
Hugging Face
Hypothesis Testing
Inferential Statistics
Interval Estimation
JavaScript
Jinja
Kedro
Kubernetes
LightGBM
Linux
LLM
Mac
Machine Learning
Macroeconomics
Marketing
Mathematical Model
Meltano
MLflow
MLOps
MySQL
NextJS
NLP
Nodejs
NoSQL
ONNX
OpenAI
Optimization Problem
Optuna
Pandas
Pinecone
PostGIS
PostgreSQL
Probability Distribution
Product
Project
Psychology
Python
PyTorch
QGIS
R
ReactJS
Regression
Rideshare
SEO
Singer
sklearn
Slack
Snowflake
Software Development
SQL
Statistical Model
Statistics
Streamlit
Tabular
Tailwind CSS
TensorFlow
Terraform
Transportation
TypeScript
Urban Planning
Vector Database
Vertex AI
VSCode
XGBoost