UNPKG

llamaindex

Version:

<p align="center"> <img height="100" width="100" alt="LlamaIndex logo" src="https://ts.llamaindex.ai/square.svg" /> </p> <h1 align="center">LlamaIndex.TS</h1> <h3 align="center"> Data framework for your LLM application. </h3>

65 lines (64 loc) 2.13 kB
import { runTransformations } from "../ingestion/IngestionPipeline.js"; import { Settings } from "../Settings.js"; import { QueryEngineTool } from "../tools/QueryEngineTool.js"; /** * Indexes are the data structure that we store our nodes and embeddings in so * they can be retrieved for our queries. */ export class BaseIndex { storageContext; docStore; indexStore; indexStruct; constructor(init){ this.storageContext = init.storageContext; this.docStore = init.docStore; this.indexStore = init.indexStore; this.indexStruct = init.indexStruct; } /** * Returns a query tool by calling asQueryEngine. * Either options or retriever can be passed, but not both. * If options are provided, they are passed to generate a retriever. */ asQueryTool(params) { if (params.options) { params.retriever = this.asRetriever(params.options); } return new QueryEngineTool({ queryEngine: this.asQueryEngine(params), metadata: params?.metadata, includeSourceNodes: params?.includeSourceNodes ?? false }); } /** * Insert a document into the index. * @param document */ async insert(document) { const nodes = await runTransformations([ document ], [ Settings.nodeParser ]); await this.insertNodes(nodes); await this.docStore.setDocumentHash(document.id_, document.hash); } /** * Alias for asRetriever * @param options */ // eslint-disable-next-line @typescript-eslint/no-explicit-any retriever(options) { return this.asRetriever(options); } /** * Alias for asQueryEngine * @param options you can supply your own custom Retriever and ResponseSynthesizer */ queryEngine(options) { return this.asQueryEngine(options); } /** * Alias for asQueryTool * Either options or retriever can be passed, but not both. * If options are provided, they are passed to generate a retriever. */ queryTool(params) { return this.asQueryTool(params); } }