We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Same Model

You must use the same embedding model for both documents and queries. Different models create incompatible vector spaces. Everything in Magical Vector Land is relative. The word "king" might embed to [0.5, 0.2, 0.1] in one model and [0.6, 0.3, 0.2] in another.

# Correct -- same model
model = SentenceTransformer("all-MiniLM-L6-v2")
doc_embeddings = model.encode(documents)
query_embeddings = model.encode(queries)

# Wrong -- different models create incompatible spaces
doc_model = SentenceTransformer("all-MiniLM-L6-v2")
query_model = SentenceTransformer("all-mpnet-base-v2")

If you get an error about your GPU or hardware acceleration, load the model on your CPU instead by passing device="cpu".

Why is this? Each model learns a different mathematical space. Comparing vectors from two models is like comparing GPS coordinates with street addresses: they're incompatible.