# Vector search

Store vectors and retrieve nearest records using SQL distance operators.

Source: https://particledb.ai/sql/vector-search/

Store vectors and retrieve nearest records using SQL distance operators.

## Example

```sql
CREATE TABLE docs_vectors (id BIGINT PRIMARY KEY, content TEXT, embedding VECTOR(3));
INSERT INTO docs_vectors VALUES (1, 'First', '[1,0,0]'), (2, 'Second', '[0,1,0]');
```

```sql
SELECT id, content FROM docs_vectors
ORDER BY embedding <-> '[1,0,0]' LIMIT 2;
```

## Behavior

Record 1 is nearest under Euclidean distance. Stored and query vectors must use the same embedding model and dimensions. `` is Euclidean distance and `` is cosine distance. Approximate indexes trade retrieval quality against resources and latency; measure both. Use relational filters to scope candidates, with authorization enforced by the application.

## Related

[SQL reference](/sql/overview/) · [Application guide](/guides/relational-data/) · [Troubleshooting](/guides/troubleshooting/)
