# Search and memory

Store vectors beside records and combine similarity search with application filters.

Source: https://particledb.ai/guides/search-and-memory/

An embedding is a numeric vector produced by an embedding model. Generate stored embeddings and query embeddings with the same model and dimensions.

The small vectors below illustrate query behavior. They are not outputs from an embedding model.

## Store records with vectors

```sql
CREATE TABLE knowledge (
  id BIGINT PRIMARY KEY,
  account_id BIGINT,
  content TEXT,
  embedding VECTOR(3)
);
INSERT INTO knowledge VALUES
  (1, 7, 'Deployment guide', '[1,0,0]'),
  (2, 7, 'API reference', '[0,1,0]'),
  (3, 9, 'Private account note', '[1,0,0]');
```

## Retrieve context for one account

```sql
SELECT id, content
FROM knowledge
WHERE account_id = 7
ORDER BY embedding <-> '[1,0,0]'
LIMIT 2;
```

The deployment guide ranks first. Record 3 is excluded by the account filter.

A filter is part of your query, not a complete authorization system. Derive the account scope from authenticated application identity and enforce it on every access path. [Security](/guides/security/).

## Add an index for larger data

Choose a supported index and distance metric using the [vector reference](/sql/vector-search/). Measure retrieval quality and latency on representative embeddings before choosing index parameters.

## Next steps

[Vector search reference](/sql/vector-search/) · [Full-text search](/sql/full-text-search/) · [Agent patterns](/guides/agents-and-workflows/)
