Skip to main content

Baidu Qianfan

The BaiduQianfanEmbeddings class uses the Baidu Qianfan API to generate embeddings for a given text.


An API key is required to use this embedding model. You can get one by registering at

Please set the acquired API key as an environment variable named BAIDU_API_KEY, and set your secret key as an environment variable named BAIDU_SECRET_KEY.

Then, you'll need to install the @langchain/baidu-qianfan package:

npm install @langchain/baidu-qianfan


import { BaiduQianfanEmbeddings } from "@langchain/baidu-qianfan";

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

API Reference:

Was this page helpful?

You can also leave detailed feedback on GitHub.