Step 1 — Initialize the embeddings model
First, import and initialize the embeddings object. In this example we use LangChain’sOpenAIEmbeddings 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
Callembed_documents to convert the list of strings into a list of numeric vectors:
embed_docs is an array of floating-point numbers (the embedding vector). Inspecting the first embedding (truncated) might look like this:
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.
Links and references
- Vector Database for GenAI
- LangChain embeddings docs — see relevant model usage and parameters
- OpenAI embeddings documentation — model options and dimensionality