跳到主要內容
Open In ColabOpen on GitHub

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

此頁面是否對您有幫助?