| name | vector-db-elixir |
| description | Design and implement a vector database in Elixir. Use when building embedding storage, similarity search, k-NN retrieval, or when the user mentions vector DB, embeddings, or semantic search in Elixir. |
Vector Database in Elixir
Scope
A vector DB stores high-dimensional vectors (embeddings) and supports similarity search: find the k nearest vectors to a query vector by distance (cosine, Euclidean, dot product).
Core Operations
| Operation | Description |
|---|
| insert | Add vector(s) with optional metadata (id, payload) |
| search | Query vector → return k nearest vectors (by similarity) |
| delete | Remove by id or filter |
| get | Fetch by id (optional) |
Implementation Workflow
-
Choose storage backend
- In-memory: ETS (fast, no persistence)
- Persistent: file (binary/term), or PostgreSQL with pgvector
- External: Qdrant client
-
Choose distance metric
- Cosine similarity (often for normalized embeddings)
- Euclidean (L2)
- Dot product (when vectors already normalized, equivalent to cosine)
-
Implement or wire
- Exact k-NN: compute distance to every vector (fine for < ~100k vectors in memory)
- Approximate: use pgvector indexes (IVFFlat, HNSW) or external engine for scale
-
Expose API
- GenServer or dedicated context module:
insert/2, search/2, delete/1
- Optional HTTP/Web API on top
Elixir Stack (Typical)
- Nx or Scholar for vector math (cosine, L2, dot product)
- GenServer + ETS or :array for in-memory index
- pgvector + Ecto for persistent, indexed storage
- Application supervision tree to start the vector store process
Design Checklist
Additional Resources