Grounding LLMs: tying the outputs of LLMs to real world data so that models responses are not just statistically likely but also factually accurate 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 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. 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: 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. 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 LLMs — Vector Databases: from embeddings to applications Hybrid search Performs both vector/dense search then combines the results. RAG usecases Reduces hallucination Enables a LLM to cite sources KV caching LLMs — Efficiently serving LLMs LLMs — Efficiently serving LLMs When generating a token naïve way would be to reprocess all previous tokens to compute new K and V for self-attention With KV caching, the model stores the computed K and V tensors for previous tokens in GPU memory as a cache, when generating the next token, it only computes Q for new token and reuses all stored K and V values. Batching Multiple input sequences come in (e.g., from users). Each sequence may be at a different stage (some might be longer, others shorter). You pad them to the same length (or use advanced batching logic). Run the model on all sequences in parallel. LLMs — Efficiently serving LLMs LLMs — Efficiently serving LLMs — notes LLMs — Efficiently serving LLMs LLMs — Efficiently serving LLMs Continuous Batching Requests come in asynchronously. To batch them: Maintain a request queue. Every few milliseconds (e.g. 10ms), collect as many requests as possible. Combine them into a batch. Run a single forward pass on the batch. But this flexibility needs smart batching strategies — especially when some sequences finish earlier than others, or when some can't be batched together. That’s where filtering comes in. LLMs — Efficiently serving LLMs Filtering batching refers to: 💡 "Choosing which sequences in the current batch should participate in the next forward pass." It filters out sequences that: Are already done (e.g., have generated an EOS token) Don’t need more tokens now (e.g., waiting for user input or throttled) Would slow down the batch because of incompatibility (e.g., different decoding strategies like greedy vs sampling) LLMs — Efficiently serving LLMs Quantization LLMs — Efficiently serving LLMs Low Rank Adaptation Parameter efficient fine tuning method LoRA freezes original model weights and learns a tiny low rank update matrices that are injected during training "why update the entire piano when you just want to retune a few strings?" LLMs — Efficiently serving LLMs…