liveBook · Manning

Embedding

As explained in AI Agents in Action, Second Edition

A dense vector is a numerical vector in which the representation generally assigns a value to every dimension.

An embedding represents text as a dense vector: a list of numbers produced by an embedding model. Unlike a sparse vector, which is mostly zeros, a dense vector generally assigns a value to every dimension. Text with related meanings tends to have nearby vector representations, making embeddings useful for finding relevant passages even when their words differ. A typical text embedding has 384 to 3,072 floating-point values, depending on the model. section 6.1.1 section 6.2.1

Consider a search for “vehicles” when a document says “cars.” TF-IDF represents the terms that appear, so it may miss that match. An embedding can capture the relationship in meaning. The trade-off runs both ways: for a specific name, code, or rare keyword, exact-term search can be faster, more predictable, and more accurate. Hybrid retrieval combines keyword and embedding searches rather than treating either as sufficient for every query. section 6.1.3 section 6.2.1

An embedding-based retrieval workflow has two phases:

  • Ingestion: split documents into context chunks, embed them, and store their vectors in a searchable database. section 6.1.1
  • Retrieval: embed the query, find similar stored chunks, and add those chunks to the prompt. The embedding model finds context; the LLM produces the answer. section 6.1.1
Figure 6.2 RAG can be broken into two phases: ingestion and retrieval. First, documents are loaded, transformed, embedded, and stored in a searchable datastore. Second, they can be retrieved using query mechanisms as part of context augmentation.

The ingestion-and-retrieval diagram shows where document and query embeddings enter the same search workflow. section 6.1.1

From text to inspectable vectors

A Python example calls an OpenAI embedding model for each document, collects the returned vectors in an array, and reduces them to three dimensions with PCA for visualization. The plot makes relationships between similar documents easier to inspect; the stored embeddings remain the full vectors returned by the model. section 6.2.1

Similarity is not a truth check. A close match can contain incorrect or outdated information; a fixed top-K cutoff can omit a useful passage; and approximate search can miss an expected match. Compare retrieved passages with the question, tune the number of results when needed, and use keyword or other retrieval methods where semantic search misses exact facts. Ground answers in the passages actually retrieved. section 6.1.2 section 6.6

How AI Agents in Action, Second Edition covers it

How deep it goes
Explains vector size, semantic proximity, and retrieval steps; sketches model training without deriving neural-network internals.
Examples
Uses vehicle-versus-car matching, document-vector visualization, and exercises comparing TF-IDF rankings with OpenAI embeddings.
What it assumes
Builds from a simpler TF-IDF vector example; assumes a working Python environment for the code exercises.
What you can do after
Apply it via OpenAI embeddings and Chroma DB to compare similarities, persist vectors, and retrieve context for a RAG agent.
How it connects
Connects embeddings to TF-IDF, cosine similarity, vector databases, RAG, memory retrieval, and hybrid search.

Also explained in

Compare how 47 books explain embedding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.