6 min total

LLMs

Vector Databases: from embeddings to applications

Vector Databases: from embeddings to applications

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

LLMs — Vector Databases: from embeddings to applications

Approximating Large vector spaces

  1. Navigatable small world

Concept:

LLMs — Vector Databases: from embeddings to applications
LLMs — Vector Databases: from embeddings to applications

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.

  1. Hierarhical navigable small world (HNSW) search O(logn)
LLMs — Vector Databases: from embeddings to applications

Top layers: very few nodes (sparse overview of space)

Bottom layer (L0): all nodes, dense local connectivity

LLMs — Vector Databases: from embeddings to applications

Searching process:

  1. Start at a random high-level node.
  2. Perform greedy search: go to the neighbor closest to the query.
  3. Keep moving until no closer neighbor is found.
  4. Drop down a level and repeat.
  5. At bottom level, perform a beam search with a priority queue of candidates (up to size ef_search).
  6. Return the top-k nearest neighbors from the candidates.
ef_search: Size of candidate list during querying (higher = slower but more accurate)

Search types

  1. 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

  1. 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:

  1. Bag of words - count how many times a word occurs in query and values vector and return vector with the highest matching word frequencies
  2. Best matching 25
LLMs — Vector Databases: from embeddings to applications
  1. Hybrid search

Performs both vector/dense search then combines the results.

RAG usecases

Reduces hallucination

Enables a LLM to cite sources