diff --git a/apps/simple/listIndex.ts b/apps/simple/listIndex.ts index db8e30fc8aee45fdcdffa4776c29beeaf5e34321..0bb1c65c71697b029f4de667f0aea6f07bd015c3 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 7b2aff279d0bd8a1b76c2e0c275f09a905534412..422236c644f731bddfca79a6e9469a0a5eaa873e 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;