0Pricing
LangChain / RAG / Vector DBs · Lesson

Embeddings and Vector Databases

Understand how text embeddings turn meaning into vectors and how vector databases enable the retrieval step at the heart of RAG.

Embeddings and Vector Databases is a free LangChain / RAG / Vector DBs lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the LangChain / RAG / Vector DBs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

From Words to Vectors

Computers cannot compare meaning directly. An embedding is a vector of numbers representing a text’s meaning, so similar texts land close together.

What an Embedding Looks Like

An embedding model maps text to a fixed-length vector with hundreds or thousands of dimensions. The numbers are not readable — what counts is their geometric relationships.

text = 'a cup of coffee'
embedding = [0.12, -0.04, 0.88, 0.31]  # simplified
print('dimensions:', len(embedding))

Semantic Similarity

Because meaning maps to position, "dog" sits near "puppy" but far from "database". That is what powers semantic search — matching by meaning, not exact keywords.

Measuring Closeness

The go-to closeness metric is cosine similarity — the cosine of the angle between two vectors. 1 means nearly identical, 0 means unrelated.

def cosine(a, b):
    dot = sum(x*y for x, y in zip(a, b))
    na = sum(x*x for x in a) ** 0.5
    nb = sum(y*y for y in b) ** 0.5
    return dot / (na * nb)

print(round(cosine([1, 0, 1], [1, 0, 1]), 2))
print(round(cosine([1, 0, 0], [0, 1, 0]), 2))

Why a Vector Database?

RAG must find the most relevant chunks among millions of vectors, fast. A vector database stores embeddings and finds nearest neighbors — something SQL is not built for.

Approximate Nearest Neighbor

Comparing a query to every vector is too slow at scale. Vector DBs use ANN indexes like HNSW that trade a sliver of accuracy for huge speed gains.

Indexing Documents

To build a knowledge base, index your docs: split into chunks, embed each one, and store the vector with its text and metadata. This is RAG’s offline ingestion step.

chunks = ['intro paragraph', 'pricing details', 'support hours']
for c in chunks:
    vec = embed(c)        # call embedding model
    db.upsert(vec, text=c)

Querying

At query time, embed the user’s question with the same model, then ask the vector DB for the top-k nearest chunks — that becomes the LLM’s context.

q_vec = embed('when is support open?')
results = db.search(q_vec, top_k=3)
for r in results:
    print(r.text, r.score)

Metadata Filtering

Vector DBs also support metadata filtering: combine similarity search with filters like language, date range, or owner to sharpen relevance.

db.search(q_vec, top_k=3, filter={'lang': 'en', 'year': 2026})

Choosing a Vector Store

Your vector store options span libraries (FAISS), dedicated DBs (Pinecone, Weaviate, Qdrant, Milvus), and extensions like pgvector. Pick by scale, hosting, and data needs.

Embeddings in the RAG Pipeline

Embeddings and the vector DB are the retrieval half of RAG: index once, then for every question embed, search, and hand the top chunks to the LLM as grounding.

Quick Check

Test your understanding of embeddings and vector search.

Recap

You learned RAG’s retrieval foundation: embeddings turn meaning into vectors, cosine measures closeness, and vector DBs use ANN for fast nearest-neighbor search.

Frequently asked questions

Is the “Embeddings and Vector Databases” lesson free?

Yes — the full text of “Embeddings and Vector Databases” is free to read here on the web, and the LangChain / RAG / Vector DBs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the LangChain / RAG / Vector DBs course, upgrade to CoddyKit PRO.

What will I learn in “Embeddings and Vector Databases”?

Understand how text embeddings turn meaning into vectors and how vector databases enable the retrieval step at the heart of RAG. You practise LangChain / RAG / Vector DBs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start LangChain / RAG / Vector DBs?

No prior experience is required. LangChain / RAG / Vector DBs on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Embeddings and Vector Databases” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this LangChain / RAG / Vector DBs lesson?

Yes. Every LangChain / RAG / Vector DBs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What are Large Language Models?
  2. The Need for Retrieval Augmented Generation
  3. Core Components of a RAG System
  4. Embeddings and Vector Databases
← Back to LangChain / RAG / Vector DBs