sample
unknown
plain_text
14 days ago
1.3 kB
2
Indexable
import { BedrockAgentRuntimeClient, RetrieveCommand } from "@aws-sdk/client-bedrock-agent-runtime"; import { fromIni } from "@aws-sdk/credential-providers"; async function retrieveFromKnowledgeBase(knowledgeBaseId, query) { // Credentials are loaded automatically from environment variables or AWS config const client = new BedrockAgentRuntimeClient({ region: "us-east-1", credentials: fromIni({ profile: 'demo-ch' }) }); const command = new RetrieveCommand({ knowledgeBaseId: knowledgeBaseId, retrievalQuery: { text: query }, //maxResults: 1, retrievalConfiguration: { vectorSearchConfiguration: { numberOfResults: 10, // Specify the number of results to return // You can add other vector search configuration options here } } }); const response = await client.send(command); return response.retrievalResults; } try { console.log("-".repeat(53)); const response = await retrieveFromKnowledgeBase("KB_ID", 'replace_with_querry'); const result = [] for (var i = 0, l = response.length; i < l; i++) { var obj = response[i]; result.push(obj["metadata"]["url"]) } const resultJSON = JSON.stringify({ result }); console.log(resultJSON); } catch (err) { console.log(err); }
Editor is loading...
Leave a Comment