> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cyborg.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Items to an Encrypted Index

Once you have created or loaded an encrypted index, you can add items to it. To do this, you can use the `upsert()` function:

<CodeGroup>
  ```python Python icon="python" theme={null}
  # 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_key is required on every data operation)
  index.upsert(items, index_key=index_key)
  ```
</CodeGroup>

<Note>Every data operation takes `index_key` as a keyword argument — the client does not cache the key across calls. You can also pass `user_id=` for an RBAC user.</Note>

## Adding Items with Contents

It's also possible to store item contents alongside vectors. To do this, include `contents` to the `upsert()` call.

The contents field accepts both strings and bytes. All contents are encoded to bytes and encrypted before storage using the index key, and will be returned as bytes when retrieved with `get()`.

<CodeGroup>
  ```python Python icon="python" theme={null}
  # 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, index_key=index_key)
  ```
</CodeGroup>

## 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.

<CodeGroup>
  ```python Python icon="python" theme={null}
  # 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, index_key=index_key)
  ```
</CodeGroup>

For more info on metadata storage and filtering, see [Metadata Filtering](./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:

```python Python icon="python" theme={null}
# ... index creation and embedding model setup
embedding_model = "all-MiniLM-L6-v2"
index = client.create_index(
    index_name="my_index",
    index_key=index_key,
    embedding_model=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, index_key=index_key)
```

In this example, the `embedding_model` will automatically generate embeddings for the `contents` field. Note that `contents` must be a string. It will also be converted to `bytes` for encrypted item storage.

Embeddings are generated by CyborgDB's built-in embedding models; no extra package is needed. `embedding_model` must name one of them. List them with `cyborgdb.supported_embedding_models()`; the bare model name (without the organization prefix) is also accepted, so `"all-MiniLM-L6-v2"` works.

## API Reference

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

<CardGroup cols={2}>
  <Card title="Python API Reference" href="../../python/encrypted-index/upsert" icon="python">
    API reference for `upsert()` in Python
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.