liveBook · Manning

Embedding

As explained in Introduction to Generative AI, Second Edition

An embedding is a numerical internal representation of data that captures features useful for computational processing.

How can a chatbot find the right policy document when someone asks a question in different words? An embedding helps turn text into a numerical representation that can be compared with others. A word embedding places words in a space where words used similarly tend to be close together. Document embeddings can serve a similar purpose for longer text. section 1.12 section 8.13

Nearby words

“Cucumber” and “pickle” may appear close together in a word-embedding space, while “cucumber” and “philosophy” appear farther apart. Unlike assigning each word an arbitrary numerical point, an embedding captures patterns related to meaning. section 1.12

Figure 1.4 Representation of word embeddings in the vector space
A white rectangular object with black background

AI-generated content may be incorrect.

The figure illustrates the idea of representing words as positions in a space. section 1.12

Embeddings are also used in retrieval-augmented generation (RAG). Documents are converted into vectors and may be stored in a vector database. A question is converted into a vector too; nearby documents are retrieved and placed in the language model’s context. This can help when the relevant information cannot all fit into that context, but it depends on the embeddings bringing back useful documents. section 8.13

Finding a travel policy

An employee asks whether a premium-economy ticket for a five-hour sales trip is reimbursable. A chatbot could retrieve the most similar travel-policy documents and use their wording to answer, rather than relying only on information already in the model’s context. section 8.13

A meaningful numerical representation is not necessarily a neutral one. Word embeddings trained on news text have exhibited gender stereotypes about occupations and descriptions. Embeddings can also complicate privacy rights: after personal data has been transformed into internal representations, identifying or removing one person’s contribution may be technically infeasible. How existing data-protection rights apply to models remains contested. section 1.12 section 3.15

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Defines embeddings through spatial similarity and walks through document retrieval, without detailing how vectors are calculated.
Examples
Uses cucumber–pickle proximity, gender-stereotyped word analogies, and a chatbot retrieving a company travel policy.
What it assumes
Introduces numerical word representations without assuming knowledge of how embeddings are calculated.
What you can do after
Evaluate/understand why embedding-based retrieval may find relevant documents and why its representations warrant scrutiny for bias.
How it connects
Connects embeddings to language models, semantic similarity, vector databases, retrieval-augmented generation, bias, and data privacy.

Also explained in

Compare how 47 books explain embedding →

Related concepts

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