Pinecone 嵌入
可以通过 PineconeEmbeddings
访问 Pinecone 的推理 API。通过 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