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

# Build an index and search vectors

> Prepare embeddings, build a vector index, and verify a nearest-neighbor query.

Use this workflow when your data already includes embeddings and you want to retrieve the closest matches to a query vector.

## 1. Prepare the embeddings

Store the embeddings in an `ARRAY<FLOAT> NOT NULL` column. Make sure the stored and query vectors have the same dimension, and check the [vector index requirements for this version](/documents/4.2/table_design/indexes/vector_index.md).

## 2. Create the vector index

Choose a metric such as L2 distance or cosine similarity and set the index dimension to match your embeddings. Use the [index creation examples](/documents/4.2/table_design/indexes/vector_index.md#create-vector-index) for a new table or the [ADD INDEX example](/documents/4.2/table_design/indexes/vector_index.md#append-vector-index) for an existing table. After creating the index, use [SHOW CREATE TABLE](/documents/4.2/sql-reference/sql-statements/table_bucket_part_index/SHOW_CREATE_TABLE.md) to confirm its definition.

## 3. Run a top-k query

Put the function for your index metric in `ORDER BY`, then use `LIMIT` to set how many matches to return. Sort `approx_l2_distance` in ascending order or `approx_cosine_similarity` in descending order. Check the [requirements for indexed queries](/documents/4.2/table_design/indexes/vector_index.md#requirements-for-vector-index-based-queries) for restrictions on expressions and predicates.

## 4. Verify index usage

Run [EXPLAIN](/documents/4.2/sql-reference/sql-statements/cluster-management/plan_profile/EXPLAIN.md) on the query and look for `VECTORINDEX: ON` in the scan node. Use the [vector index examples](/documents/4.2/table_design/indexes/vector_index.md) to test recall or tune search parameters on representative queries.


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