セマンティック検索のためのベクトルクエリ
この演習では、'What is in front of the Notre Dame Main Building?' という質問からクエリベクトルを作成します。作成した埋め込みクエリを使って、'pinecone-datacamp' インデックスの 'squad_dataset' ネームスペースを検索し、最も類似したベクトルを上位5件返します。
この演習はコースの一部です
Pineconeを使ったAIアプリケーション開発
演習の手順
- Pinecone クライアントを API キーで初期化します(OpenAI クライアントは
clientとして利用できます)。 - 提供された
queryを、他のベクトルの埋め込みに使用したのと同じ OpenAI の埋め込みモデルで埋め込み、クエリベクトルを作成します。 query_embを使って"squad_dataset"ネームスペースにクエリを投げ、最も類似した結果を上位5件返します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Initialize the Pinecone client
pc = Pinecone(api_key="____")
index = pc.Index('pinecone-datacamp')
query = "What is in front of the Notre Dame Main Building?"
# Create the query vector
query_response = ____(
input=____,
model="text-embedding-3-small"
)
query_emb = query_response.data[0].embedding
# Query the index and retrieve the top five most similar vectors
retrieved_docs = ____
for result in retrieved_docs['matches']:
print(f"{result['id']}: {round(result['score'], 2)}")
print('\n')