@llamaindex/core
Version:
LlamaIndex Core Module
51 lines (47 loc) • 1.79 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var index_cjs = require('../../utils/dist/index.cjs');
// Assuming that necessary interfaces and classes (like OT, TextNode, BaseNode, etc.) are defined elsewhere
// Import statements (e.g., for TextNode, BaseNode) should be added based on your project's structure
class BaseObjectNodeMapping {
// Concrete methods can be defined as usual
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validateObject(obj) {}
// Implementing the add object logic
// eslint-disable-next-line @typescript-eslint/no-explicit-any
addObj(obj) {
this.validateObject(obj);
this._addObj(obj);
}
// Implementing toNodes method
// eslint-disable-next-line @typescript-eslint/no-explicit-any
toNodes(objs) {
return objs.map((obj)=>this.toNode(obj));
}
// Implementing fromNode method
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fromNode(node) {
const obj = this._fromNode(node);
this.validateObject(obj);
return obj;
}
}
class ObjectRetriever {
constructor(retriever, objectNodeMapping){
this._retriever = retriever;
this._objectNodeMapping = objectNodeMapping;
}
// In TypeScript, getters are defined like this.
get retriever() {
return this._retriever;
}
// Translating the retrieve method
async retrieve(strOrQueryBundle) {
const nodes = await this.retriever.retrieve({
query: index_cjs.extractText(strOrQueryBundle)
});
const objs = nodes.map((n)=>this._objectNodeMapping.fromNode(n.node));
return objs;
}
}
exports.BaseObjectNodeMapping = BaseObjectNodeMapping;
exports.ObjectRetriever = ObjectRetriever;