> For the complete documentation index, see [llms.txt](https://docs.envector.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.envector.io/1.4.x/sdk-user-guide/insert.md).

# Insert

## Inserting Data into Index

There are multiple ways to insert data into an index:

* Plaintext vectors (with automatic index encryption)
* Pre-encrypted vectors (CipherBlock)
* Vectors with metadata

⚠️ **Note:** Since the index metric is *inner product (IP)*, vectors must be normalized before insertion. Normalization ensures that similarity scores reflect cosine similarity rather than raw magnitude differences.

***

## 1. Inserting Plaintext (with Index Encryption)

You can insert plaintext vectors in bulk using `list[list[float]]`, `list[np.ndarray]`, or a 2D `numpy.ndarray`.\
If `index_encryption` is enabled in the index configuration, the vectors will be automatically encrypted before insertion.\
For detailed configuration, refer to *Index Configuration*.

Example

```python
import numpy as np
import pyenvector as ev

ev.init(address="localhost:50050", key_path="keys", key_id="example")

index = ev.create_index("example_index", dim=512)

vecs = np.random.rand(100, 512)
# vecs = [[0.001, 0.02, ..., 0.127]] # List[List[float]]
# vecs = [np.random.rand(512)] * 100 # List[np.ndarray]

# Normalize vectors before insertion (required for inner product metric)
vecs = vecs / np.linalg.norm(vecs, axis=1, keepdims=True)

index.insert(vecs)
# Output: 
# Index(
#    IndexConfig(
#        index_name="example_index",
#        dim=512,
#        key_path='keys',
#        key_id='example',
#    ),
#  num_entities=100,
#  cipher=<pyenvector.crypto.cipher.Cipher object at 0x7f1776199d60>
#)
        
```

## 2. Inserting with Metadata

You can insert vectors together with metadata.\
Metadata should be provided as a list of strings. If `metadata_encryption=True` is enabled in the index configuration, the metadata will be encrypted before being stored.

Example

<pre class="language-python"><code class="lang-python">import numpy as np
import pyenvector as ev

ev.init(address="localhost:50050", key_path="keys", key_id="example")

index = ev.create_index("example_index", dim=512)

vecs = np.random.rand(100, 512)
# Normalize vectors for inner product metric
vecs = vecs / np.linalg.norm(vecs, axis=1, keepdims=True)

metadatas = [f"metadata_{i}" for i in range(100)]

index.insert(vecs, metadata=metadatas)
# Output: 
# Index(
#    IndexConfig(
<strong>#        index_name="example_index",
</strong>#        dim=512,
#        key_path='keys',
#        key_id='example',
#    ),
#  num_entities=100,
#  cipher=&#x3C;pyenvector.crypto.cipher.Cipher object at 0x7f1776199d60>
#)
</code></pre>

***

## When Does Inserted Data Become Searchable?

By default, `Index.insert()` submits both the **ingest** and **indexing** stages and loads the result, so the data becomes searchable soon after the call returns. For high-throughput pipelines, you can defer indexing with `execute_until="flush"` and trigger it later via `Index.indexing()` — see [Index Operation Lifecycle](/1.4.x/sdk-user-guide/advanced-user-guide/index-operation-lifecycle.md) for the full lifecycle and `await_completion` options.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.envector.io/1.4.x/sdk-user-guide/insert.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
