Once you have created or connected to an encrypted index, you can add items to it. To do this, you can use the upsert() function:
# Items to add to the encrypted index
items = [
    {"id": "item_1", "vector": [0.1, 0.2, 0.3, 0.4]},
    {"id": "item_2", "vector": [0.5, 0.6, 0.7, 0.8]},
    {"id": "item_3", "vector": [0.9, 0.10, 0.11, 0.12]}
]

# Add items to the encrypted index
index.upsert(items)

Adding Items with Contents

It’s also possible to store item contents alongside vectors. To do this, include contents in the upsert() call. The contents field will be encrypted using the index key.
# Items to add to the encrypted index
items = [
    {"id": "item_1", "vector": [0.1, 0.2, 0.3, 0.4], "contents": "Hello!"},
    {"id": "item_2", "vector": [0.5, 0.6, 0.7, 0.8], "contents": "World!"},
    {"id": "item_3", "vector": [0.9, 0.10, 0.11, 0.12], "contents": "Cyborg!"}
]

# Add items to the encrypted index
index.upsert(items)

Adding Items with Metadata

CyborgDB also supports metadata storage, retrieval and filtering. To add metadata to an item, include metadata in the upsert() call. All metadata fields will be encrypted using the index key.
# Items to add to the encrypted index
items = [
    {"id": "item_1", "vector": [0.1, 0.2, 0.3, 0.4], "metadata": {"name": "Alice", "age": 30}},
    {"id": "item_2", "vector": [0.5, 0.6, 0.7, 0.8], "metadata": {"name": "Bob", "age": 40}},
    {"id": "item_3", "vector": [0.9, 0.10, 0.11, 0.12], "metadata": {"name": "Charlie", "age": 50}}
]

# Add items to the encrypted index
index.upsert(items)
For more info on metadata storage and filtering, see Metadata Filtering.

Automatic Embedding Generation

If you provided an embedding_model during index creation, you can automatically generate embeddings for items by providing contents to the upsert() call:
# ... index creation and embedding model setup
embedding_model = "sentence-transformers/all-MiniLM-L6-v2"
index = client.create_index("my_index", index_key, index_config, embedding_model)

# Items to add to the encrypted index
items = [
    {"id": "item_1", "contents": "Hello, World!"},
    {"id": "item_2", "contents": "Hello, Cyborg!"}
]

# Add items to the encrypted index
index.upsert(items)
In this example, the embedding_model will automatically generate embeddings for the contents field. The contents will also be stored alongside the generated embeddings. This feature uses various embedding models available through the service. You can use any model supported by the CyborgDB service, including models from the HuggingFace Model Hub.

API Reference

For more information on adding items to an encrypted index, refer to the API reference: