The upsert method enables you to insert or update vectors in the index.
You can perform upsert operations in three ways: using a vector object, a tuple, or a dictionary.
import randomfrom upstash_vector import Index, Vectorindex = Index.from_env()dimension = 128 # Adjust based on your index's dimensionupsert_amount = 100vectors = [ Vector( id=f"generated-id-{i}", vector=[random.random() for _ in range(dimension)], metadata={"some_field": f"some_value-{i}"}, data=f"some-unstructured-data-{i}", ) for i in range(upsert_amount)]index.upsert(vectors=vectors)
import randomfrom upstash_vector import Indexindex = Index.from_env()dimension = 128 # Adjust based on your index's dimensionupsert_amount = 100vectors = [ ( f"generated-id-{i}", [random.random() for _ in range(dimension)], {"some_field": f"some_value-{i}"}, f"some-unstructured-data-{i}", ) for i in range(upsert_amount)]index.upsert(vectors=vectors)
import randomfrom upstash_vector import Indexindex = Index.from_env()dimension = 128 # Adjust based on your index's dimensionupsert_amount = 100vectors = [ { "id": f"generated-id-{i}", "vector": [random.random() for _ in range(dimension)], "metadata": {"some_field": f"some_value-{i}"}, "data": f"some-unstructured-data-{i}", } for i in range(upsert_amount)]index.upsert(vectors=vectors)
Also, you can specify a namespace to operate on. When no namespace
is provided, the default namespace will be used.