@llamaindex/core
Version:
LlamaIndex Core Module
48 lines (45 loc) • 1.67 kB
JavaScript
import { extractText } from '../../utils/dist/index.js';
// 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: extractText(strOrQueryBundle)
});
const objs = nodes.map((n)=>this._objectNodeMapping.fromNode(n.node));
return objs;
}
}
export { BaseObjectNodeMapping, ObjectRetriever };