RAG basics: embeddings, chunks, vector databases and cosine similarity
RAG combines a retriever with a generator: the query is converted into a vector, matched against the document index, and the relevant chunks are supplied as context to an LLM. [S1]
Embeddings and semantic search
Embeddings are numerical representations of data, also known as vectors, and can be used for semantic search. [S2]
Semantic search uses the meaning of the words in a query to return relevant results. [S2]
Cosine similarity measures the cosine of the angle between two vectors, so documents far apart by Euclidean distance because of size can still have a small angle. [S2]
The RAG pipeline
Documents in the knowledge base are ingested, broken into smaller chunks, transformed into text embeddings and stored in a database. [S1]
Because LLMs have a limit on the number of input tokens, documents are split into chunks before embedding them. [S1]
A vector database is a specialized database designed to store, manage and search embedded vectors. [S1]
The lesson chunks transcripts into 3 minute segments with about 20 words overlapping the next segment, so the embedding is not cut off. [S2]
Why it helps
RAG reduces fabrication by using verifiable data in the knowledge base to provide context to user queries. [S1]
Claims
- id: C1 claim: "RAG combines a retriever with a generator." source: S1 evidence: "RAG combines a retriever with a generator"
- id: C2 claim: "Documents are chunked because of input token limits." source: S1 evidence: "Because LLMs have a limit on the number of input tokens"
- id: C3 claim: "A vector database stores, manages and searches embedded vectors." source: S1 evidence: "designed to store, manage and search embedded vectors"
- id: C4 claim: "Semantic search uses the meaning of query words." source: S2 evidence: "uses the semantics, or meaning, of the words in a query"
- id: C5 claim: "Cosine similarity measures the angle between two vectors." source: S2 evidence: "measures the cosine of the angle between two vectors"
Sources
- [S1] Retrieval Augmented Generation (RAG) and Vector Databases. Microsoft Generative AI for Beginners (GitHub). https://github.com/microsoft/generative-ai-for-beginners/blob/main/15-rag-and-vector-databases/README.md MIT; accessed 2026-11-05.
- [S2] Building Search Applications. Microsoft Generative AI for Beginners (GitHub). https://github.com/microsoft/generative-ai-for-beginners/blob/main/08-building-search-applications/README.md MIT; accessed 2026-11-05.
Attribution: source authors named above; adapted summaries, not endorsed by them. MIT notices: Copyright (c) Microsoft Corporation, MIT License.
License: CC-BY-4.0 · Adapted summaries of the named sources below; wording and synthesis by Librarian.
Cite this
Librarian. 2026. "RAG basics: embeddings, chunks, vector databases and cosine similarity." iinventedlight Library, iil:note:h9m6jy44, version of 2026-11-05. https://iinventedlight.com/library/notes/genai-rag-embeddings-vector-search/. License: CC-BY-4.0.
@misc{iil_note_h9m6jy44,
author = {{Librarian}},
title = {{RAG basics: embeddings, chunks, vector databases and cosine similarity}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-05},
url = {https://iinventedlight.com/library/notes/genai-rag-embeddings-vector-search/},
note = {Permanent ID iil:note:h9m6jy44. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/genai-rag-embeddings-vector-search.md.