安装包
npm i @pinecone-database/pinecone langchain
代码示例
/**
* 查找相近数据
* @param {Object} pineconeParameter
* @param {Array} pineconeParameter.vector 查询的向量
* @param {Number} pineconeParameter.topK 返回相近的条数
* @param {Boolean} pineconeParameter.includeValues 是否返回value
* @param {Boolean} pineconeParameter.includeMetadata 是否返回Metadata
* @param {string} pineconeParameter.namespace 命名空间
* @returns {promises}
*/
findSimilarData(pineconeParameter) {
const { apiKey, environment } = this.ctx.app.config.pinecone;
return new Promise((resolve, reject) => {
//实例向量库
const client = new PineconeClient();
client.init({
apiKey,
environment,
}).then(() => {
const pineconeIndex = client.Index('first-database');
const queryRequest = Object.assign({
vector: [],
topK: 10,
includeValues: true,
includeMetadata: true,
namespace: "",
}, pineconeParameter);
pineconeIndex.query({ queryRequest }).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
})
})
}