Pinecone包埋
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
从这里我们可以创建 sync 或 async 嵌入,让我们从 sync 开始吧!我们使用embed_query:
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