Compare commits

...

2 Commits

Author SHA1 Message Date
Simon Suo 3708afff4c wip 2023-07-17 00:17:00 -07:00
Simon Suo 0cae0e8e48 add testing file 2023-07-16 22:58:04 -07:00
2 changed files with 70 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import { Document } from "@llamaindex/core/src/Node";
import { VectorStoreIndex } from "@llamaindex/core/src/BaseIndex";
import { SubQuestionQueryEngine } from "@llamaindex/core/src/QueryEngine";
import essay from "./essay";
import { LLMQuestionGenerator } from "@llamaindex/core/src/QuestionGenerator";
import { defaultSubQuestionPrompt } from "@llamaindex/core/src/Prompt";
import { Refine, ResponseSynthesizer } from "@llamaindex/core/src/ResponseSynthesizer";
import { serviceContextFromDefaults } from "@llamaindex/core/src/ServiceContext";
// Customize the prompt for the question generator
async function main() {
const document = new Document({ text: essay });
const index = await VectorStoreIndex.fromDocuments([document]);
// TODO: hard to modify the existing prompts since it's a function
const questionGen = new LLMQuestionGenerator({
prompt : defaultSubQuestionPrompt,
});
const serviceContext = serviceContextFromDefaults();
const builder = new Refine(serviceContext);
const synthesizer = new ResponseSynthesizer(builder);
const queryEngine = SubQuestionQueryEngine.fromDefaults({
questionGen: questionGen,
responseSynthesizer: synthesizer,
queryEngineTools: [
{
queryEngine: index.asQueryEngine(),
metadata: {
name: "pg_essay",
description: "Paul Graham essay on What I Worked On",
},
},
],
});
const response = await queryEngine.aquery(
"How was Paul Grahams life different before and after YC?"
);
console.log(response);
}
main().catch(console.error);
+20
View File
@@ -0,0 +1,20 @@
import { Document } from "@llamaindex/core/src/Node";
import { VectorStoreIndex } from "@llamaindex/core/src/BaseIndex";
import essay from "./essay";
import { RetrieverQueryEngine } from "@llamaindex/core/src/QueryEngine";
// Customize retrieval and query args
async function main() {
const document = new Document({ text: essay });
const index = await VectorStoreIndex.fromDocuments([document]);
const retriever = index.asRetriever();
// TODO: using similarityTopK > 2 causes an error
retriever.similarityTopK = 3;
// TODO: cannot pass responseSynthesizer into retriever query engine
const queryEngine = new RetrieverQueryEngine(retriever);
const response = await queryEngine.aquery('Who is the author of the essay?');
console.log(response.response);
}
main().catch(console.error);