Retrieval-Augmented Generation with LangChain

Nov 12 2024 · Python 3.12, LangChain 0.3.x, JupyterLab 4.2.4

Lesson 02: Working with Embeddings & Vector Databases

Vector Embeddings Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Demo: Exploring Embeddings with OpenAI and LangChain

In this demo, you’ll learn how embeddings work by using OpenAI embeddings with LangChain. Start by setting up LangChain:

pip install langchain

Embedding Models and Vector Databases

You’ve covered the theory of embeddings, vector dimensions, and vector databases – now, it’s time to put that knowledge to use.

jupyter lab
export OPENAI_API_KEY="<insert-your-api-key-here>"
pip install langchain-openai
import os
from langchain_openai import OpenAIEmbeddings

openai_embedding = OpenAIEmbeddings(api_key=os.environ['OPENAI_API_KEY'])
embeddings = openai_embedding.embed_documents(
  [
    "RAG gives me AI super powers",
    "Thanks, Kodeco!",
  ]
)
len(embeddings[0])
embeddings[0][:10]
[-0.02180216647684574,
-0.03175415098667145,
0.004589573014527559,
-0.014155137352645397,
0.001597367925569415,
0.010148582980036736,
-0.020595453679561615,
-0.009335068985819817,
-0.03324558958411217,
-0.025300273671746254]
print(openai_embedding.model)
openai_embedding = OpenAIEmbeddings(api_key=os.environ['OPENAI_API_KEY'],
  model='text-embedding-3-small', dimensions=1024)
See forum comments
Cinema mode Download course materials from Github
Previous: Vector Dimensions & Embeddings Next: Introducing Chroma Database