Skip to content
Snippets Groups Projects
Commit 5a50ed2d authored by Sourabh Desai's avatar Sourabh Desai
Browse files

udpate ListIndex.fromDocuments method signature

parent 775be4da
No related branches found
No related tags found
No related merge requests found
import { Document, ListIndex, ListRetrieverMode } from "llamaindex";
import {
Document,
ListIndex,
ListRetrieverMode,
serviceContextFromDefaults,
SimpleNodeParser,
} from "llamaindex";
import essay from "./essay";
async function main() {
const serviceContext = serviceContextFromDefaults({
nodeParser: new SimpleNodeParser({
chunkSize: 40,
}),
});
const document = new Document({ text: essay });
const index = await ListIndex.fromDocuments([document]);
const index = await ListIndex.fromDocuments({
documents: [document],
serviceContext,
});
const queryEngine = index.asQueryEngine(ListRetrieverMode.LLM);
const response = await queryEngine.aquery(
"What did the author do growing up?"
......
......@@ -74,11 +74,12 @@ export class ListIndex extends BaseIndex<IndexList> {
});
}
static async fromDocuments(
documents: Document[],
storageContext?: StorageContext,
serviceContext?: ServiceContext
): Promise<ListIndex> {
static async fromDocuments(args: {
documents: Document[];
storageContext?: StorageContext;
serviceContext?: ServiceContext;
}): Promise<ListIndex> {
let { documents, storageContext, serviceContext } = args;
storageContext = storageContext ?? (await storageContextFromDefaults({}));
serviceContext = serviceContext ?? serviceContextFromDefaults({});
const docStore = storageContext.docStore;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment