跳到主要内容
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")
从这里我们可以同步或异步创建嵌入,让我们从同步开始!我们使用 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

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.