我有一个json数据,格式为:
[
{
"name": "Pocketbase",
"description": "Some description text",
"product_url": "https://pocketbase.io",
"github_url": "https://github.com/pocketbase/pocketbase",
"more_details": "raw text of features, uses cases etc.",
"open_source": true,
"expand": { type: [{}] }
}
]
我将其转换为以下文本以保存在松果中:
const tagList = data.expand.type.map(t => t.name);
let textTempalte = `Name of software: ${data.name}
Description: ${data.description}
Places it will be helpful: ${tagList.join(',')}
Is this project open source: ${data.open_source ? "Yes" : "No"}`;
if (data.more_detail.length > 0) {
textTempalte = textTempalte.concat(`\nMore detail: ${tech.more_detail}`);
}
if (data.product_url.length > 0) {
textTempalte = textTempalte.concat(`\nProduct homepage: ${tech.product_url}`);
}
if (data.github_url.length > 0) {
textTempalte = textTempalte.concat(`\nGithub link: ${tech.github_url}`);
}
使用模型
text-embedding-ada-002
我正在创建嵌入并为每个数据添加这些嵌入以响应pinecone数据库中的索引。
当我使用
description
和 more_detail
中的“实时数据库”等输入进行查询时,匹配从 pinecone 返回 0。
// Create embeding
const oaiResponse = await openai.createEmbedding({
model: "text-embedding-ada-002",
input: "realtime database",
});
const vector: QueryRequest = {
topK: 10,
vector: oaiResponse.data.data[0].embedding,
includeMetadata: true,
namespace: 'Default Project',
};
const resp = await index.query({
queryRequest: vector,
});
console.log(resp.mactches.length); // 0
我做错了什么?
这是一个异步请求,最好使用“then”方法来等待响应
// Create embedding
await openai.createEmbedding({
model: "text-embedding-ada-002",
input: "realtime database",
})
.then(async(oaiResponse)=> {
const vector: QueryRequest = {
topK: 10,
vector: oaiResponse.data.data[0].embedding,
includeMetadata: true,
namespace: 'Default Project',
};
const resp = await index.query({
queryRequest: vector,
});
})
.then(console.log(resp.mactches.length);)