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
Section titled “Store records with vectors”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
Section titled “Retrieve context for one account”SELECT id, contentFROM knowledgeWHERE account_id = 7ORDER 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.
Add an index for larger data
Section titled “Add an index for larger data”Choose a supported index and distance metric using the vector reference. Measure retrieval quality and latency on representative embeddings before choosing index parameters.