Vector Databases
Pre 2013: Early work on vector similarity exists but no Vector dbs
2013 - 2017: Word2Vec and GloVe made vector representations widely used, vector search began to grow
2017 - 2018: FAISS (Facebook AI Similarity Search) was the first scalable vector similarity tool, it lacked vector db too
2019 - 2021: Milvus was the first open source vector database with DBMS features. Weavite added semantic search. Pinecone launched 2021
Popular Similarity methods
Cosine similarity
Euclidean distance
Manhattan distance
Dot product
Jaccard similarity

Approximating Large vector spaces
- Navigatable small world
Concept:


Nodes: vectors
Edges: connections to nearby nodes
You can navigate from one node to another by following short paths. Vector search in high-dim is expensive, NSW lets you approximate nearest neighbors quickly by traversing a sparse graph instead of scanning the whole dataset.
For each point connect it to a k nearest neighbors
The connections form a "small-world network" a graph where most nodes are not neighbors, but most nodes can be reached from every other by a small number of steps.
- Hierarhical navigable small world (HNSW) search O(logn)

Top layers: very few nodes (sparse overview of space)
Bottom layer (L0): all nodes, dense local connectivity

Searching process:
- Start at a random high-level node.
- Perform greedy search: go to the neighbor closest to the query.
- Keep moving until no closer neighbor is found.
- Drop down a level and repeat.
- At bottom level, perform a beam search with a priority queue of candidates (up to size ef_search).
- Return the top-k nearest neighbors from the candidates.
| ef_search: Size of candidate list during querying (higher = slower but more accurate) |
Search types
- Dense search (semantic search)
Uses vector embeddings to perform search, allows us to capture and return semantically similar objects
If model was trained on a different dataset, it will provide poor accuracy on our dataset's semantic
Searching with random data (like serial numbers) will also yield poor results
- Sparse search (keyword search)
We match exact string matching.
Text is embedded into vectors by counting how many times each unique word occurs for a document. That vector will have many zeroes because it doesn’t contains each unique word.
Approaches:
- Bag of words - count how many times a word occurs in query and values vector and return vector with the highest matching word frequencies
- Best matching 25

- Hybrid search
Performs both vector/dense search then combines the results.
RAG usecases
Reduces hallucination
Enables a LLM to cite sources