liveBook · Manning

Embedding

As explained in Build Python Web Apps with Streamlit

A text embedding is a numerical vector representation of text that captures features useful for semantic comparison.

A customer-service chatbot may need an answer from a company support article, not just from an LLM’s pre-trained knowledge. An embedding turns a piece of text into a vector—a list of numbers—so the app can search for relevant content by similarity. In retrieval-augmented generation (RAG), that search helps select context to give the LLM alongside the customer’s question. section 10.7 section 10.5.1

Think of recommending a movie

Imagine rating movies on two scales: comedic value and explosions per hour. A movie rated 1.2 and 6 becomes the vector [1.2, 6]. Plotting such vectors makes similarity easier to picture. Text embeddings serve a comparable search purpose, though the example does not explain how a text-embedding model chooses its numbers. section 10.5.1

To put embeddings to work in a support chatbot:

  • Split support articles into chunks and add them, with their embeddings, to a vector index. section 10.5.2
  • Configure the index for the chosen embedding model and a similarity metric; one setup uses OpenAI’s text-embedding-3-small, 1536 dimensions, and cosine similarity in Pinecone. section 10.5.2
  • Search the index with the customer’s question, then place the retrieved excerpts in the context supplied to the LLM. section 10.5.2
splitter = RecursiveCharacterTextSplitter(
  chunk_size=1000,
  chunk_overlap=200
)
texts = splitter.split_documents(documents)

The splitter divides loaded documents into overlapping chunks before they are added to the vector store. section 10.5.2

An embedding is a search aid, not the answer itself. Retrieval supplies the article excerpts; the LLM then uses those excerpts to generate a response. You can implement this workflow without learning the embedding model’s internals first. section 10.5.1 section 10.5.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines vectors through a movie-rating analogy and configures text embeddings for retrieval, without explaining embedding-model internals.
Examples
Uses movie ratings as a vector analogy and support-article chunks as a searchable chatbot knowledge base.
What it assumes
Introduces embeddings from a simple numerical example before using Python libraries; does not require knowledge of embedding-model internals.
What you can do after
Apply it via OpenAIEmbeddings and Pinecone to ingest support articles and retrieve relevant excerpts for a chatbot.
How it connects
Connects embeddings to vectors, similarity search, vector databases, document chunks, and retrieval-augmented generation.

Also explained in

Compare how 47 books explain embedding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.