Skip to main content
We are now in the third phase of the workflow: generating embeddings. In this lesson we convert text chunks into numeric vectors (embeddings). Before returning to the PDF-based workflow where we already loaded and chunked documents, let’s take a short detour to understand embeddings as a standalone concept — this will clarify how retrieval-augmented generation (RAG) works and why embeddings are central to semantic search. Embeddings are numeric vector representations of text that preserve semantic meaning and context. Once converted, these vectors enable similarity comparisons (for example, via cosine similarity) so you can retrieve semantically related documents from a vector store.

Step 1 — Initialize the embeddings model

First, import and initialize the embeddings object. In this example we use LangChain’s OpenAIEmbeddings with the text-embedding-3-large model:

Step 2 — Prepare documents to embed

Create a small list of documents. In a real pipeline these would be the chunks extracted from your PDFs or other sources; here we use example news headlines for illustration:

Step 3 — Convert text to embeddings

Call embed_documents to convert the list of strings into a list of numeric vectors:
You can verify that the number of returned embeddings matches the number of input documents:
Each element in embed_docs is an array of floating-point numbers (the embedding vector). Inspecting the first embedding (truncated) might look like this:
The dimensionality of each vector depends on the chosen embedding model. For text-embedding-3-large the vectors have 3072 dimensions:
Embeddings are not meant to be human-readable. They are high-dimensional numeric representations used by algorithms to compute semantic similarity (for example, via cosine similarity) during semantic search or retrieval.

Quick reference — embedding workflow

What to do with these vectors

Once you have these vectors you typically:
  • Store them in a vector database (ANN index) for efficient similarity search.
  • Use similarity metrics (cosine similarity, dot product) to retrieve the most relevant chunks for a given user query.
  • Combine retrieved context with a generative model for retrieval-augmented generation (RAG) — e.g., building a Q&A chatbot over your PDF corpus.
For vector storage and retrieval, consider vector databases or specialized libraries that support approximate nearest neighbor (ANN) search and persistence.
  • Vector Database for GenAI
  • LangChain embeddings docs — see relevant model usage and parameters
  • OpenAI embeddings documentation — model options and dimensionality
In the next part of this lesson we’ll introduce a vector database and demonstrate a simple similarity search. After covering retrieval and storage, we’ll continue building the Q&A chatbot for the PDF.

Watch Video