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

# Vectorize

> Store embeddings and run bounded similarity search from a Worker.

Vectorize is a named Durable Object with vector CRUD, namespace and metadata
filtering, and similarity search. Create an index with fixed dimensions and one
metric: `cosine`, `euclidean`, or `dot-product`.

## Bind an index

```jsonc theme={null}
{
  "vectorize": [
    { "binding": "DOCUMENTS", "index_name": "product-docs" }
  ]
}
```

## Insert or update vectors

```js theme={null}
await env.DOCUMENTS.upsert([
  {
    id: "doc-42",
    values: embedding,
    namespace: "guides",
    metadata: { title: "Deploy a Worker", locale: "en" },
  },
]);
```

`insert` preserves an existing ID; `upsert` fully replaces it. The mutation is
visible when the promise resolves.

## Query

```js theme={null}
const result = await env.DOCUMENTS.query(queryEmbedding, {
  topK: 5,
  namespace: "guides",
  returnMetadata: "all",
  filter: { locale: "en" },
});
```

You can also search using a stored vector:

```js theme={null}
const similar = await env.DOCUMENTS.queryById("doc-42", { topK: 5 });
```

## Complete API

| Method | Purpose |
| - | - |
| `insert(vectors)` | Add IDs without replacement |
| `upsert(vectors)` | Add or replace IDs |
| `query(vector, options)` | Find nearest vectors |
| `queryById(id, options)` | Use an existing vector as the query |
| `getByIds(ids)` | Fetch complete vectors |
| `deleteByIds(ids)` | Remove vectors |
| `describe()` | Inspect immutable index configuration and progress |

Requests accept ordinary arrays, `Float32Array`, or `Float64Array`. Query
`topK` is between 1 and 100; batch ID operations accept at most 1,000 IDs.

<Note>
  Vectorize performs exact native Turso similarity search. A query with more than
  10,000 eligible rows fails explicitly instead of silently switching to an
  approximate or remote index.
</Note>


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