adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
45 lines (44 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LlamaIndexRetrieval = void 0;
const BaseRetrievalTool_1 = require("./BaseRetrievalTool");
/**
* Retrieval tool that uses LlamaIndex to retrieve information
*/
class LlamaIndexRetrieval extends BaseRetrievalTool_1.BaseRetrievalTool {
/**
* Create a new LlamaIndex retrieval tool
*
* @param options Options for the LlamaIndex retrieval tool
*/
constructor(options) {
super(options);
this.retriever = options.retriever;
}
/**
* Retrieve information using LlamaIndex
*
* @param query The query to retrieve information for
* @param maxResults Maximum number of results to return
* @param context The context for the retrieval
* @returns The retrieved information
*/
async retrieve(query, maxResults, context) {
try {
// This is a simplified implementation since we don't have direct LlamaIndex bindings in TypeScript
// In a real implementation, this would use the LlamaIndex TypeScript bindings if available
const results = await this.retriever.retrieve(query);
if (!results || results.length === 0) {
return "No results found";
}
// Return the first result's text
// In a real implementation with TypeScript bindings, this would be properly typed
return results[0].text;
}
catch (error) {
console.error("Error retrieving from LlamaIndex:", error);
return `Error retrieving information: ${error instanceof Error ? error.message : String(error)}`;
}
}
}
exports.LlamaIndexRetrieval = LlamaIndexRetrieval;