-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
41 lines (34 loc) · 1.2 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Pinecone } from "@pinecone-database/pinecone";
import { HfInference } from "@huggingface/inference";
const hf = new HfInference(process.env.HF_TOKEN);
export async function queryPineconeVectorStore (
client : Pinecone,
indexname : string,
namespace : string,
searchQuery : string
) : Promise<string> {
const hfOutput = await hf.featureExtraction({
model : 'mixedbread-ai/mxbai-embed-large-v1',
inputs : searchQuery
})
console.log('hfoutput' , hfOutput);
const queryEmbbeding = Array.from(hfOutput);
console.log('queryEmbedding' , queryEmbbeding)
const index = client.Index(indexname);
const queryResponse = await index.namespace(namespace).query({
topK : 5,
vector : queryEmbbeding as any,
includeMetadata : true,
includeValues : false
})
console.log(queryResponse)
if(queryResponse.matches.length > 0) {
const concatRetrivals = queryResponse.matches.map((match , idx) => {
return `\n Clinical Findings ${idx+1} : \n ${match.metadata?.chunk}`
}).join("\n\n")
console.log(concatRetrivals)
return concatRetrivals;
} else {
return "<no_match>"
}
}