Traditional databases are terrible for memory retrieval. If you stored "User is allergic to shellfish" and later searched for "food restrictions," a SQL LIKE query would return nothing. Vector databases solve this.
What Is a Vector Embedding?
When you convert text to a vector embedding, you get a list of hundreds or thousands of numbers. These numbers encode the semantic meaning of the text — not just the words, but what those words mean in context.
The key insight: text with similar meaning produces vectors that are mathematically close together in high-dimensional space.
Cosine Similarity: The Core of Semantic Search
To find memories relevant to a query, you embed the query and then find stored memories whose embedding vectors are "closest" to the query vector using cosine similarity.
This is why "What can't the user eat?" correctly retrieves "User is allergic to shellfish" — their vector representations are close in semantic space, even though they share no common words.
The Performance Challenge
The challenge with vector search is scale. Finding the nearest neighbors among millions of vectors using brute force is slow. Modern vector databases like pgvector (used in memorylayer) use approximate nearest neighbor algorithms — HNSW or IVFFlat — to search millions of vectors in milliseconds.
Why This Matters for Your AI App
When you use memorylayer's search endpoint, you're getting a fully optimized vector search pipeline: text → embedding → vector search → ranked results. Each step is tuned for speed and relevance so you don't have to think about it.