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

Query Embeddings

We need to convert user queries into vectors, just like we did with our documents. That way we can compare the query to the documents. For example, say we have these vectors in our document vector store:

  • [1,2,3]
  • [4,5,6]
  • [7,8,9]

Which one is closest to the query "bear"?

... It's impossible to say without first converting "bear" into the same kind of vector. So, "bear" –> [2, 3, 4] (for example).

Now, what's closest to [2, 3, 4]? We can use vector math to find out!

Preprocessing for Embeddings

Remember that embedding models handle many preprocessing tasks automatically:

  • Case-insensitive: "FUNNY" and "funny" get similar embeddings.
  • Punctuation-robust: "movies!" and "movies" are nearly identical.
  • Whitespace-tolerant: Extra spaces are handled gracefully.

This means we can use minimal preprocessing for queries – just basic cleaning like stripping whitespace.

Assignment

Implement query embedding functionality that converts user search queries into vectors.

    1. print(f"Query: {query}")
      print(f"First 3 dimensions: {embedding[:3]}")
      print(f"Shape: {embedding.shape}")
      

Run and submit the CLI tests.