Pinecone Embeddings
Pinecone 的推論 API 可以通過 PineconeEmbeddings
存取。 通過 Pinecone 服務提供文字嵌入。 我們首先安裝先決條件庫
!pip install -qU "langchain-pinecone>=0.2.0"
接下來,我們註冊/登入 Pinecone以取得我們的 API 金鑰
import os
from getpass import getpass
os.environ["PINECONE_API_KEY"] = os.getenv("PINECONE_API_KEY") or getpass(
"Enter your Pinecone API key: "
)
查看文檔以取得可用的模型。 現在我們初始化我們的嵌入模型,如下所示
from langchain_pinecone import PineconeEmbeddings
embeddings = PineconeEmbeddings(model="multilingual-e5-large")
API 參考:PineconeEmbeddings
從這裡我們可以同步或異步建立嵌入,讓我們從同步開始! 我們使用 embed_query
將單個文字嵌入為查詢嵌入(即我們在 RAG 中搜尋的內容)
docs = [
"Apple is a popular fruit known for its sweetness and crisp texture.",
"The tech company Apple is known for its innovative products like the iPhone.",
"Many people enjoy eating apples as a healthy snack.",
"Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces.",
"An apple a day keeps the doctor away, as the saying goes.",
]
doc_embeds = embeddings.embed_documents(docs)
doc_embeds
query = "Tell me about the tech company known as Apple"
query_embed = embeddings.embed_query(query)
query_embed