1. Learn
  2. /
  3. Courses
  4. /
  5. Vector Databases for Embeddings with Pinecone

Connected

Exercise

Building a retrieval function

A key process in the Retrieval Augmented Generation (RAG) workflow is retrieving data from the database. In this exercise, you'll design a custom function called retrieve() that will perform this crucial process in the final exercise of the course.

Instructions

100 XP
  • Initialize the Pinecone client with your API key (the OpenAI client is available as client).
  • Define the function retrieve that takes four parameters: query, top_k, namespace, and emb_model.
  • Embed the input query using the emb_model argument.
  • Retrieve the top_k similar vectors to query_emb with metadata, specifying the namespace provided to the function as an argument.