Compare commits

...

2 Commits

Author SHA1 Message Date
Sourabh Desai cd24ebf926 fix instantiation 2023-07-17 22:32:53 +00:00
Sourabh Desai 52f8ca133c small improvements to listindex instantiation 2023-07-17 22:31:46 +00:00
3 changed files with 21 additions and 11 deletions
+11 -1
View File
@@ -1,10 +1,20 @@
import { Document } from "@llamaindex/core/src/Node";
import { ListIndex, ListRetrieverMode } from "@llamaindex/core/src/index/list";
import essay from "./essay";
import { serviceContextFromDefaults } from "@llamaindex/core/src/ServiceContext";
import { SimpleNodeParser } from "@llamaindex/core/src/NodeParser";
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?"
+6 -5
View File
@@ -71,11 +71,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;
@@ -134,11 +134,10 @@ describe("CallbackManager: onLLMStream and onRetrieve", () => {
});
test("For ListIndex w/ a ListIndexRetriever", async () => {
const listIndex = await ListIndex.fromDocuments(
[document],
undefined,
serviceContext
);
const listIndex = await ListIndex.fromDocuments({
documents: [document],
serviceContext,
});
const queryEngine = listIndex.asQueryEngine();
const query = "What is the author's name?";
const response = await queryEngine.aquery(query);