From 5a50ed2dfea478ded0a2eb8e0ac0eea8e09bb85c Mon Sep 17 00:00:00 2001 From: Sourabh Desai <sourabhdesai@gmail.com> Date: Tue, 18 Jul 2023 01:39:20 +0000 Subject: [PATCH] udpate ListIndex.fromDocuments method signature --- apps/simple/listIndex.ts | 18 ++++++++++++++++-- packages/core/src/index/list/ListIndex.ts | 11 ++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/simple/listIndex.ts b/apps/simple/listIndex.ts index db8e30fc8..0bb1c65c7 100644 --- a/apps/simple/listIndex.ts +++ b/apps/simple/listIndex.ts @@ -1,9 +1,23 @@ -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?" diff --git a/packages/core/src/index/list/ListIndex.ts b/packages/core/src/index/list/ListIndex.ts index 7b2aff279..422236c64 100644 --- a/packages/core/src/index/list/ListIndex.ts +++ b/packages/core/src/index/list/ListIndex.ts @@ -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; -- GitLab