import {
Document,
storageContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
async function main() {
const document = new Document({ text: essay, id_: "essay" });
const storageContext = await storageContextFromDefaults({
persistDir: "./storage",
});
const index = await VectorStoreIndex.fromDocuments([document], {
storageContext,
});
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query: "What did the author do in college?",
});
console.log(response.toString());
const secondStorageContext = await storageContextFromDefaults({
persistDir: "./storage",
});
const loadedIndex = await VectorStoreIndex.init({
storageContext: secondStorageContext,
});
const loadedQueryEngine = loadedIndex.asQueryEngine();
const loadedResponse = await loadedQueryEngine.query({
query: "What did the author do growing up?",
});
console.log(loadedResponse.toString());
}
main().catch(console.error);