Use iFlytek Spark embeddings interface to implement a simple knowledge base RAG API.
Write the appid, api_key, and api_secret of your iFlytek Spark embedding permission into search.py.
Write the question pair, the question identifier, the question, and the embedding vector of the question into Name, Description, and Description Embeddings in subfeatures_dataset.csv respectively.
Start app.py
python app.pyVisit http://localhost:5000/search?description=<query>. Replace query with the question you want to match. For example, http://localhost:5000/search?description=电话费怎么查
The interface will return the identifiers and scores of the top five questions in descending order of similarity.
[
{
"score": 0.9682152555160143,
"subfeature": 5
},
{
"score": 0.9043227799045512,
"subfeature": 3
},
{
"score": 0.8832442272195338,
"subfeature": 1
},
{
"score": 0.8672601961443654,
"subfeature": 4
},
{
"score": 0.8264842492121457,
"subfeature": 2
}
]使用 讯飞星火embeddings接口 实现的简易知识库API。
将你已开通讯飞星火embedding权限的appid、api_key、api_secret写入search.py。
将问题对以及已经查到的问题标识符、问题以及问题的embedding向量分别写入subfeatures_dataset.csv内的Name, Description, Description Embeddings。
启动 app.py
python app.py访问 http://localhost:5000/search?description=<query>。将query替换为你的要匹配的问题。例如http://localhost:5000/search?description=话费怎么查
接口将返回相似度由高到低的前五个问题的标识符以及得分。
[
{
"score": 0.9682152555160143,
"subfeature": 5
},
{
"score": 0.9043227799045512,
"subfeature": 3
},
{
"score": 0.8832442272195338,
"subfeature": 1
},
{
"score": 0.8672601961443654,
"subfeature": 4
},
{
"score": 0.8264842492121457,
"subfeature": 2
}
]