跳到主要内容
PremEmbeddings 类使用 Prem AI API 为给定文本生成嵌入。

设置

要使用 Prem API,您需要一个 API 密钥。您可以在此处注册一个 Prem 帐户并创建 API 密钥。 您首先需要安装 @langchain/community 包:
有关安装 LangChain 软件包的一般说明,请参阅此部分
npm
npm install @langchain/community @langchain/core

用法

import { PremEmbeddings } from "@langchain/community/embeddings/premai";

const embeddings = new PremEmbeddings({
  // In Node.js defaults to process.env.PREM_API_KEY
  apiKey: "YOUR-API-KEY",
  // In Node.js defaults to process.env.PREM_PROJECT_ID
  project_id: "YOUR-PROJECT_ID",
  model: "@cf/baai/bge-small-en-v1.5", // The model to generate the embeddings
});

const res = await embeddings.embedQuery(
  "What would be a good company name a company that makes colorful socks?"
);
console.log({ res });

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